diff options
author | Mike Crute <mike@crute.us> | 2017-07-18 03:51:43 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2017-08-16 18:30:39 +0000 |
commit | 963517b79eeb794bace8545a8e7f9c3d10f1f869 (patch) | |
tree | 1f41eb87839162277aa8d3ed14b8e2734f99dd11 | |
parent | 5daa556568096364462f57531a27deef969fcdf5 (diff) | |
download | ubntmfi-963517b79eeb794bace8545a8e7f9c3d10f1f869.tar.bz2 ubntmfi-963517b79eeb794bace8545a8e7f9c3d10f1f869.tar.xz ubntmfi-963517b79eeb794bace8545a8e7f9c3d10f1f869.zip |
-rwxr-xr-x | reversing_tools/parse_mitm.py | 15 | ||||
-rwxr-xr-x | reversing_tools/parse_pcap.py | 31 |
2 files changed, 30 insertions, 16 deletions
diff --git a/reversing_tools/parse_mitm.py b/reversing_tools/parse_mitm.py index ef61298..e59ce73 100755 --- a/reversing_tools/parse_mitm.py +++ b/reversing_tools/parse_mitm.py | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | 2 | ||
3 | import sys, os | 3 | import sys |
4 | import os | ||
4 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python')) | 5 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python')) |
5 | 6 | ||
6 | import json | 7 | import json |
@@ -11,7 +12,7 @@ from inform import InformSerializer | |||
11 | 12 | ||
12 | def make_serializer(from_file): | 13 | def make_serializer(from_file): |
13 | with open(from_file) as fp: | 14 | with open(from_file) as fp: |
14 | keystore = { i['mac']: i['x_authkey'] for i in json.load(fp) } | 15 | keystore = {i['mac']: i['x_authkey'] for i in json.load(fp)} |
15 | 16 | ||
16 | return InformSerializer("", keystore) | 17 | return InformSerializer("", keystore) |
17 | 18 | ||
@@ -23,14 +24,16 @@ def dumps_pretty(obj): | |||
23 | if __name__ == "__main__": | 24 | if __name__ == "__main__": |
24 | ser = make_serializer("data/devices.json") | 25 | ser = make_serializer("data/devices.json") |
25 | 26 | ||
26 | with open('data/mitm/reboot.txt', 'rb') as fp, open('test.out', 'w') as fp2: | 27 | with open('data/mitm/onoff.txt', 'rb') as fp, open('test.out', 'w') as fp2: |
27 | read = FlowReader(fp) | 28 | read = FlowReader(fp) |
28 | 29 | ||
29 | for rec in read.stream(): | 30 | for rec in read.stream(): |
30 | res = ser.parse(StringIO(rec.response.content)) | 31 | res = ser.parse(StringIO(rec.response.content)) |
31 | req = ser.parse(StringIO(rec.request.content)) | 32 | req = ser.parse(StringIO(rec.request.content)) |
32 | 33 | ||
33 | print dumps_pretty(req.payload) | 34 | # print req.payload |
34 | print dumps_pretty(res.payload) | 35 | if res.payload['_type'] == 'cmd': |
35 | 36 | print dumps_pretty(res.payload) | |
37 | # print dumps_pretty(req.payload) | ||
38 | # print dumps_pretty(res.payload) | ||
36 | 39 | ||
diff --git a/reversing_tools/parse_pcap.py b/reversing_tools/parse_pcap.py index ed6f465..3668379 100755 --- a/reversing_tools/parse_pcap.py +++ b/reversing_tools/parse_pcap.py | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | 2 | ||
3 | import sys, os | 3 | import sys |
4 | import os | ||
4 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python')) | 5 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'python')) |
5 | 6 | ||
6 | import dpkt | 7 | import dpkt |
@@ -47,17 +48,27 @@ def collect_records(from_file): | |||
47 | 48 | ||
48 | def make_serializer(from_file): | 49 | def make_serializer(from_file): |
49 | with open(from_file) as fp: | 50 | with open(from_file) as fp: |
50 | keystore = { i['mac']: i['x_authkey'] for i in json.load(fp) } | 51 | keystore = {i['mac']: i['x_authkey'] for i in json.load(fp)} |
51 | 52 | ||
52 | return InformSerializer("", keystore) | 53 | return InformSerializer("", keystore) |
53 | 54 | ||
54 | 55 | ||
55 | if __name__ == "__main__": | 56 | if __name__ == "__main__": |
56 | ser = make_serializer("devices.json") | 57 | import glob |
57 | 58 | ser = make_serializer("data/devices.json") | |
58 | for i, data in enumerate(collect_records("mfi.out")): | 59 | |
59 | try: | 60 | for file in glob.glob("data/test_files/*.bin"): |
60 | packet = ser.parse(StringIO(data)) | 61 | fn, ext = os.path.splitext(file) |
61 | print packet.raw_payload | 62 | path = os.path.dirname(fn) |
62 | except ValueError: | 63 | fn = os.path.basename(fn) |
63 | pass | 64 | |
65 | with open(file) as fin, open(os.path.join(path, fn + ".txt"), 'w') as fout: | ||
66 | json.dump(json.loads(ser.parse(fin).raw_payload), fout, sort_keys=True, | ||
67 | indent=4, separators=(',', ': ')) | ||
68 | |||
69 | # for i, data in enumerate(collect_records("mfi.out")): | ||
70 | # try: | ||
71 | # packet = ser.parse(StringIO(data)) | ||
72 | # print packet.raw_payload | ||
73 | # except ValueError: | ||
74 | # pass | ||