Advertisement
f8lerror

GatherSploits.py

Mar 1st, 2013
6,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Gather Sploits by f8lerror
  3.  
  4.  
  5. import csv
  6. import argparse
  7. from shodan import WebAPI
  8. from xml.dom import minidom
  9.  
  10. SHODAN_API_KEY = ""#Your SHODAN API key HERE!!!!!!!!!!!
  11. api = WebAPI(SHODAN_API_KEY)
  12.  
  13. parser = argparse.ArgumentParser(description='Gather Sploits by Port')
  14. parser.add_argument('-x', '--xml', help='Nmap results in XML format', required=True)
  15. parser.add_argument('-l','--local', help='Data gathered from /pentest/exploits/exploitdb/files.csv', action='store_true', required=False)
  16. parser.add_argument('-o','--output', help='Outputs to File gsploits.txt', action='store_true', required=False)
  17. parser.add_argument('-f','--force', help='Force OS search. ex. windows, linux, osX',required=False)
  18. parser.add_argument('-a','--all', help='All os search', action='store_true', required=False)
  19. args = parser.parse_args()
  20.  
  21. def outfile(host,op2,args):
  22.  
  23.     ofile = open('gsploits.txt', 'a')
  24.     ofile.write(host+' | '+op2+'\n')
  25.  
  26. def onlinesearch(host, port, osd, args):
  27.  
  28.     results = api.exploitdb.search('port:'+str(port))
  29.     if osd != "all":
  30.         print '\nResults for: ' + host +':'+ port +' OS='+osd
  31.         for exploit in results['matches']:
  32.             if exploit['platform'] == osd or exploit['platform'] == 'multiple':
  33.                 op1 = str(exploit['port']),' | ', exploit['platform'],' | ',exploit['date'],' | ','http://www.exploit-db.com/exploits/'+str(exploit['id']),' | ',exploit['description']
  34.                 op1 = ''.join(op1)
  35.                 print op1
  36.                 if args.output:
  37.                     outfile(host, op1, args)
  38.     else:
  39.         print '\nResults for: ' + host +':'+ port +' OS='+osd
  40.         for exploit in results['matches']:
  41.             op1 = str(exploit['port']),' | ', exploit['platform'],' | ',exploit['date'],' | ','http://www.exploit-db.com/exploits/'+str(exploit['id']),' | ',exploit['description']
  42.             op1 = ''.join(op1)
  43.             print op1
  44.             if args.output:
  45.                 outfile(host, op1,args)
  46.  
  47. def localsearch(host, port, osd, args):
  48.  
  49.     try:
  50.         myfilepath = file("/pentest/exploits/exploitdb/files.csv", "r")#change this if you need too.
  51.         mycsv = csv.reader(myfilepath)
  52.     except:
  53.         print 'Cannot find CSV file try an online search using the -o or -h for help'
  54.         exit(0)
  55.     if osd != "all":
  56.         print '\nResults for: ' + host +':'+ port +' OS='+osd
  57.         print 'found os'
  58.         for row in mycsv:
  59.             if row[7] == port:
  60.                 if row[5] == osd:
  61.                     op1 = row[7],' | ',row[5],' | ',row[3],' | ', row[1],' | ', row[2]
  62.                     op1 = ''.join(op1)
  63.                     print op1
  64.                     if args.output:
  65.                         outfile(host, op1, args)
  66.     else:
  67.         print '\nDisplaying results for: ' + host +':'+ port +' OS='+osd
  68.         print
  69.         for row in mycsv:
  70.             if row[7] == port:
  71.                 op1 = row[7],' | ',row[5],' | ',row[3],' | ', row[1],' | ', row[2]
  72.                 op1 = ''.join(op1)
  73.                 print op1
  74.                 if args.output:
  75.                     outfile(host, op1,args)
  76.  
  77. def parsit():
  78.  
  79.     xmldoc = minidom.parse(args.xml)
  80.     blah = xmldoc.getElementsByTagName('host')
  81.     for dhost in  blah:
  82.         host = dhost.getElementsByTagName('address')[0].getAttributeNode('addr').value
  83.         osd = None
  84.         try:
  85.             for osid in dhost.getElementsByTagName('osclass'):
  86.                 osd = osid.attributes['osfamily'].value
  87.                 osd = osd.lower()
  88.                 if args.all:
  89.                     osd = "all"
  90.                 elif args.force:
  91.                     osd = args.force
  92.         except:
  93.             osd = "all"
  94.             if args.force:
  95.                 osd = args.force
  96.             else:
  97.                 osd = "all"
  98.         for dportid in dhost.getElementsByTagName('port'):
  99.             port = dportid.getAttributeNode('portid').value
  100.             if osd == None:
  101.                 osd = "all"
  102.                 if args.force:
  103.                     osd = args.force
  104.                 if args.local:
  105.                     localsearch(host, port, osd, args)
  106.                 else:
  107.  
  108.                     onlinesearch(host, port, osd, args)
  109.  
  110.             else:
  111.                 if args.force:
  112.                     osd = args.force
  113.                 if args.local:
  114.                     localsearch(host, port, osd, args)
  115.                 else:
  116.                     onlinesearch(host, port, osd, args)
  117.  
  118. parsit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement