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,19 +54,13 @@ def generation(queue: Queue, shellcode: bytes):
queue.put(result) queue.put(result)
def growth(*, shellcode: bytes, length: int) -> bytes: def growth(*, shellcode: bytes, objdump: str) -> bytes:
if length <= len(shellcode):
return bytes(shellcode)
opcodes = disasm(shellcode)
max_op_len = 15 max_op_len = 15
if len(shellcode) > len(opcodes) * max_op_len: if len(shellcode) > objdump.count('\n') * max_op_len:
return bytes(shellcode) return bytes(shellcode)
for mnemonic, op_str in opcodes: if objdump.count('nop'):
if mnemonic == 'nop':
return bytes(shellcode) return bytes(shellcode)
shellcode = bytearray(shellcode) shellcode = bytearray(shellcode)

View File

@ -10,6 +10,7 @@ import logging
from .mutation import generation, mutate, seed_shell, growth from .mutation import generation, mutate, seed_shell, growth
from .orm import db_config, ScrapNode from .orm import db_config, ScrapNode
from .disassemble import objdump
def sins(): def sins():
@ -94,13 +95,17 @@ def sins():
lineage += 1 lineage += 1
continue continue
if not result: if result != len(scrap):
lineage += 1 lineage += 1
continue 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 = ScrapNode(child=scrap, parent_id=parent.id)
parent.objdump = opcodes
session.add(parent) session.add(parent)
session.commit() session.commit()