-
Notifications
You must be signed in to change notification settings - Fork 35
/
claim.py
205 lines (188 loc) · 7.82 KB
/
claim.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
try:
import requests, os, threading, ctypes, time, platform
from colorama import Fore
except ImportError:
input("Error while importing modules. Please install the modules in requirements.txt")
ascii_text = """
_ _
(_) | |
_ _ __ ___| |_ __ _
| | '_ \/ __| __/ _` |
| | | | \__ \ || (_| |
|_|_| |_|___/\__\__,_|"""
if platform.system() == "Windows":
clear = "cls"
else:
clear = "clear"
class Instagram:
def __init__(self):
self.url = "https://instagram.com"
self.session = requests.Session()
self.lock = threading.Lock()
self.claiming = True
self.proxy_errors = 0
self.proxies = []
self.errors = 0
self.attempts = 0
self.retries = 0
self.counter = 0
def change_title(self):
if clear == "cls":
ctypes.windll.kernel32.SetConsoleTitleW(
f"Instagram Auto Claimer | Attempts: {self.attempts} | Retries: {self.retries} | Proxy Errors: {self.proxy_errors} | Errors: {self.errors} | Developed by @useragents on Github"
)
def safe_print(self, arg):
self.lock.acquire()
print(arg)
self.lock.release()
def print_console(self, arg):
self.safe_print(f"\n {Fore.WHITE}[{Fore.LIGHTMAGENTA_EX}Console{Fore.WHITE}] {arg}")
def get_csrf_token(self):
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36",
"Referer": "https://www.instagram.com/"
}
r = self.session.get(
self.url + "/data/shared_data/",
headers = headers
)
return r.json()["config"]["csrf_token"]
def login(self, username: str, password: str):
csrf_token = self.get_csrf_token()
data = {
"enc_password": "#PWD_INSTAGRAM_BROWSER:0:&:" + password,
"username": username,
"queryParams": {},
"optIntoOneTap": False,
"stopDeletionNonce": "",
"trustedDeviceRecords": {}
}
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://www.instagram.com/",
"X-CSRFToken": csrf_token,
}
r = self.session.post(
self.url + "/accounts/login/ajax/",
headers = headers,
data = data
)
if "userId" in r.text:
user_id = r.json()["userId"]
self.print_console(f"Successfully logged into @{username} ({user_id})")
for cookie in r.cookies:
if cookie.name == "csrftoken":
csrf_token = cookie.value
return csrf_token
elif "spam" in r.text:
if r.json()["spam"] == True:
self.print_console(f"Login request considered as spam, try again later")
elif "authenticated" in r.text:
if r.json()["authenticated"] == False:
self.print_console(f"Invalid credentials")
else:
print(r.text)
input()
os._exit(0)
def get_email(self, csrf_token: str):
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36",
"Referer": "https://www.instagram.com/",
"X-CSRFToken": csrf_token,
}
r = self.session.get(
self.url + "/accounts/edit/",
headers = headers
)
try:
email = r.text.split('"email":"')[1].split('"')[0]
name = r.text.split('"first_name":"')[1].split('"')[0]
except IndexError:
print("Error getting email + name on Insta account.\nPlease enter the exact full name (not username) on your insta account and email.")
email = input("\n email address: ")
name = input("\n full name on insta: ")
return email, name
def load_proxies(self):
if not os.path.exists("proxies.txt"):
open('proxies.txt', 'a').close()
self.print_console("No proxies loaded in proxies.txt")
time.sleep(10)
os._exit(0)
with open("proxies.txt", "r", encoding = "UTF-8") as f:
for line in f.readlines():
line = line.replace("\n", "")
self.proxies.append(line)
if not len(self.proxies):
self.print_console("No proxies loaded in proxies.txt")
time.sleep(10)
os._exit(0)
def claim_username(self, target, csrf_token, email_address, name, proxy):
headers = {
"Accept": "*/*",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"X-CSRFToken": csrf_token,
}
data = {
"username": target,
"email": email_address,
"first_name": name,
}
proxies = {"https": "http://{}".format(proxy)}
try:
r = self.session.post(
self.url + "/accounts/edit/",
headers = headers,
data = data,
proxies = proxies
)
except:
self.proxy_errors += 1
self.change_title()
return
if "status" in r.text:
if r.json()["status"] == "fail":
if "This username isn't available" in r.text:
self.attempts += 1
elif "wait a few minutes" in r.text:
self.retries += 1
else:
self.errors += 1
elif r.json()["status"] == "ok":
self.print_console(f"Successfully claimed @{target}")
self.claiming = False
else:
self.errors += 1
else:
self.errors += 1
self.change_title()
def main(self):
os.system(clear)
if clear == "cls":
ctypes.windll.kernel32.SetConsoleTitleW("Instagram Auto Claimer | Developed by @useragents on Github")
print(Fore.LIGHTMAGENTA_EX + ascii_text)
self.load_proxies()
username = str(input(f"\n {Fore.WHITE}[{Fore.LIGHTMAGENTA_EX}Console{Fore.WHITE}] Username: @"))
password = str(input(f" {Fore.WHITE}[{Fore.LIGHTMAGENTA_EX}Console{Fore.WHITE}] Password: "))
target = str(input(f" {Fore.WHITE}[{Fore.LIGHTMAGENTA_EX}Console{Fore.WHITE}] Target: @"))
threads = int(input(f" {Fore.WHITE}[{Fore.LIGHTMAGENTA_EX}Console{Fore.WHITE}] Threads: "))
csrf_token = self.login(username, password)
email_address, name = self.get_email(csrf_token)
def thread_starter():
self.claim_username(target, csrf_token, email_address, name, self.proxies[self.counter])
while self.claiming:
if threading.active_count() <= threads:
try:
threading.Thread(target = thread_starter).start()
self.counter += 1
except:
pass
if len(self.proxies) <= self.counter: #Loop through proxy list
self.counter = 0
obj = Instagram()
obj.main()
input()