-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_rsploit.py
More file actions
executable file
·339 lines (307 loc) · 9.26 KB
/
process_rsploit.py
File metadata and controls
executable file
·339 lines (307 loc) · 9.26 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import os,sys
if len(sys.argv) < 2:
print("Usage: process_fuzzreplay [TARGET_FOLDER]")
exit()
LOGFOLDER = sys.argv[1]
if not os.path.exists(LOGFOLDER) or not os.path.isdir(LOGFOLDER):
print("Invalid dir")
exit()
print("Working on %s..." % LOGFOLDER)
exploitmap = dict()
targetmap = dict()
rcemap = dict()
offbrandmap = dict()
samebrandmap = dict()
devicemap = dict()
blacklist = set()
IDS = os.listdir(LOGFOLDER)
total = len(IDS)
count = 0
extensions = [".rar", ".zip", ".tar", ".bin"]
print(" ids: ", total)
print("-"*50)
print("Processing exploit references...")
print("-"*50)
with open("blacklist.list", "r") as blacklistFile:
for line in blacklistFile:
line = line.strip()
blacklist.add(line)
blacklistFile.close()
# with open("exploitdump.log", "w+") as eOutFile:
# for exploit, targets in exploitmap.items():
# # print(exploit)
# for target in sorted(targets):
# # print("%s,%s" % (target, exploit))
# line = "%s,%s" % (target, exploit)
# eOutFile.write(line)
# eOutFile.write("\n")
# eOutFile.close()
exploitlist = []
with open("exploits.list", "r") as exploitFile:
for line in exploitFile:
line = line.strip()
if line.startswith("#"):
continue
exploitlist.append(line)
eollist = []
devicemap = dict()
with open("eol.list", "r") as eolFile:
for line in eolFile:
# print(line)
line = line.strip()
eollist.append(line)
fields = line.split()
brand = fields[0].strip()
name = fields[1].strip()
device = fields[2].split("/")[-2].strip()
devicemap[name] = device
print("-"*50)
print("References compiled, writing processing logs...")
print("-"*50)
missing = set()
unknown = set()
for targetfile in IDS:
count += 1
if "_" not in targetfile:
continue
# print(" - processing [%d/%d]: %s" % (count, total, targetfile))
if count % 250 == 0:
print(" - processing %d/%d" % (count, total))
target = targetfile.split("_")[0].strip()
hashname = targetfile.split("_")[1].strip()
targetpath = os.path.join(LOGFOLDER, targetfile)
with open(targetpath, "rb") as targetFile:
exploit = ""
tag = ""
brand = ""
vulnerable = False
validated = "N"
for line in targetFile:
if line.startswith(b"Target: "):
targetname = line.split(b"/")[-1].strip().decode("utf-8", errors="ignore")
for ext in extensions:
if targetname.lower().endswith(ext):
targetname = targetname.rsplit(".", 1)[0]
if b"Running initializer on" in line:
brand = line.split()[3].strip().decode("utf-8", errors="ignore")
tag = "%s,%s,%s" % (brand, target, targetname)
if targetname not in devicemap.keys() and targetfile not in missing:
print(" - missing", targetname, targetfile)
missing.add(targetfile)
# print(targetname)
if b"Testing exploit" in line:
exploit = line.split()[-1].strip().decode("utf-8", errors="ignore").strip("/")
exploitbrand = exploit.split("/")[-2].strip()
vulnerable = False
validated = "N"
# print(" - processing: ", exploit)
if exploit and line.startswith(b"SIGSEGV_HAPPENED") or b".core" in line or \
b"SERVER CRASHED" in line or line.startswith(b"GHRCE") or \
(b"AAAAA" in line and b"is vulnerable" in line):
if line.startswith(b"GHRCE") or \
(b"AAAAA" in line and b"is vulnerable" in line):
validated = "Y"
vulnerable = True
if b" >> SERVER" in line:
if b"MALFUNCTION" not in line and exploit and vulnerable:
if exploit not in exploitmap.keys():
exploitmap[exploit] = list()
if tag not in exploitmap[exploit]:
exploitmap[exploit].append(tag)
# print(" - adding", exploit, tag)
if target not in targetmap.keys():
targetmap[target] = list()
offbrandmap[target] = list()
samebrandmap[target] = list()
rcetag = target+"_"+exploit
if exploit not in targetmap[target]:
if exploit not in exploitlist:
if exploit not in unknown:
print(" x - skipping unknown exploit", exploit)
unknown.add(exploit)
else:
targetmap[target].append(exploit)
rcemap[rcetag] = validated
if brand != exploitbrand:
offbrandmap[target].append(exploit)
else:
samebrandmap[target].append(exploit)
exploit = b""
targetFile.close()
print(" - processed %d/%d" % (count, total))
total = len(eollist)
count = 0
# print("-"*50)
# print("Writing seed map")
# print("-"*50)
# for exploit in exploitlist:
# if exploit.startswith("#"):
# continue
# count += 1
# if count % 250 == 0:
# print(" - writing %d/%d" % (count, total))
# exploitname = exploit.strip()
# if exploit not in exploitmap.keys():
# continue
# targets = exploitmap[exploit]
# for target in targets:
# fields = target.split(",")
# brand = fields[0].strip()
# devid = fields[1].strip()
# name = fields[2].strip()
# device = devicemap[name]
# if device in blacklist or exploitname.endswith(".txt"):
# continue
# seedpath = os.path.join("seedmap", devid)
# exploit_tag = exploitname.split("/")[1]+"_id_"+exploitname.split(":")[1].split(",")[0]
# # print(" >", exploit_tag)
# with open(seedpath, "w+") as seedFile:
# seedFile.write(exploit_tag+"\n")
# seedFile.close()
print("-"*50)
print("Writing device.matrix")
print("-"*50)
total = len(exploitlist)
count = 0
deviceList = []
with open("device.matrix", "w+") as matrixFile:
for exploit in exploitlist:
if exploit.startswith("#"):
continue
count += 1
if count % 250 == 0:
print(" - writing %d/%d" % (count, total))
exploitname = exploit.strip()
if exploit not in exploitmap.keys():
continue
targets = exploitmap[exploit]
hits = ""
seen = set()
for target in targets:
# print(target)
fields = target.split(",")
brand = fields[0].strip()
devid = fields[1].strip()
name = fields[2].strip()
if name not in devicemap.keys():
print(" x - missing", name)
continue
device = devicemap[name]
if device in seen:
continue
seen.add(device)
targethits = len(targetmap[devid])
offbrandhits = len(offbrandmap[devid])
# print("%s,%s,%s,%s" % (brand, device, name, exploithits))
outline = "%s %s %d %d\n" % (exploit, device, targethits, offbrandhits)
matrixFile.write(outline)
if device not in deviceList:
deviceList.append(device)
falsepositive = set()
dedup = set()
count = 0
print("Writing exploits.matrix")
print("-"*50)
with open("exploits.matrix", "w") as matrixFile, open("exploits.same.matrix", "w") as matrixOnBrand, open("exploits.diff.matrix", "w") as matrixOffBrand:
for exploit in exploitlist:
if exploit.startswith("#"):
continue
count += 1
if count % 250 == 0:
print(" - writing %d/%d" % (count, total))
exploitname = exploit.strip()
exploitbrand = exploit.split("/")[-2].strip()
if exploit not in exploitmap.keys():
continue
targets = exploitmap[exploit]
hits = ""
outline = None
seen = set()
exploit_numhits = len(targets)
for target in targets:
# print(target)
fields = target.split(",")
brand = fields[0].strip()
devid = fields[1].strip()
name = fields[2].strip()
if name not in devicemap.keys():
print(" x - missing", name)
continue
if name in blacklist:
print(" x - blacklisted", name)
continue
device = devicemap[name]
if device in seen:
continue
# seen.add(device)
targethits = len(targetmap[devid])
validated = rcemap[devid+"_"+exploit]
# print("%s,%s,%s,%s" % (brand, device, name, exploithits))
if targethits < len(exploitlist):
# outline = "%s %s %s %s %s %d/%d:%d/%d\n" % (exploit, brand, device, name, devid, targethits, len(exploitlist), exploit_numhits, len(deviceList))
outline = "%s %s %s %s %s %d %s\n" % (exploit, brand, device, name, devid, exploit_numhits, validated)
else:
if target not in falsepositive:
print(" -x false positive", target)
falsepositive.add(target)
if outline and outline not in dedup:
matrixFile.write(outline)
if brand == exploitbrand:
matrixOnBrand.write(outline)
else:
matrixOffBrand.write(outline)
dedup.add(outline)
matrixFile.close()
print("-"*50)
print("Writing brand.matrix")
print("-"*50)
total = len(exploitlist)
count = 0
brands = ["asus", "belkin", "dlink", "linksys", "netgear", "tenda", "tplink", "trendnet", "ZyXEL"]
with open("brand.matrix", "w+") as matrixFile:
outline = "crashname "
for b in brands:
outline += "%s " % b
outline += "\n"
matrixFile.write(outline)
for exploit in exploitlist:
if exploit.startswith("#"):
continue
count += 1
if count % 250 == 0:
print(" - writing %d/%d" % (count, total))
outline = "%s" % (exploit)
exploitname = exploit.strip()
if exploit not in exploitmap.keys():
continue
targets = exploitmap[exploit]
hits = ""
seen = set()
brandcount = dict()
for target in targets:
# print(target)
fields = target.split(",")
brand = fields[0].strip()
devid = fields[1].strip()
name = fields[2].strip()
if name not in devicemap.keys():
print(" x - missing", name)
continue
device = devicemap[name]
if device in seen:
continue
seen.add(device)
if brand not in brandcount.keys():
brandcount[brand] = 0
brandcount[brand] += 1
for brand in brands:
if brand in brandcount.keys():
numhits = brandcount[brand]
else:
numhits = 0
outline += " %d" % (numhits)
outline += "\n"
matrixFile.write(outline)
print("-"*50)
print("Done")
print("-"*50)