4sn3z

dorknet modificado

Mar 20th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.07 KB | None | 0 0
  1. #!/usr/bin/env python2.7
  2.  
  3. import argparse
  4. import sys
  5. import time
  6.  
  7. from selenium import webdriver
  8. from selenium.webdriver.common.keys import Keys
  9. from selenium.webdriver.common.by import By
  10. from selenium.webdriver.support.ui import WebDriverWait
  11. from selenium.webdriver.support import expected_conditions as EC
  12.  
  13.  
  14. # Check for args, print logo and usage
  15. if not len(sys.argv[1:]):
  16.     print """
  17. ____          _   _____     _  
  18. |    \ ___ ___| |_|   | |___| |_
  19. |  |  | . |  _| '_| | | | -_|  _|
  20. |____/|___|_| |_,_|_|___|___|_|  
  21.                              
  22. Welcome to DorkNet.
  23.  
  24. To start using this script please provide one or more command
  25. line arguments and their corresponding value, where applicable.
  26. To display all options available use -h or --help.
  27.  
  28. Example:
  29. DorkNet.py -h
  30. DorkNet.py -d inurl:show.php?id= --verbose\n"""
  31.    
  32.     sys.exit(0)
  33.  
  34.  
  35. # Handle command line arguments
  36. parser = argparse.ArgumentParser(description="Use this script and dorks to find vulnerable web applications.")
  37. group = parser.add_mutually_exclusive_group()
  38. group.add_argument("-d", "--dork", help="       specify the dork you wish to use\n")
  39. group.add_argument("-l", "--list", help="       specify path to list with dorks\n")
  40. parser.add_argument("-v", "--verbose", action="store_true", help="  toggle verbosity\n")
  41. args = parser.parse_args()
  42.  
  43. dork_list = []
  44.  
  45. # Dork list processing
  46. if args.list:
  47.     print "\n[+]Reading in list from: " + args.list + "\n\n"   
  48.     try:
  49.         with open(args.list, "r") as ins:
  50.             for line in ins:
  51.                 dork_list.append(line)
  52.                
  53.                 if args.verbose == True:
  54.                     print "[~]" + line
  55.                
  56.     except IOError as e:
  57.         print "\n[!]Could not read dork list"
  58.         if args.verbose == True:
  59.             print "\nAn IO Error was raised with the following error message: "
  60.             print "\n %s" % e
  61.            
  62. else:
  63.     dork_list.append(args.dork)
  64.  
  65.  
  66.  
  67. print "\nWould you like DorkNet to proxy its connection to the search engine?"
  68. query = raw_input("[Y]es/[N]o: ")
  69.  
  70. if query == 'y':
  71.     IP = raw_input("\nPlease enter the proxy host IP: ")
  72.     PORT = raw_input("\nPlease enter the proxy port: ")
  73.     set_proxy = True
  74. elif query == 'n':
  75.     print "\n[+]Establishing unproxied connection..."
  76.     set_proxy = False
  77. else:
  78.     print "\n[!]Unhandled option, defaulting to unproxied connection..."
  79.     set_proxy = False
  80.  
  81.  
  82. # Web Driver Proxy
  83. def proxy(PROXY_HOST,PROXY_PORT):
  84.     fp = webdriver.FirefoxProfile()
  85.     print "[+]Proxy host set to: " + PROXY_HOST
  86.     print "[+]Proxy port set to: " + PROXY_PORT
  87.     print "\n[+]Establishing connection..."
  88.     fp.set_preference("network.proxy.type", 1)
  89.     fp.set_preference("network.proxy.http",PROXY_HOST)
  90.     fp.set_preference("network.proxy.http_port",int(PROXY_PORT))
  91.     fp.set_preference("general.useragent.override","'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'")
  92.     fp.update_preferences()
  93.     return webdriver.Firefox(firefox_profile=fp)
  94.  
  95.  
  96. # Function to generate and process results based on input
  97. def search():
  98.     link_list = []
  99.    
  100.     if set_proxy == True:
  101.         driver = proxy(IP, PORT)
  102.     else:
  103.         driver = webdriver.Firefox()
  104.  
  105.     for int in range(1):
  106.         try:
  107.             driver.get("http://google.com")
  108.         except Exception as e:
  109.             print "\n[!]A connection could not be established"
  110.             if args.verbose == True:
  111.                 print "An error was raised with the following error message: "
  112.                 print "\n %s" % e
  113.             break
  114.             driver.quit()
  115.             sys.exit(0)
  116.  
  117.         assert "Google" in driver.title
  118.         for items in dork_list:
  119.             elem = driver.find_element_by_name("q")
  120.             elem.clear()
  121.             elem.send_keys(items)
  122.             elem.send_keys(Keys.RETURN)
  123.             time.sleep(1)
  124.  
  125.             try:
  126.                 WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "r")))
  127.             except Exception as e:
  128.                 driver.quit()
  129.                 print "\n[!]Detecting page source elements failed/timed out.\n"
  130.  
  131.                 if args.verbose == True:
  132.                     print "An error was raised with the following error message: "
  133.                     print "\n %s" % e
  134.  
  135.                 time.sleep(1.3)
  136.                 continue
  137.  
  138.  
  139.             assert "No results found" not in driver.page_source
  140.             if "No results found." in driver.page_source:
  141.                 driver.quit()
  142.                 continue
  143.             index = 0
  144.             while index <= 1000:
  145.                 try:
  146.                   links = driver.find_elements_by_xpath("//h3//a[@href]")
  147.                   for elem in links:
  148.                       link_list.append(elem.get_attribute("href"))
  149.                       index += 1
  150.                   next_page = driver.find_element_by_css_selector('#pnnext')
  151.                                   next_page.click()
  152.                   time.sleep(2)
  153.                 except Exception as errurl:
  154.                                   print "An error was raised with the following error message: "
  155.                                   print "\n %s" % errurl
  156.                   driver.quit()
  157.                   break
  158.  
  159.     driver.quit()
  160.     return link_list
  161.  
  162. proc_one = search()
  163.  
  164. with open("results.log", "w") as outfile:
  165.     for item in proc_one:
  166.         outfile.write("%s\n" % item)
  167.  
  168. if args.verbose == True:
  169.     with open("results.log", "r") as infile:
  170.         for line in infile:
  171.             print line
  172.  
  173.  
  174. print "\n\nDone. Results have been saved to a textfile, in the current directory as %s for further processing." % outfile
Advertisement
Add Comment
Please, Sign In to add comment