rewarding remember len,

removing redundant disassembly
master
JoYo 2019-02-24 07:39:00 +00:00
parent ba8d38e56b
commit a3ba591077
2 changed files with 11 additions and 12 deletions

View File

@ -54,20 +54,14 @@ def generation(queue: Queue, shellcode: bytes):
queue.put(result)
def growth(*, shellcode: bytes, length: int) -> bytes:
if length <= len(shellcode):
return bytes(shellcode)
opcodes = disasm(shellcode)
def growth(*, shellcode: bytes, objdump: str) -> bytes:
max_op_len = 15
if len(shellcode) > len(opcodes) * max_op_len:
if len(shellcode) > objdump.count('\n') * max_op_len:
return bytes(shellcode)
for mnemonic, op_str in opcodes:
if mnemonic == 'nop':
return bytes(shellcode)
if objdump.count('nop'):
return bytes(shellcode)
shellcode = bytearray(shellcode)
shellcode += b'\x90'

View File

@ -10,6 +10,7 @@ import logging
from .mutation import generation, mutate, seed_shell, growth
from .orm import db_config, ScrapNode
from .disassemble import objdump
def sins():
@ -94,13 +95,17 @@ def sins():
lineage += 1
continue
if not result:
if result != len(scrap):
lineage += 1
continue
scrap = growth(shellcode=scrap, length=result)
logger.debug(f'result: {result}, {len(scrap)}')
opcodes = objdump(scrap)
scrap = growth(shellcode=scrap, objdump=opcodes)
parent = ScrapNode(child=scrap, parent_id=parent.id)
parent.objdump = opcodes
session.add(parent)
session.commit()