Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 126 additions & 126 deletions dorknet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3

import argparse
import sys
Expand All @@ -9,17 +9,19 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

from blessings import Terminal
from blessed import Terminal

t = Terminal()


# Check for args, print logo and usage
if not len(sys.argv[1:]):
print t.cyan("""
print(t.cyan("""
____ _ _____ _
| \ ___ ___| |_| | |___| |_
| \\ ___ ___| |_| | |___| |_
| | | . | _| '_| | | | -_| _|
|____/|___|_| |_,_|_|___|___|_|

Expand All @@ -31,8 +33,8 @@

Example:
DorkNet.py -h
DorkNet.py -d inurl:show.php?id= --verbose\n""")
DorkNet.py -d inurl:show.php?id= --verbose\n"""))

sys.exit(0)


Expand All @@ -51,145 +53,143 @@
#if args.nogui == True:
# options = webdriver.FirefoxOptions()
# options.add_argument("--headless")


# Dork list processing
if args.list:
print "\n[" + t.green("+") + "]Reading in list from: " + args.list + "\n\n"
try:
with open(args.list, "r") as ins:
for line in ins:
dork_list.append(line)
if args.verbose == True:
print "[" + t.magenta("~") + "]" + line
except IOError as e:
print "\n[" + t.red("!") + "]Could not read dork list"
if args.verbose == True:
print "\nAn IO Error was raised with the following error message: "
print "\n %s" % (e)
print("\n[" + t.green("+") + "]Reading in list from: " + args.list + "\n\n")
try:
with open(args.list, "r") as ins:
for line in ins:
dork_list.append(line)

if args.verbose:
print("[" + t.magenta("~") + "]" + line)

except IOError as e:
print("\n[" + t.red("!") + "]Could not read dork list")
if args.verbose:
print("\nAn IO Error was raised with the following error message: ")
print("\n %s" % (e))

else:
dork_list.append(args.dork)



print "\n[" + t.green("+") + "]Would you like DorkNet to proxy it's connection to the search engine?"
query = raw_input("[Y]es/[N]o: ").lower()
print("\n[" + t.green("+") + "]Would you like DorkNet to proxy it's connection to the search engine?")
query = input("[Y]es/[N]o: ").lower()

if query == 'y':
IP = raw_input("\n[" + t.green("+") + "]Please enter the proxy host IP: ")
PORT = raw_input("\n[" + t.green("+") + "]Please enter the proxy port: ")
set_proxy = True
IP = input("\n[" + t.green("+") + "]Please enter the proxy host IP: ")
PORT = input("\n[" + t.green("+") + "]Please enter the proxy port: ")
set_proxy = True
elif query == 'n':
print "\n[" + t.green("+") + "]Establishing unproxied connection...\n"
set_proxy = False
print("\n[" + t.green("+") + "]Establishing unproxied connection...\n")
set_proxy = False
else:
print "\n[" + t.red("!") + "]Unhandled option, defaulting to unproxied connection..."
set_proxy = False
print("\n[" + t.red("!") + "]Unhandled option, defaulting to unproxied connection...")
set_proxy = False


# Web Driver Proxy
def proxy(PROXY_HOST,PROXY_PORT):
fp = webdriver.FirefoxProfile()
print "[" + t.green("+") + "]Proxy host set to: " + PROXY_HOST
print "[" + t.green("+") + "]Proxy port set to: " + PROXY_PORT
print "\n[" + t.green("+") + "]Establishing connection..."
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http",PROXY_HOST)
fp.set_preference("network.proxy.http_port",int(PROXY_PORT))
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'")
fp.update_preferences()
return webdriver.Firefox(firefox_profile=fp)
def proxy(PROXY_HOST, PROXY_PORT):
fp = FirefoxProfile()
print("[" + t.green("+") + "]Proxy host set to: " + PROXY_HOST)
print("[" + t.green("+") + "]Proxy port set to: " + PROXY_PORT)
print("\n[" + t.green("+") + "]Establishing connection...")
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", int(PROXY_PORT))
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"
)

