-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.py
506 lines (331 loc) · 14.7 KB
/
main.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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
#!/usr/bin/python3
import csv
import os
import tempfile
import exploitdb
import shodandb
import display
import time
class Main:
def __init__(self):
self.file = "files.csv"
self.os = os.name
self.foundList = []
self.headerList = []
self.width = None
self.height = None
self.file = "files.csv"
#Calls to main Functions of program
##
## self.searchDB(search)
## self.getTerminalSize()
## resultsPagesList = self.createPageLists(self.foundList)
## self.createPageListing(resultsPagesList)
self.getTerminalSize()
def getTerminalSize(self):
env = os.environ
def ioctl_GWINSZ(fd):
try:
import fcntl, termios, struct, os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
'1234'))
except:
return
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
### Use get(key[, default]) instead of a try/catch
#try:
# cr = (env['LINES'], env['COLUMNS'])
#except:
# cr = (25, 80)
self.width = int(cr[1])
self.height = int(cr[0])
def createTempFile(self,path): #Writes and opens a temporary file with the shell code in it.
with open(path,mode="r",encoding="utf-8") as myFile:
content = myFile.readlines()
with tempfile.NamedTemporaryFile(mode="w",delete=False) as temp:
for line in content:
temp.write(line)
temp.flush()
if self.os == "nt": #NT Systems - Windows
os.system('start notepad.exe ' + temp.name)
else: #Linux Systems
os.system('%s %s' % (os.getenv('EDITOR'), temp.name))
def createTempFileShodan(self,content): #Writes and opens a temporary file with the shell code in it.
with tempfile.NamedTemporaryFile(mode="w",delete=False) as temp:
for line in content:
temp.write(line)
temp.flush()
if self.os == "nt": #NT Systems - Windows
os.system('start notepad.exe ' + temp.name)
else: #Linux Systems
os.system('%s %s' % (os.getenv('EDITOR'), temp.name))
def createPageListingExploitDB(self,resultsPagesList):
width = self.width
height = self.height
totalResults = len(self.foundList)
end = False
print("-" * width)
currentPage = 0
pageNavigation = """
________________________________________________________________
| |
| Navigation Options |
| |
| - Enter 'p' followed by page number (e.g. 'p4', 'p5') |
| - Enter 'e' followed by the exploit number (e.g. 'e3', 'e11') |
| - Enter 'exit' to return to the main menu |
|________________________________________________________________|
"""
totalNumOfPages = len(resultsPagesList)
print(pageNavigation)
input("Press [enter] to continue...")
while end == False:
print("-" * width)
print("Current page - {0}".format(currentPage + 1),end=" | ")
print("Exploits - {0}".format(totalResults),end=" | ")
print("Pages - {0}".format(totalNumOfPages),end="\n")
print()
for num in range(0,len(resultsPagesList[currentPage])):
print("{0}. {1}".format((((currentPage + 1) * 10) - 10 + (num + 1)),resultsPagesList[currentPage][num][2]))
#resultsPagesList[currentPage][num]['pagenum'] = currentPage
print()
print("-" * width)
print()
try:
choice = input("Enter option: ")
if choice == 'exit':
break
else:
pNumber = int(choice[1:])
##Navigate pages
if choice[0] == "p":
if pNumber > 0 and pNumber <= totalNumOfPages:
currentPage = int(choice[1:]) - 1
else:
print()
print("Please choose a page number in range...")
##Navigate Exploits
elif choice[0] == "e":
exploitNumber = int(choice[1:])
exploitMenu = """
_______________________________
| |
| Exploit Options |
| |
| 1. View Full Details |
| 2. View Shell Code |
| 3. Continue |
|_______________________________|
"""
print(exploitMenu)
exploitMenuChoice = 0
while exploitMenuChoice != 3:
if exploitNumber % 10 == 0:
pageOfExploit = (exploitNumber // 10) - 1
exploitNumInList = 9
else:
pageOfExploit = (exploitNumber // 10)
exploitNumInList = (exploitNumber % 10) - 1
print("-" * width)
exploitMenuChoice = int(input("Please choose an option: "))
if exploitMenuChoice == 1:
print("\nFull Details\n")
for each in self.headerList:
print(each)
elif exploitMenuChoice == 2:
try:
#Open the code of the exploit in a temp file
if exploitNumber % 10 == 0:
pageOfExploit = (exploitNumber // 10) - 1
exploitNumInList = 9
self.createTempFile(resultsPagesList[pageOfExploit][exploitNumInList][1])
else:
pageOfExploit = (exploitNumber // 10)
exploitNumInList = (exploitNumber % 10) - 1
self.createTempFile(resultsPagesList[pageOfExploit][exploitNumInList][1])
except KeyError:
print("Code unvailable for this exploit. Refer to online site for database provider.")
elif choice == 3:
continue
except ValueError:
print()
print("Please enter a valid option !")
def createPageListingShodan(self,resultsPagesList, keyDataList):
width, height = self.width, self.height
totalResults = keyDataList[0]
end = False
print("-" * width)
currentPage = 0
pageNavigation = """
________________________________________________________________
| |
| Navigation Options |
| |
| - Enter 'p' followed by page number (e.g. 'p4', 'p5') |
| - Enter 'e' followed by the exploit number (e.g. 'e3', 'e11') |
| - Enter 'exit' to return to the main menu |
|________________________________________________________________|
"""
totalNumOfPages = len(resultsPagesList)
print(pageNavigation)
input("Press [enter] to continue...")
while end == False:
print("-" * width)
print("Current page - {0}".format(currentPage + 1),end=" | ")
print("Exploits - {0}".format(totalResults),end=" | ")
print("Pages - {0}".format(totalNumOfPages),end="\n")
print()
for num in range(0,len(resultsPagesList[currentPage])):
descTitle = resultsPagesList[currentPage][num]['description'].split('\n',1)
descTitle = descTitle[0]
print("{0}. {1}".format((((currentPage + 1) * 10) - 10 + (num + 1)),descTitle))
resultsPagesList[currentPage][num]['pagenum'] = currentPage
print()
print("-" * width)
print()
try:
choice = input("Enter option: ")
if choice == 'exit':
break
else:
pNumber = int(choice[1:])
##Navigate pages
if choice[0] == "p":
if pNumber > 0 and pNumber <= totalNumOfPages:
currentPage = int(choice[1:]) - 1
else:
print()
print("Please choose a page number in range...")
##Navigate Exploits
elif choice[0] == "e":
exploitNumber = int(choice[1:])
exploitMenu = """
_______________________________
| |
| Exploit Options |
| |
| 1. View Full Details |
| 2. View Shell Code |
| 3. Continue |
|_______________________________|
"""
print(exploitMenu)
exploitMenuChoice = 0
while exploitMenuChoice != 3:
if exploitNumber % 10 == 0:
pageOfExploit = (exploitNumber // 10) - 1
exploitNumInList = 9
else:
pageOfExploit = (exploitNumber // 10)
exploitNumInList = (exploitNumber % 10) - 1
print("-" * width)
exploitMenuChoice = int(input("Please choose an option: "))
if exploitMenuChoice == 1:
print("\nFull Details\n")
for key,value in resultsPagesList[pageOfExploit][exploitNumInList].items():
if key == 'code':
print("Code \t\t\t See Code Option")
elif key == 'description':
print("Desc \t\t\t",value)
elif key == 'platform':
print(key.title(), "\t\t",value)
elif key == 'pagenum':
print(key.title(), "\t\t",value)
else:
print(key.title(), "\t\t\t",value)
elif exploitMenuChoice == 2:
try:
#Open the code of the exploit in a temp file
if exploitNumber % 10 == 0:
pageOfExploit = (exploitNumber // 10) - 1
exploitNumInList = 9
self.createTempFileShodan(resultsPagesList[pageOfExploit][exploitNumInList]['code'])
else:
pageOfExploit = (exploitNumber // 10)
exploitNumInList = (exploitNumber % 10) - 1
self.createTempFileShodan(resultsPagesList[pageOfExploit][exploitNumInList]['code'])
except KeyError:
print("Code unvailable for this exploit. Refer to online site for database provider.")
elif choice == 3:
continue
except ValueError:
print()
print("Please enter a valid option !")
def createPageListsExploitDB(self,results):
#Too much data to output at once format into pages
resultsPagesList = []
totalResults = len(results)
if totalResults > 10:
totalPages = int(totalResults // 10)
if (totalResults % 10) > 0:
totalPages += 1
for page in range(1,totalPages + 1):
resultsList = []
#Counter Variables for creating lists for each page
endNum = (page * 10)
startNum = (page * 10) - 10
#If last page use the total pages variable as the end number
if endNum > totalResults:
endNum = totalResults
#Create lists
resultsList = results[startNum:endNum]
resultsPagesList.append(resultsList)
#10 or less results = one page
else:
endNum = totalResults
startNum = 0
#Create lists
resultsList = results[startNum:endNum]
resultsPagesList.append(resultsList)
return resultsPagesList
endNum = (page * 10)
startNum = (page * 10) - 10
#If last page use the total pages variable as the end number
if endNum > totalResults:
endNum = totalResults
#Create lists
resultsList = results[startNum:endNum]
resultsPagesList.append(resultsList)
#10 or less results = one page
else:
endNum = totalResults
startNum = 0
#Create lists
resultsList = results[startNum:endNum]
resultsPagesList.append(resultsList)
return resultsPagesList
if __name__ == "__main__":
end = False
while end != True:
displayLib = display.Display()
option = int(input("Please choose now:"))
main = Main()
if option == 1:
try:
try:
searchQuery = input("Search Query:")
except ValueError:
print("Please enter a correct search string...")
newShodan = shodandb.ShodanDB_Search(searchQuery)
resultsPagesList, keyDataList = newShodan.searchShodan()
main.createPageListingShodan(resultsPagesList, keyDataList)
except Exception as e:
print("\nError Reporting: {0}\n".format(e))
input("Press enter to continue...")
elif option == 2:
searchQuery = input("Search Query:")
eDB = exploitdb.ExploitDB_Search(searchQuery)
eDB.searchDB()
foundList = eDB.foundList
resultsPagesList = main.createPageListsExploitDB(foundList)
main.createPageListingExploitDB(resultsPagesList)