Advertisement
Guest User

mangochillin123

a guest
May 22nd, 2019
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import re, time, requests
  5. from threading import Thread
  6. import asyncio
  7. import aiohttp
  8.  
  9. class Instagram(object):
  10. def __init__(self):
  11. super(Instagram, self).__init__()
  12. self.session = requests.Session()
  13. self.logged_in = False
  14.  
  15. self.ajax_token = None
  16. self.csrf_token = None
  17.  
  18. self.email = None
  19. self.username = None
  20.  
  21.  
  22.  
  23. async def start(self):
  24. self.proxy = proxies_queue.get() if use_proxy == 'y' else None
  25.  
  26. async with aiohttp.ClientSession() as session:
  27. while CATCH:
  28. try:
  29. res = await session.get('https://www.instagram.com/{0}'.format(self.target),
  30. proxy=self.proxy
  31. )
  32.  
  33.  
  34. if res.status == 404:
  35. self.username_available(self, username)
  36.  
  37. if res.status == 429:
  38. if use_proxy == 'y':
  39. print('task {} is banned. take new proxy'.format(self.number))
  40. old_proxy = self.proxy
  41. proxies_queue.put(self.proxy)
  42. self.proxy = proxies_queue.get()
  43. print('task {} got new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
  44. else:
  45. print('task {} is banned. sleep'.format(self.number))
  46. await asyncio.sleep(60 * 3)
  47. print('task {} waked up. try to make requests')
  48. except Exception as ex:
  49. print('task {} error {} so change proxy'.format(self.number, ex.__repr__()))
  50. # print(await session.get('https://www.google.com/'))
  51. if use_proxy == 'y':
  52. proxies_queue.put(self.proxy)
  53. old_proxy = self.proxy
  54. self.proxy = proxies_queue.get()
  55. print('task {} new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
  56. else:
  57. print('task {} error {}'.format(self.number, ex.__repr__()))
  58.  
  59. def prepare_login(self):
  60. response = self.session.get("https://www.instagram.com/accounts/login/?hl=en", headers={
  61. "Accept-Language": "en-US,en;q=0.5",
  62. "Accept-Encoding": "gzip, deflate, br",
  63. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  64. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  65. "Cache-Control": "max-age=0"
  66. })
  67.  
  68. if (response.status_code == 200):
  69. self.ajax_token = re.search("\"rollout_hash\":\"(.*?)\"", response.text).group(1)
  70. self.csrf_token = re.search("\"csrf_token\":\"(.*?)\"", response.text).group(1)
  71.  
  72. return self.ajax_token is not None and self.csrf_token is not None
  73.  
  74. def login(self, username, password):
  75. if (not self.prepare_login()):
  76. print("[-] Failed to fetch CSRF token")
  77. return False
  78.  
  79. self.logged_in = self.session.post("https://www.instagram.com/accounts/login/ajax/", headers={
  80. "Accept": "*/*",
  81. "Accept-Language": "en-US,en;q=0.5",
  82. "Accept-Encoding": "gzip, deflate, br",
  83. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  84. "Content-Type": "application/x-www-form-urlencoded",
  85. "Referer": "https://www.instagram.com/accounts/login/?hl=en",
  86. "X-CSRFToken": self.csrf_token,
  87. "X-Instagram-AJAX": self.ajax_token,
  88. "X-Requested-With": "XMLHttpRequest"
  89. }, data={
  90. "username": username,
  91. "password": password
  92. }).json()["authenticated"]
  93.  
  94. return self.logged_in
  95.  
  96. def logout(self):
  97. self.session.post("https://www.instagram.com/accounts/logout/", headers={
  98. "Accept-Language": "en-US,en;q=0.5",
  99. "Accept-Encoding": "gzip, deflate, br",
  100. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  101. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  102. "Content-Type": "application/x-www-form-urlencoded",
  103. "Referer": "https://www.instagram.com/{}/".format(self.username)
  104. }, data={
  105. "csrfmiddlewaretoken": self.session.cookies["csrftoken"]
  106. })
  107.  
  108. return "sessionid" not in self.session.cookies
  109.  
  110. def consent_required():
  111. response = self.session.post("https://www.instagram.com/web/consent/update_dob/", headers={
  112. "Accept": "*/*",
  113. "Accept-Language": "en-US,en;q=0.5",
  114. "Accept-Encoding": "gzip, deflate, br",
  115. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  116. "Content-Type": "application/x-www-form-urlencoded",
  117. "Referer": "https://www.instagram.com/terms/unblock/?next=/",
  118. "X-CSRFToken": self.session.cookies["csrftoken"],
  119. "X-Instagram-AJAX": self.ajax_token,
  120. "X-Requested-With": "XMLHttpRequest"
  121. }, data={
  122. "day": "1",
  123. "month": "1",
  124. "year": "1998",
  125. "current_screen_key": "dob"
  126. })
  127.  
  128. if ("\"status\": \"ok\"" in response.text):
  129. print("[+] Successfully updated consent to GDPR")
  130. return self.get_email();
  131.  
  132. print("[-] Failed to consent to GDPR, use an IP that is not from Europe")
  133. return False
  134.  
  135. def get_email(self):
  136. response = self.session.get("https://www.instagram.com/accounts/edit/", headers={
  137. "Accept-Language": "en-US,en;q=0.5",
  138. "Accept-Encoding": "gzip, deflate, br",
  139. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  140. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  141. "Referer": "https://www.instagram.com/accounts/login/?next=/accounts/edit/",
  142. "Cache-Control": "max-age=0"
  143. })
  144.  
  145. if ("/terms/unblock/" in response.url):
  146. return self.consent_required()
  147. elif ("/accounts/edit/" in response.url and response.status_code == 200):
  148. self.email = re.search("\"email\":\"(.*?)\"", response.text).group(1)
  149. self.username = re.search("\"username\":\"(.*?)\"", response.text).group(1)
  150.  
  151. return self.email is not None and self.username is not None
  152.  
  153. def username_available(self, username):
  154. return self.session.get("https://www.instagram.com/{}/?__a=1".format(username), headers={
  155. "Accept-Language": "en-US,en;q=0.5",
  156. "Accept-Encoding": "gzip, deflate, br",
  157. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  158. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  159. "Cache-Control": "max-age=0"
  160. }).status_code == 404
  161.  
  162. def set_username(self, username):
  163. return self.session.post("https://www.instagram.com/accounts/edit/", headers={
  164. "Accept": "*/*",
  165. "Accept-Language": "en-US,en;q=0.5",
  166. "Accept-Encoding": "gzip, deflate, br",
  167. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
  168. "Content-Type": "application/x-www-form-urlencoded",
  169. "Referer": "https://www.instagram.com/accounts/edit/",
  170. "X-CSRFToken": self.session.cookies["csrftoken"],
  171. "X-Instagram-AJAX": self.ajax_token,
  172. "X-Requested-With": "XMLHttpRequest"
  173. }, data={
  174. "email": self.email,
  175. "username": username,
  176. "gender": "3"
  177. }).status_code == 200
  178.  
  179. class Turbo(Thread):
  180. def __init__(self, instagram, target):
  181. super(Turbo, self).__init__()
  182. self.is_running = True
  183. self.instagram = instagram
  184. self.target = target
  185. self.attempts = 0
  186.  
  187. def run(self):
  188. while (self.is_running):
  189. try:
  190. if (self.instagram.username_available(self.target)):
  191. if (self.instagram.set_username(self.target)):
  192. print("\r[+] Claimed username @{} after {:,} attempts\n".format(self.target, self.attempts + 1))
  193. self.terminate()
  194.  
  195. self.attempts += 1
  196. except:
  197. continue
  198.  
  199. def terminate(self, exit=False):
  200. self.is_running = False
  201.  
  202. if (exit):
  203. print("\r[-] Turbo stopped, exiting after {:,} attempts...\n".format(self.attempts))
  204.  
  205. def main():
  206. instagram = Instagram()
  207. username = input("[?] Username: ").strip()
  208. password = input("[?] Password: ")
  209. use_proxy = input('Use proxy? (y/n): ')
  210. threads_count = int(input('Enter threads count: '))
  211. print("\n[?] Attempting to login")
  212.  
  213. if use_proxy != 'n':
  214. print('collect proxies from file')
  215.  
  216. with open('proxies.txt') as f:
  217. for proxy in f:
  218. proxies_queue.put(proxy.rstrip())
  219.  
  220. print('{} proxies collected'.format(proxies_queue.qsize()))
  221.  
  222.  
  223. if use_proxy == 'y' and threads_count > proxies_queue.qsize():
  224. exit('You specified more threads than have proxies')
  225.  
  226. if (not instagram.login(username, password)):
  227. print("[-] Failed to login")
  228. exit(1)
  229.  
  230. print("[+] Successfully logged in")
  231.  
  232. if (not instagram.get_email()):
  233. print("[-] Failed to fetch e-mail address")
  234. exit(1)
  235.  
  236. target = input("\n[?] Target: ").strip().lower()
  237.  
  238. thread = Turbo(instagram, target)
  239. thread.setDaemon(True)
  240. thread.start()
  241.  
  242. while (thread.is_running):
  243. try:
  244. print("[?] Turboing - {:,} attempts".format(thread.attempts), end="\r", flush=True)
  245. time.sleep(0.1) # Update attempts every 100ms
  246. except KeyboardInterrupt:
  247. thread.terminate(True)
  248. thread.join()
  249.  
  250. if (__name__ == "__main__"):
  251. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement