Shutup RisiR.
This is the code that worked for me:
#!/usr/bin/env python2.7
import re
import argparse
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Check for args, print logo and usage
if not len(sys.argv[1:]):
print """
__ _ ___
| \ ___ _ _| |_| __|__ _ _ __ _ ___
| |) / _ \ '_| / / _/ _ \ '_/ _` / -_)
|___/\___/_| |_\_\_|\___/_| \__, \___|
|___/
Welcome to DorkForge.
To start using this script please provide one or more command
line arguments and their corresponding value, where applicable.
To display all options available use -h or --help.
Example:
DorkForge.py -h
DorkForge.py -d inurl:show.php?id= --verbose\n"""
sys.exit(0)
# Handle command line arguments
parser = argparse.ArgumentParser(description="Use this script and dorks to find vulnerable web applications.")
group = parser.add_mutually_exclusive_group()
group.add_argument("-d", "--dork", help="specify the dork you wish to use\n")
group.add_argument("-l", "--list", help="specify path to list with dorks\n")
parser.add_argument("-p", "--pages", default=1, type=int, help="specify amount of pages to check\n")
parser.add_argument("-v", "--verbose", help="toggle verbosity\n")
args = parser.parse_args()
dork_list = []
# If list, read item in
if args.list:
try:
with open(args.list, "r") as ins:
for line in ins:
dork_list.append(line)
except IOError:
print "Could not read dork list"
if args.verbose == True:
print "An IO Error was raised with the following error message: "
print "\n", e
else:
dork_list.append(args.dork)
# Dork list processing/searching
def search():
driver = webdriver.Firefox()
link_list = []
for int in range(args.pages):
driver.get("http://google.com")
assert "Google" in driver.title
for items in dork_list:
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys(items)
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "r")))
links = driver.find_elements_by_xpath("//h3//a[@href]")
for elem in links:
link_list.append(elem.get_attribute("href"))
#try:
# source = driver.page_source()
# handler = open("page_source.html", "rw") # Needs unique names
# handler.write(source)
# handler.close()
#except IOError as e:
# print "Could not write page source"
# if args.verbose == True:
# print "An IO Error was raised with the following error message: "
# print "\n", e
driver.close()
return link_list
# Link list processing
proc_one = search()
for sorted_url in proc_one:
final = []
if "stackoverflow" or "github" not in sorted_url:
final.append(sorted_url)
print final
A few changes, the biggest being the introduction of a wait. There's non-zero time between simulating pressing enter and results being available on the page, so we need to wait for search results to be available by polling. I changed the xpath to find links to get less garbage on the page that isn't results. Also this:
for elem in links:
link_list = []
Empties link_list on every iteration so I brought it up to the top of search()