This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmobile_devices_parser.py
More file actions
104 lines (73 loc) · 2.77 KB
/
mobile_devices_parser.py
File metadata and controls
104 lines (73 loc) · 2.77 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
97
98
99
100
101
102
103
104
#!/usr/bin/env python
'''
mobile devices parser
Version 0.1
by Roy Firestein (roy@firestein.net)
Parse mobile devices audit plugin and export to CSV
'''
import os
import xml.dom.minidom
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f", "--file", action="store", type="string", dest="file", help="Nessus file to parse")
parser.add_option("-o", "--output", action="store", type="string", dest="output", help="output file name")
(menu, args) = parser.parse_args()
devices = {"Android": [], "iPhone": [], "iPad": []}
def main():
nes_file = menu.file
report = xml.dom.minidom.parse(nes_file)
for el in report.getElementsByTagName('ReportItem'):
if el.getAttribute("pluginID") == "60035":
# find plugin_output element
output = get_plugin_output(el)
model = get_model(output)
version = get_version(output)
user = get_user(output)
serial = get_serial(output)
item = {"serial": serial, "version": version, "user": user}
if not item in devices[model]:
devices[model].append(item)
print "%s\t%s\t%s\t%s" %(model, version, user, serial)
if len(devices['iPhone']) > 0 or len(devices['iPad']) > 0 or len(devices['Android']) > 0:
save_csv(devices)
def save_csv(devices):
fh = open(menu.output, "w")
fh.write("Platform,User,Version,Serial\n")
for d in devices['iPhone']:
fh.write('"%s","%s","%s","%s"\n' %("iPhone", d['user'], d['version'], d['serial']))
for d in devices['iPad']:
fh.write('"%s","%s","%s","%s"\n' %("iPad", d['user'], d['version'], d['serial']))
for d in devices['Android']:
fh.write('"%s","%s","%s","%s"\n' %("Android", d['user'], d['version'], d['serial']))
fh.close()
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
def get_plugin_output(el):
a = el.getElementsByTagName("plugin_output")[0]
return getText(a.childNodes)
def get_model(data):
for line in data.split("\n"):
if line.startswith("Model"):
return line.split(" ")[2]
return None
def get_version(data):
for line in data.split("\n"):
if line.startswith("Version"):
return line.split(" ")[2]
return None
def get_user(data):
for line in data.split("\n"):
if line.startswith("User"):
return line.split(" ")[2]
return None
def get_serial(data):
for line in data.split("\n"):
if line.startswith("Serial"):
return line.split(" ")[3]
return None
if __name__ == "__main__":
main()