-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwatch_syslog.py
80 lines (61 loc) · 2.51 KB
/
watch_syslog.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
#!/usr/bin/env python3
# Watch and capture QMI packets from the running idevicesyslog
# You need to have permissions for executing the dumpcap (you have to be part of the "wireshark" group or run this as sudo)
# Inspired / parts from https://github.com/seemoo-lab/aristoteles/blob/master/tools/watch_frida.py (MIT License)
import argparse
import io
import os
import re
import subprocess
from wireshark import Wireshark
from shutil import which
class WatchSyslog(Wireshark):
""" Inspect QMI packets in Wireshark extracted using the idevicesyslog utility. """
def __init__(self, verbose: bool):
super().__init__(verbose)
self.syslog_process = None
def _spawn_device_syslog(self) -> bool:
if which("idevicesyslog") is None:
print("idevicesyslog not found!")
return False
DEVNULL = open(os.devnull, "wb")
self.syslog_process = subprocess.Popen(
"idevicesyslog",
stdout=subprocess.PIPE,
stderr=DEVNULL,
)
return True
def check_input_monitor(self) -> bool:
if self.syslog_process.poll() == 0:
print("_pollTimer: Syslog has terminated")
self.syslog_process = None
return False
else:
return True
def start_input_monitor(self) -> bool:
if self.syslog_process is None:
if not self._spawn_device_syslog():
print("Unable to start Syslog")
return False
for line in io.TextIOWrapper(self.syslog_process.stdout, encoding="utf-8"):
bin_content = re.search(r".*CommCenter.*Bin=\['(.*)']", line)
if bin_content is not None:
self.feed_wireshark(bin_content.group(1).lower().replace(" ", ""))
return True
def kill_input_monitor(self) -> None:
if self.syslog_process is not None:
print("Killing Syslog process...")
try:
self.syslog_process.terminate()
self.syslog_process.wait()
except OSError:
print("Error during syslog process termination")
self.syslog_process = None
# Call script
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(
description="Attaches to the idevicesyslog and pipes the output to wireshark for live monitoring.")
arg_parser.add_argument('-v', '--verbose', action='store_true', help='Print verbose logs')
args = arg_parser.parse_args()
watcher = WatchSyslog(args.verbose)
watcher.start_monitor()