options = Options()
options.profile = fp
return webdriver.Firefox(options=options)


# Function to generate and process results based on input
def search():
link_list = []

if set_proxy == True:
# the --nogui option doesn't seem to want to play nice with
# The way in which i configure the proxy, if the user chose
# to employ one
driver = proxy(IP, PORT)
#elif args.nogui == True:
# driver = webdriver.Firefox(firefox_options=options)
else:
driver = webdriver.Firefox()

for int in range(1):
try:
driver.get("http://google.com")
except Exception as e:
print "\n[" + t.red("!") + "]A connection could not be established"
if args.verbose == True:
print "An error was raised with the following error message: "
print "\n %s" % (e)
break
driver.quit()
sys.exit(0)

#if args.nogui == True:
# for items in dork_list:
# elem = driver.find_element_by_name("q")
# elem.clear()
# elem.send_keys(items)
# elem.send_keys(Keys.RETURN)
# time.sleep(2.2)
#
#else:
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)
time.sleep(2.2)
try:
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "r"))) #r
except Exception as e:
driver.quit()
print "\n[" + t.red("!") + "]Detecting page source elements failed/timed out.\n"

if args.verbose == True:
print "An error was raised with the following error message: "
print "\n %s" % (e)

time.sleep(1)
continue


assert "No results found" not in driver.page_source
if "No results found" in driver.page_source:
continue

links = driver.find_elements_by_xpath("//div[@data-hveid]/div/div/a[@onmousedown]") # //h3//a[@href]

for elem in links:
link_list.append(elem.get_attribute("href")) # href elem.get_attribute("href")



driver.quit()
for url in link_list:
if url.endswith("search"):
link_list.remove(url)
return link_list
link_list = []

if set_proxy:
# the --nogui option doesn't seem to want to play nice with
# The way in which i configure the proxy, if the user chose
# to employ one
driver = proxy(IP, PORT)
#elif args.nogui == True:
# driver = webdriver.Firefox(firefox_options=options)
else:
driver = webdriver.Firefox()

for _ in range(1):
try:
driver.get("http://google.com")
except Exception as e:
print("\n[" + t.red("!") + "]A connection could not be established")
if args.verbose:
print("An error was raised with the following error message: ")
print("\n %s" % (e))
break
driver.quit()
sys.exit(0)

#if args.nogui == True:
# for items in dork_list:
# elem = driver.find_element_by_name("q")
# elem.clear()
# elem.send_keys(items)
# elem.send_keys(Keys.RETURN)
# time.sleep(2.2)
#
#else:
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)
time.sleep(2.2)
try:
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "r"))) # r
except Exception as e:
driver.quit()
print("\n[" + t.red("!") + "]Detecting page source elements failed/timed out.\n")

if args.verbose:
print("An error was raised with the following error message: ")
print("\n %s" % (e))

time.sleep(1)
continue

assert "No results found" not in driver.page_source
if "No results found" in driver.page_source:
continue

links = driver.find_elements(By.XPATH, "//div[@data-hveid]/div/div/a[@onmousedown]") # //h3//a[@href]

for elem in links:
link_list.append(elem.get_attribute("href"))

driver.quit()
for url in link_list[:]:
if url.endswith("search"):
link_list.remove(url)
return link_list


proc_one = search()

with open("results.log", "ab") as outfile:
for item in proc_one:
outfile.write("\n" + item)

outfile.close()

if args.verbose == True:
with open("results.log", "r") as infile:
for line in infile:
print "[" + t.magenta("~") + "]" + line

outfile.close()

print "\n\n[" + t.green("+") + "]Done. Results have been saved to a textfile, in the current directory as %s for further processing.\n" % outfile
for item in proc_one:
outfile.write(("\n" + item).encode())

if args.verbose:
with open("results.log", "r") as infile:
for line in infile:
print("[" + t.magenta("~") + "]" + line)

print("\n\n[" + t.green("+") + "]Done. Results have been saved to a textfile, in the current directory as results.log for further processing.\n")