-
Notifications
You must be signed in to change notification settings - Fork 0
/
mulObfs.py
executable file
·70 lines (59 loc) · 2.82 KB
/
mulObfs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import call,Popen,PIPE
import obfsdef as od
import argparse
import glob
import os
def chkObfs():
out,err = Popen(['./a.out','42','42','42','42'],stdin=PIPE,stdout=PIPE,
stderr=PIPE).communicate(input=b'secret\n')
assert 'You win!' in out.decode('utf-8').split('\n')[0], 'Obfuscated program`s execution result differ from original program.'
def main(av):
if av.target[-1] is not '/': args.target += '/'
if av.dest[-1] is not '/': args.dest += '/'
binpath = args.dest+'bin/'
call(['mkdir','-p',av.dest])
call(['mkdir','-p',binpath])
if av.apple: ENV = '--Environment=x86_64:Darwin:Clang:5.1 '+od.TIGRESS_HOME+'/apple.h -include'
else: ENV = '--Environment=x86_64:Linux:Gcc:4.6'
if av.verbose: errOut = None
else: errOut = PIPE
## Appending ENV
for method in od.METHODS:
for e in ENV.split(' '): od.METHODS[method].insert(1,e)
cfiles = glob.glob(av.target+'*.c')
num = 1
for cfile in cfiles:
print('(',num,'/',len(cfiles),') Obfuscating',os.path.basename(cfile),':')
OUTFILE = av.dest+os.path.basename(cfile)
for method in od.METHODS:
## Obfuscating
print(' '+method+'-obfuscate ...',flush=True,end='')
od.METHODS[method].append('--out='+OUTFILE[:-2]+'_'+method+'.c')
od.METHODS[method].append(cfile)
call(od.METHODS[method],stderr=errOut)
if av.check: chkObfs()
if av.ext is not False:
call(['mv','a.out',binpath+os.path.basename(cfile)[:-2]+'_'+method+av.ext])
od.METHODS[method] = od.METHODS[method][:-2] # Delete appended cfile, --out...
print('finished!')
num += 1
if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description='''
Obfuscate multiple programs on target directory with methods defined
on obfsdef.py.''')
parser.add_argument('target',help='target directory')
parser.add_argument('dest',help='destination directory')
parser.add_argument('--apple',action='store_true',
help='Set --Environment=x86_64:Darwin:Clang:5.1 (default --Environment=x86_64:Linux:Gcc:4.6)')
parser.add_argument('--ext', nargs='?', default=False, const='',
help='Output binary file extension (e.g. .exe, .bin, .out)')
parser.add_argument('--check',action='store_true',
help='Enable checking the obfuscated file. *Only useful for programs generated using gen_orig.py')
parser.add_argument('--verbose',action='store_true',help='Enabling tigress messages.')
parser.add_argument('--version',action='version',version='%(prog)s 1.0')
args = parser.parse_args()
main(args)