@@ -471,6 +471,8 @@ def nmapxml(file=""):
471471 if no file name is given, then it tries stdin\n
472472 @return: returns true if it fails
473473 """
474+ import xml .etree .ElementTree as ET
475+
474476 global terms
475477 global STDIN
476478
@@ -496,47 +498,42 @@ def nmapxml(file=""):
496498 if content == "" or content [:5 ] != "<?xml" :
497499 STDIN = content
498500 return False
499- # making sure beautiful soup is importable first
500- try :
501- from bs4 import BeautifulSoup
502- except :
503- print (
504- "Error: you need to have beautifulsoup installed to properly use this program" )
505- print ("To install beautifulsoup, run 'pip install beautifulsoup4' in your commandline." )
506- return False
507501 # Read XML file
508502
509503 # ## Feedback to enduser
510504 if (type (file ) == str ):
511- print ("[i] Reading: " + highlightTerm (str (file ), str (file ), True ))
505+ print ("[i] Reading: " + highlightTerm (str (file ), str (file )))
512506 else :
513- print ("[i] Reading: " + highlightTerm (file .name , file .name , True ))
507+ print ("[i] Reading: " + highlightTerm (file .name , file .name ))
514508 tmpaddr = ""
515509 tmpname = ""
516510 # ## Read in XMP (IP, name, service, and version)
517- # xx This time with beautiful soup!
518- xmlsheet = BeautifulSoup ( content , "lxml" )
511+ root = ET . fromstring ( content )
512+
519513
520- hostsheet = xmlsheet . find_all ("host" )
514+ hostsheet = root . findall ("host" )
521515 for host in hostsheet :
522516 # made these lines to separate searches by machine
523- tmpaddr = host .find ("address" ).get ( "addr" )
517+ tmpaddr = host .find ("address" ).attrib [ "addr" ]
524518 tmpaddr = highlightTerm (tmpaddr , tmpaddr )
525- try :
526- tmpname = host .find ("hostname" ).get ("name" )
519+
520+ if (host .find ("hostnames/hostname" ) != None ):
521+ tmpname = host .find ("hostnames/hostname" ).attrib ["name" ]
527522 tmpname = highlightTerm (tmpname , tmpname )
528- except :
529- tmpname = " "
530523 print ("Finding exploits for " + tmpaddr +
531524 " (" + tmpname + ")" ) # print name of machine
532- for service in host .find_all ("service" ):
533- terms .append (str (service .get ("name" )))
534- terms .append (str (service .get ("product" )))
535- terms .append (str (service .get ("version" )))
525+ for service in host .findall ("ports/port/service" ):
526+ if "name" in service .attrib .keys ():
527+ terms .append (str (service .attrib ["name" ]))
528+ if "product" in service .attrib .keys ():
529+ terms .append (str (service .get ("product" )))
530+ if "version" in service .attrib .keys ():
531+ terms .append (str (service .get ("version" )))
536532 validTerm (terms )
537533 print ("Searching terms:" , terms ) # displays terms found by xml
538534 searchsploitout () # tests search terms by machine
539535 terms = [] # emptys search terms for next search
536+
540537 return True
541538
542539
0 commit comments