@@ -505,6 +505,53 @@ def nmapxml(file=""):
505505 terms = [] # emptys search terms for next search
506506 return True
507507
508+
509+ def nmapgrep (file = "" ):
510+ """
511+
512+ """
513+ global terms
514+
515+ # First check whether file exists or use stdin
516+ try :
517+ content = open (file , "r" ).read ()
518+ except :
519+ if (not os .sys .stdin .isatty ()):
520+ content = os .sys .stdin .read ()
521+ else :
522+ return False
523+
524+ # Check whether its grepable
525+ if (content .find ("Host: " ) == - 1 and "-oG" in content .split ("\n " )[0 ]):
526+ return False
527+
528+ # making a matrix to contain necessary strings
529+ nmatrix = content .split ("\n " )
530+ for lines in range (len (nmatrix ) - 1 , - 1 , - 1 ):
531+ if (nmatrix [lines ].find ("Host: " ) == - 1 or nmatrix [lines ].find ("Ports: " ) == - 1 ):
532+ nmatrix .pop (lines )
533+ else :
534+ nmatrix [lines ] = nmatrix [lines ].split ("\t " )[:- 1 ]
535+ nmatrix [lines ][0 ] = nmatrix [lines ][0 ][6 :].split (" " )
536+ nmatrix [lines ][0 ][1 ] = nmatrix [lines ][0 ][1 ][1 :- 1 ] if (len (nmatrix [lines ][0 ][1 ]) > 2 ) else "" # pull hostname out of parenthesis
537+ nmatrix [lines ][1 ] = nmatrix [lines ][1 ][7 :].split (", " )
538+ for j in range (len (nmatrix [lines ][1 ])):
539+ nmatrix [lines ][1 ][j ] = nmatrix [lines ][1 ][j ].replace ("/" , " " ).split ()[3 :]
540+ print (nmatrix )
541+ # Outputing results from matrix
542+ for host in nmatrix :
543+ tmpaddr = highlightTerm (host [0 ][0 ], host [0 ][0 ], True )
544+ tmpname = highlightTerm (host [0 ][1 ], host [0 ][1 ], True )
545+ print ("Finding exploits for " + tmpaddr +
546+ " (" + tmpname + ")" ) # print name of machine
547+ for service in host [1 ]:
548+ terms .extend (service )
549+ validTerm (terms )
550+ print ("Searching terms:" , terms ) # displays terms found by grep
551+ searchsploitout () # tests search terms by machine
552+ terms = [] # emptys search terms for next search
553+ return True
554+
508555##########################
509556## COMMAND FUNCTIONS ##
510557##########################
@@ -519,6 +566,7 @@ def path(id):
519566 except TypeError :
520567 print ("%s does not exist. Please double check that this is the correct id." % id )
521568
569+
522570def mirror (id ):
523571 """ Function used to mirror exploits
524572 """
0 commit comments