-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrida_hook.py
More file actions
70 lines (53 loc) · 1.5 KB
/
frida_hook.py
File metadata and controls
70 lines (53 loc) · 1.5 KB
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
import frida
import sys
import time
class FridaHoocker():
def __init__(self):
self.script = None
self._process_terminated = False
def on_destroyed(self):
print("[*] Destroyed!")
sys.exit(1)
def on_detach(self):
self._process_terminated = True
print("[*] Detach")
def on_message(self, message, data):
if message['type'] == 'send':
msg_data = message['payload']
if msg_data['name'] == 'log':
try:
print('%s' % msg_data['payload'])
self.script.post({'type': 'ack'})
except Exception as e:
print(e)
else:
print('[*] Error: %s' % message)
def main(self, target_process):
session = frida.attach(target_process)
with open("script.js") as fp:
script_js = fp.read()
fp.close()
self.script = session.create_script(script_js)
self.script.on('destroyed', self.on_destroyed)
self.script.on('message', self.on_message)
session.on('detached', self.on_detach)
self.script.load()
frida.resume(target_process)
print("[*] Ctrl+C to detach from program.\n")
while True:
try:
time.sleep(0.5)
except KeyboardInterrupt:
break
frida.kill(target_process)
session.detach()
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: %s <process name or PID>" % __file__)
sys.exit(1)
try:
target_process = int(sys.argv[1])
except ValueError:
target_process = frida.spawn(sys.argv[1])
frida_hook = FridaHoocker()
frida_hook.main(target_process)