Compare commits

..

4 Commits

Author SHA1 Message Date
JoYo a628370365 minor logging output 2019-02-24 07:50:51 +00:00
JoYo a3ba591077 rewarding remember len,
removing redundant disassembly
2019-02-24 07:39:00 +00:00
JoYo ba8d38e56b minor fixes and formatting 2019-02-24 07:38:11 +00:00
JoYo 8d8df2ab5a log op count 2019-02-24 07:14:29 +00:00
5 changed files with 19 additions and 19 deletions

View File

@ -2,3 +2,4 @@
from .run import sins
from .mutation import generation, mutate
from .orm import db_config, ScrapNode
from .disassemble import disasm, objdump

View File

@ -4,7 +4,8 @@ import json
capstone = Cs(CS_ARCH_X86, CS_MODE_64)
def disasm(shellcode: bytes)->list:
def disasm(shellcode: bytes) -> list:
opcodes = list()
for opcode in capstone.disasm(shellcode, 0):
@ -12,7 +13,8 @@ def disasm(shellcode: bytes)->list:
return opcodes
def objdump(shellcode: bytes)->str:
def objdump(shellcode: bytes) -> str:
opcodes = str()
for opcode in capstone.disasm(shellcode, 0):

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

@ -6,9 +6,6 @@ from sqlalchemy import LargeBinary, Column, ForeignKey, Integer, String, DateTim
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, relationship, backref
from sqlalchemy.orm.collections import attribute_mapped_collection
import json
from .disassemble import objdump
now = '{0:%Y%m%dT%H%M%S}'.format(datetime.utcnow())
Base = declarative_base()
@ -43,7 +40,6 @@ class ScrapNode(Base):
self.image = child
self.length = len(child)
self.sha1sum
self.objdump = objdump(child)
def __repr__(self):
values = {

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,15 +95,21 @@ def sins():
lineage += 1
continue
if not result:
if result != len(scrap):
lineage += 1
continue
scrap = growth(shellcode=scrap, length=result)
opcodes = objdump(scrap)
ops_count = opcodes.count('\n')
logger.debug({'result': result, 'ops': ops_count})
scrap = growth(shellcode=scrap, objdump=opcodes)
parent = ScrapNode(child=scrap, parent_id=parent.id)
parent.objdump = opcodes
session.add(parent)
session.commit()
logger.info(f'scrap:\n{parent}')
logger.info(parent)
lineage = 0