Skip to content

Commit 0f9baee

Browse files
committed
Replaced all globals with argparse values (#2)
1 parent 4b284c2 commit 0f9baee

File tree

1 file changed

+16
-37
lines changed

1 file changed

+16
-37
lines changed

searchsploit.py

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@
44
import argparse
55

66
# Default options
7-
COLOUR = True
8-
EDBID = False
9-
EXACT = False
10-
JSON = False
11-
OVERFLOW = False
12-
WEBLINK = False
13-
TITLE = False
14-
IGNORE = False
15-
CASE = False
167
COL = 0
178
STDIN = "" # made to hold standard input for multiple functions
189

@@ -293,7 +284,7 @@ def highlightTerm(line, term, autoComp=False):
293284
def separater(lim, line1, line2):
294285
""" Splits the two texts to fit perfectly within the terminal width
295286
"""
296-
if OVERFLOW:
287+
if parseArgs.overflow:
297288
line = line1 + " | " + line2
298289
line = line.replace(":8", '\033[91m').replace(":9", '\033[0m')
299290
print(line)
@@ -395,19 +386,19 @@ def validTerm(argsList):
395386
invalidTerms = ["microsoft", "microsoft windows", "apache", "ftp",
396387
"http", "linux", "net", "network", "oracle", "ssh", "ms-wbt-server", "unknown", "none"]
397388
dudTerms = ["unknown", "none"]
398-
if EXACT:
389+
if parseArgs.exact:
399390
return argsList
400391
argsList.sort()
401392
argslen = len(argsList)
402393
for i in range(argslen - 1, 0, -1):
403394
if (argsList[i].lower() in dudTerms):
404395
argsList.pop(i)
405-
elif (argsList[i].lower() in invalidTerms and not IGNORE):
396+
elif (argsList[i].lower() in invalidTerms and not parseArgs.ignore):
406397
print(
407398
"[-] Skipping term: " + argsList[i] + " (Term is too general. Please re-search manually:")
408399
argsList.pop(i)
409400
# Issues, return with something
410-
elif not CASE:
401+
elif not parseArgs.case:
411402
argsList[i] = argsList[i].lower()
412403
argsList.sort()
413404
argslen = len(argsList)
@@ -433,7 +424,7 @@ def searchdb(path="", terms=[], cols=[], lim=-1):
433424
"""
434425
searchTerms = []
435426
tmphold = []
436-
if EXACT:
427+
if parseArgs.exact:
437428
tmpstr = str(terms[0])
438429
for i in range(1, len(terms)):
439430
tmpstr += " " + terms[i]
@@ -444,14 +435,14 @@ def searchdb(path="", terms=[], cols=[], lim=-1):
444435
for lines in db:
445436
if (lines != ""):
446437
for term in terms:
447-
if TITLE:
438+
if parseArgs.title:
448439
line = lines.split(",")[2]
449-
if CASE:
440+
if parseArgs.case:
450441
if term not in line:
451442
break
452443
elif term not in line.lower():
453444
break
454-
elif CASE:
445+
elif parseArgs.case:
455446
if term not in lines:
456447
break
457448
elif term not in lines.lower():
@@ -475,7 +466,7 @@ def searchsploitout():
475466

476467
# xx validating terms
477468
validTerm(terms)
478-
if JSON:
469+
if parseArgs.json:
479470
jsonDict = {}
480471
temp = ""
481472
for i in terms:
@@ -504,9 +495,9 @@ def searchsploitout():
504495
query = [] # temp variable thatll hold all the results
505496
try:
506497
for i in range(len(files_array)):
507-
if EDBID:
498+
if parseArgs.id:
508499
query = searchdb(os.path.abspath(os.path.join(path_array[i], files_array[i])), terms, [2, 0])
509-
elif WEBLINK:
500+
elif parseArgs.www:
510501
query = searchdb(os.path.abspath(os.path.join(path_array[i], files_array[i])), terms, [2, 1, 0])
511502
else:
512503
query = searchdb(os.path.abspath(os.path.join(path_array[i], files_array[i])), terms, [2, 1])
@@ -519,14 +510,14 @@ def searchsploitout():
519510
separater(COL/4, "", os.path.abspath(path_array[i]))
520511
drawline(lim) # display title for every database
521512
for lines in query:
522-
if WEBLINK: # if requesting weblinks. shapes the output for urls
513+
if parseArgs.www: # if requesting weblinks. shapes the output for urls
523514
lines[1] = "https://www.exploit-db.com/" + \
524515
lines[1][:lines[1].index("/")] + "/" + lines[2]
525-
if COLOUR:
516+
if parseArgs.colour:
526517
for term in terms:
527518
lines[0] = highlightTerm(lines[0], term)
528519
lines[1] = highlightTerm(lines[1], term)
529-
if EDBID:
520+
if parseArgs.id:
530521
# made this change so that ids get less display space
531522
separater(int(COL * 0.8), lines[0], lines[1])
532523
else:
@@ -733,15 +724,6 @@ def run():
733724
"""
734725

735726
# global variables brought down
736-
global CASE
737-
global EXACT
738-
global IGNORE
739-
global JSON
740-
global OVERFLOW
741-
global TITLE
742-
global WEBLINK
743-
global COLOUR
744-
global EDBID
745727

746728
if (len(argv) == 1 and os.sys.stdin.isatty()):
747729
usage() # runs if given no arguements
@@ -803,12 +785,9 @@ def run():
803785
if (not os.sys.stdin.isatty()):
804786
text = str(os.sys.stdin.read())
805787
terms.extend(text.split())
806-
if terms == []:
807-
usage() # if no actual terms were made just arguements, then exit
808-
return
809788

810789
# Colors for windows
811-
if COLOUR and os.sys.platform == "win32":
790+
if parseArgs.colour and os.sys.platform == "win32":
812791
try:
813792
import colorama
814793
except ImportError:
@@ -817,7 +796,7 @@ def run():
817796
print(
818797
"\"pip install colorama\" in your terminal so that windows can use colors.")
819798
print("Printing output without colors")
820-
COLOUR = False
799+
parseArgs.colour = False
821800
else:
822801
colorama.init()
823802
searchsploitout()

0 commit comments

Comments
 (0)