Advertisement
Guest User

Untitled

a guest
May 5th, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import xml.etree.ElementTree as etree
  4. from optparse import OptionParser, OptionGroup
  5. import sys
  6.  
  7. # File to populate with missed hosts
  8. fname = 'missed-hosts.txt'
  9.  
  10.  
  11. parser = OptionParser(usage='usage: %prog -f <path/to/file.nessus>')
  12. parser.add_option('-f', '--file', action='store_true', dest='xml',
  13.                         help='designate Nessus XML file')
  14.  
  15.  
  16. (options, args) = parser.parse_args()
  17.  
  18. # Get .nessus file location
  19. if options.xml:
  20.     nessus = sys.argv[2]
  21. else:
  22.     parser.print_help()
  23.     sys.exit(0)
  24.  
  25.  
  26. #def check_from_file(all_hosts,nessus):
  27. #   un_specifiedlist = list()
  28. #   file_reader = open(location,'r')
  29. #   for line in file_reader.readlines():
  30. #       if line not in nessus:
  31. #           un_specifiedlist.append(line)
  32. #   writetofile(un_specifiedlist)
  33.  
  34.  
  35.  
  36.  
  37. def writetofile (arr):
  38.     f = open(fname, 'a')
  39.     f.write('Nessus missed the following hosts:\n')
  40.     for i in arr:
  41.         f.write(i + '\n')
  42.     f.close()
  43.  
  44.  
  45. print '[+] Loading Nessus file...'
  46.  
  47. # Attempt at parsing xml
  48. try:
  49.     tree = etree.parse(nessus)
  50. except:
  51.     print '[!] Invalid file'
  52.     sys.exit(0)
  53.  
  54.  
  55. # Looks for all hosts inside the xml file
  56. print '[+] Finding all hosts....'
  57. hosts = tree.findall('.//ReportHost')
  58.  
  59. if len(hosts) == 0:
  60.         print '[!] No hosts extracted, invalid Nessus XML file'
  61.         sys.exit(0)
  62.  
  63.  
  64. print '[+] Parsing through ReportItems...'
  65. missed_hosts = []
  66. for host in hosts:
  67.     missed_hosts.append(host.attrib['name'])
  68.  
  69. print '[+] Writing hosts to ' + fname
  70. writetofile(missed_hosts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement