-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
executable file
·100 lines (83 loc) · 2.76 KB
/
run.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
from subprocess import (Popen, PIPE)
import subprocess
import capnp
import os
import sys
dbname = 'holmes_test'
container = "obj.holmes"
chunker = "chunk.holmes"
subprocess.check_call('echo "drop database ' + dbname + '; create database ' + dbname + ';" | psql', shell=True)
env = os.environ.copy()
env['PGDATABASE'] = dbname
holmesProc = Popen(['holmes'], stdout=PIPE, env=env)
port = int(holmesProc.stdout.readline())
os.dup2(sys.stdout.fileno(), holmesProc.stdout.fileno())
addr = "localhost:" + str(port)
analProgs = [container, chunker]
analProcs = []
for prog in analProgs:
analProcs.append(Popen([prog, addr]))
import func
import toil
import succ
import reach
import dumpKV
import byteweight
from holmes import *
# pymods = [func.MarkFuncs(), toil.ToIL(), succ.LooseSucc(), reach.ReachSucc()]
pymods = [func.MarkFuncs(), toil.ToIL(), succ.LooseSucc(), reach.ReachSucc(), byteweight.Naive()]
pypids = []
for pymod in pymods:
pypids += [forkRegister(pymod, addr)]
print("Port: " + str(port))
fileName = sys.argv[1]
with open(fileName, mode='rb') as file:
fileContent = file.read()
holmes = Holmes(addr)
#Races
import time
import datetime
time.sleep(1);
begin = datetime.datetime.now()
holmes.setFacts([Fact("file", [fileName, fileContent])])
# holmes.setFacts([Fact("reachable", [fileName, addr])])
done = datetime.datetime.now()
print("Time:", done - begin)
# byteweight.check(holmes)
funcs = holmes.deriveFacts([Premise("func", [Bind("fileName", "string")
,Bind("addr", "addr")])
,Premise("reaches", [Bind("fileName", "string")
,Bind("addr", "addr")
,Forall("body", "addr")])])
i = 0
for func in funcs:
print("Function at: " + hex(func['addr']))
for addr in func['body']:
il = holmes.deriveFacts([Premise("hasil", [Exact(func['fileName'], "string")
,Exact(addr, "addr")
,Bind("il", "json")])])
print(hex(addr) + ":")
il = list(il)
if len(il) == 0:
print(" No IL available")
else:
print(" IL: ", str(il[0]['il']))
asm = holmes.deriveFacts([Premise("hasasm", [Exact(func['fileName'], "string")
,Exact(addr, "addr")
,Bind("asm", "string")])])
asm = list(asm)
if len(asm) == 0:
print(" No Disassembly available")
else:
print(" Disassembly: ", str(asm[0]['asm']))
i += 1
if i == 2:
break
import signal
for pypid in pypids:
os.kill(pypid, signal.SIGKILL)
for analProc in analProcs:
analProc.terminate()
holmesProc.terminate()
os.unlink('/tmp/bapd')