-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmondump.py
61 lines (51 loc) · 2.19 KB
/
mondump.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
import frida
import sys
import argparse
import signal
from collections import defaultdict
CHUNKS = defaultdict(set)
def prepare_script(frida_target_process, pattern, time):
with open('mondump.js','r') as f:
return frida_target_process.session.create_script( f.read() % { 'pattern':pattern.encode('hex'),
'msecs':time })
def on_frida_message(msg, data , chunks = CHUNKS):
if msg['payload'].has_key('addr') and msg['payload'].has_key('time') and msg['payload'].has_key('data'):
chunks[msg['payload']['addr']].add(msg['payload']['data'])
return
if msg['payload'].has_key('log'):
print('LOG: {}'.format(msg['payload']['log']))
return
def pretty_print_chunks (chunks , file=sys.stdout):
for addr,strs in chunks.items():
print >> file, '@{}:'.format(hex(addr))
for s in strs:
try:
print >> file, unicode(s.encode('ascii','ignore'))
except Exception,e:
print >> file, [c for c in s]
def signal_handler(signal, frame):
print 'Removing TAPs and writing to %s' % ofile
script.unload()
with open(ofile,'w') as f:
pretty_print_chunks(CHUNKS, file=f)
sys.exit(0)
def main():
global script
global ofile
parser = argparse.ArgumentParser()
parser.add_argument("pid", type=int, help="target PID")
parser.add_argument("-p", "--pattern", default='HTTP', help="Pattern to match,(AAABBBXXXWW , wildchar ? not yet supported)")
parser.add_argument("-t", "--time", default=5000, help="Periodic memory scan time in msec")
parser.add_argument("-o", "--outfile", default='dump.txt', help="Output File where to put captured strings")
args = parser.parse_args()
process = frida.attach(args.pid)
ofile = args.outfile
script = prepare_script(process, args.pattern, args.time)
script.on('message', on_frida_message)
script.load()
signal.signal(signal.SIGINT, signal_handler)
while True:
inp = sys.stdin.readline()
pretty_print_chunks(CHUNKS)
if __name__ == '__main__':
main()