|
|
|
@ -13,13 +13,40 @@ from .orm import db_config, ScrapNode
|
|
|
|
|
from .disassemble import objdump |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export(): |
|
|
|
|
now = '{0:%Y%m%dT%H%M%S}'.format(datetime.utcnow()) |
|
|
|
|
parser = ArgumentParser( |
|
|
|
|
description='export recent scrap shellcode.') |
|
|
|
|
parser.add_argument('-v', '--verbose', action='count') |
|
|
|
|
parser.add_argument('-db', '--database', default='/out/sins.sqlite', |
|
|
|
|
help='path to scrap database.') |
|
|
|
|
parser.add_argument('-o', '--out_path', |
|
|
|
|
help='path to export scrap shellcode.') |
|
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
level = logging.DEBUG if args.verbose else logging.INFO |
|
|
|
|
logging.basicConfig(level=level, format='%(message)s') |
|
|
|
|
logging.info(now) |
|
|
|
|
|
|
|
|
|
db_path = Path(args.database) |
|
|
|
|
session = db_config(db_path) |
|
|
|
|
logging.info(f'db_path: {db_path}') |
|
|
|
|
recent = session.query(ScrapNode).order_by(desc('ctime')).first() |
|
|
|
|
logging.info(f'recent: {recent}') |
|
|
|
|
|
|
|
|
|
out_path = Path(f'{args.out_path}/scrap-{recent.checksum[:8]}.bin') |
|
|
|
|
|
|
|
|
|
with out_path.open('wb') as file: |
|
|
|
|
file.write(recent.image) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sins(): |
|
|
|
|
now = '{0:%Y%m%dT%H%M%S}'.format(datetime.utcnow()) |
|
|
|
|
parser = ArgumentParser( |
|
|
|
|
description='position independent code (PIC) mutation experiment.') |
|
|
|
|
parser.add_argument('-v', '--verbose', action='count') |
|
|
|
|
parser.add_argument('-s', '--seed', help='path to PIC image.') |
|
|
|
|
parser.add_argument('-o', '--output', help='path to results directory.') |
|
|
|
|
parser.add_argument('-o', '--out_path', help='path to results directory.') |
|
|
|
|
parser.add_argument('-l', '--lineage', default=10, |
|
|
|
|
help='max count of unsuccessful generation.') |
|
|
|
|
args = parser.parse_args() |
|
|
|
@ -42,8 +69,8 @@ def sins():
|
|
|
|
|
|
|
|
|
|
logger.info(now) |
|
|
|
|
|
|
|
|
|
if args.output: |
|
|
|
|
db_path = Path(f'{args.output}/sins.sqlite') |
|
|
|
|
if args.out_path: |
|
|
|
|
db_path = Path(f'{args.out_path}/sins.sqlite') |
|
|
|
|
else: |
|
|
|
|
temp_dir = TemporaryDirectory() |
|
|
|
|
db_path = Path(f'{temp_dir.name}/sins.sqlite') |
|
|
|
@ -67,7 +94,8 @@ def sins():
|
|
|
|
|
seed = ScrapNode(child=seed_shell) |
|
|
|
|
logger.debug(f'seed_shell:\n{seed}') |
|
|
|
|
|
|
|
|
|
exists = session.query(ScrapNode).filter(ScrapNode.checksum == seed.checksum).all() |
|
|
|
|
exists = session.query(ScrapNode).filter( |
|
|
|
|
ScrapNode.checksum == seed.checksum).all() |
|
|
|
|
|
|
|
|
|
if exists: |
|
|
|
|
seed = exists[0] |
|
|
|
|