Compare commits

..

No commits in common. "a6283703657eb4077a7fdab03da6b056a132dff5" and "38706feff61c807983e00e284484faf1f4cf9fc5" have entirely different histories.

5 changed files with 19 additions and 19 deletions

View File

@ -2,4 +2,3 @@
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,6 @@ import json
capstone = Cs(CS_ARCH_X86, CS_MODE_64)
def disasm(shellcode: bytes)->list:
opcodes = list()
@ -13,7 +12,6 @@ def disasm(shellcode: bytes) -> list:
return opcodes
def objdump(shellcode: bytes)->str:
opcodes = str()

View File

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

View File

@ -6,6 +6,9 @@ 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()
@ -40,6 +43,7 @@ class ScrapNode(Base):
self.image = child
self.length = len(child)
self.sha1sum
self.objdump = objdump(child)
def __repr__(self):
values = {

View File

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