johnmahugu

python content bruter (brute force)

Jun 3rd, 2015
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. import urllib2
  2. import urllib
  3. import threading
  4. import Queue
  5.  
  6. threads        = 5
  7. target_url     = "http://testphp.vulnweb.com"
  8. wordlist_file  = "/tmp/all.txt" # from SVNDigger
  9. resume         = None
  10. user_agent     = "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0"
  11.  
  12. def build_wordlist(wordlist_file):
  13.  
  14.     # read in the word list
  15.     fd = open(wordlist_file,"rb")
  16.     raw_words = fd.readlines()
  17.     fd.close()
  18.    
  19.     found_resume = False
  20.     words        = Queue.Queue()
  21.    
  22.     for word in raw_words:
  23.        
  24.         word = word.rstrip()
  25.        
  26.         if resume is not None:
  27.            
  28.             if found_resume:
  29.                 words.put(word)
  30.             else:
  31.                 if word == resume:
  32.                     found_resume = True
  33.                     print "Resuming wordlist from: %s" % resume
  34.                                        
  35.         else:
  36.             words.put(word)
  37.    
  38.     return words
  39.  
  40.  
  41. def dir_bruter(extensions=None):
  42.    
  43.     while not word_queue.empty():
  44.         attempt = word_queue.get()
  45.        
  46.         attempt_list = []
  47.        
  48.         # check if there is a file extension if not
  49.         # it's a directory path we're bruting
  50.         if "." not in attempt:
  51.             attempt_list.append("/%s/" % attempt)
  52.         else:
  53.             attempt_list.append("/%s" % attempt)
  54.    
  55.         # if we want to bruteforce extensions
  56.         if extensions:
  57.             for extension in extensions:
  58.                 attempt_list.append("/%s%s" % (attempt,extension))
  59.                
  60.         # iterate over our list of attempts        
  61.         for brute in attempt_list:
  62.            
  63.             url = "%s%s" % (target_url,urllib.quote(brute))
  64.            
  65.             try:
  66.                 headers = {}
  67.                 headers["User-Agent"] = user_agent
  68.                 r = urllib2.Request(url,headers=headers)
  69.                
  70.                
  71.                 response = urllib2.urlopen(r)
  72.                
  73.                 if len(response.read()):
  74.                     print "[%d] => %s" % (response.code,url)
  75.                    
  76.             except urllib2.HTTPError,e:
  77.  
  78.                 if e.code != 404:
  79.                     print "!!! %d => %s" % (e.code,url)
  80.                
  81.                 pass
  82.  
  83.  
  84. word_queue = build_wordlist(wordlist_file)
  85. extensions = [".php",".bak",".orig",".inc"]
  86.  
  87. for i in range(threads):
  88.             t = threading.Thread(target=dir_bruter,args=(extensions,))
  89.             t.start()
Advertisement
Add Comment
Please, Sign In to add comment