Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import re, time, requests
- from threading import Thread
- import asyncio
- import aiohttp
- class Instagram(object):
- def __init__(self):
- super(Instagram, self).__init__()
- self.session = requests.Session()
- self.logged_in = False
- self.ajax_token = None
- self.csrf_token = None
- self.email = None
- self.username = None
- async def start(self):
- self.proxy = proxies_queue.get() if use_proxy == 'y' else None
- async with aiohttp.ClientSession() as session:
- while CATCH:
- try:
- res = await session.get('https://www.instagram.com/{0}'.format(self.target),
- proxy=self.proxy
- )
- if res.status == 404:
- self.username_available(self, username)
- if res.status == 429:
- if use_proxy == 'y':
- print('task {} is banned. take new proxy'.format(self.number))
- old_proxy = self.proxy
- proxies_queue.put(self.proxy)
- self.proxy = proxies_queue.get()
- print('task {} got new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
- else:
- print('task {} is banned. sleep'.format(self.number))
- await asyncio.sleep(60 * 3)
- print('task {} waked up. try to make requests')
- except Exception as ex:
- print('task {} error {} so change proxy'.format(self.number, ex.__repr__()))
- # print(await session.get('https://www.google.com/'))
- if use_proxy == 'y':
- proxies_queue.put(self.proxy)
- old_proxy = self.proxy
- self.proxy = proxies_queue.get()
- print('task {} new proxy {} old {}'.format(self.number, self.proxy, old_proxy))
- else:
- print('task {} error {}'.format(self.number, ex.__repr__()))
- def prepare_login(self):
- response = self.session.get("https://www.instagram.com/accounts/login/?hl=en", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Cache-Control": "max-age=0"
- })
- if (response.status_code == 200):
- self.ajax_token = re.search("\"rollout_hash\":\"(.*?)\"", response.text).group(1)
- self.csrf_token = re.search("\"csrf_token\":\"(.*?)\"", response.text).group(1)
- return self.ajax_token is not None and self.csrf_token is not None
- def login(self, username, password):
- if (not self.prepare_login()):
- print("[-] Failed to fetch CSRF token")
- return False
- self.logged_in = self.session.post("https://www.instagram.com/accounts/login/ajax/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/accounts/login/?hl=en",
- "X-CSRFToken": self.csrf_token,
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "username": username,
- "password": password
- }).json()["authenticated"]
- return self.logged_in
- def logout(self):
- self.session.post("https://www.instagram.com/accounts/logout/", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/{}/".format(self.username)
- }, data={
- "csrfmiddlewaretoken": self.session.cookies["csrftoken"]
- })
- return "sessionid" not in self.session.cookies
- def consent_required():
- response = self.session.post("https://www.instagram.com/web/consent/update_dob/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/terms/unblock/?next=/",
- "X-CSRFToken": self.session.cookies["csrftoken"],
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "day": "1",
- "month": "1",
- "year": "1998",
- "current_screen_key": "dob"
- })
- if ("\"status\": \"ok\"" in response.text):
- print("[+] Successfully updated consent to GDPR")
- return self.get_email();
- print("[-] Failed to consent to GDPR, use an IP that is not from Europe")
- return False
- def get_email(self):
- response = self.session.get("https://www.instagram.com/accounts/edit/", headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Referer": "https://www.instagram.com/accounts/login/?next=/accounts/edit/",
- "Cache-Control": "max-age=0"
- })
- if ("/terms/unblock/" in response.url):
- return self.consent_required()
- elif ("/accounts/edit/" in response.url and response.status_code == 200):
- self.email = re.search("\"email\":\"(.*?)\"", response.text).group(1)
- self.username = re.search("\"username\":\"(.*?)\"", response.text).group(1)
- return self.email is not None and self.username is not None
- def username_available(self, username):
- return self.session.get("https://www.instagram.com/{}/?__a=1".format(username), headers={
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Cache-Control": "max-age=0"
- }).status_code == 404
- def set_username(self, username):
- return self.session.post("https://www.instagram.com/accounts/edit/", headers={
- "Accept": "*/*",
- "Accept-Language": "en-US,en;q=0.5",
- "Accept-Encoding": "gzip, deflate, br",
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
- "Content-Type": "application/x-www-form-urlencoded",
- "Referer": "https://www.instagram.com/accounts/edit/",
- "X-CSRFToken": self.session.cookies["csrftoken"],
- "X-Instagram-AJAX": self.ajax_token,
- "X-Requested-With": "XMLHttpRequest"
- }, data={
- "email": self.email,
- "username": username,
- "gender": "3"
- }).status_code == 200
- class Turbo(Thread):
- def __init__(self, instagram, target):
- super(Turbo, self).__init__()
- self.is_running = True
- self.instagram = instagram
- self.target = target
- self.attempts = 0
- def run(self):
- while (self.is_running):
- try:
- if (self.instagram.username_available(self.target)):
- if (self.instagram.set_username(self.target)):
- print("\r[+] Claimed username @{} after {:,} attempts\n".format(self.target, self.attempts + 1))
- self.terminate()
- self.attempts += 1
- except:
- continue
- def terminate(self, exit=False):
- self.is_running = False
- if (exit):
- print("\r[-] Turbo stopped, exiting after {:,} attempts...\n".format(self.attempts))
- def main():
- instagram = Instagram()
- username = input("[?] Username: ").strip()
- password = input("[?] Password: ")
- use_proxy = input('Use proxy? (y/n): ')
- threads_count = int(input('Enter threads count: '))
- print("\n[?] Attempting to login")
- if use_proxy != 'n':
- print('collect proxies from file')
- with open('proxies.txt') as f:
- for proxy in f:
- proxies_queue.put(proxy.rstrip())
- print('{} proxies collected'.format(proxies_queue.qsize()))
- if use_proxy == 'y' and threads_count > proxies_queue.qsize():
- exit('You specified more threads than have proxies')
- if (not instagram.login(username, password)):
- print("[-] Failed to login")
- exit(1)
- print("[+] Successfully logged in")
- if (not instagram.get_email()):
- print("[-] Failed to fetch e-mail address")
- exit(1)
- target = input("\n[?] Target: ").strip().lower()
- thread = Turbo(instagram, target)
- thread.setDaemon(True)
- thread.start()
- while (thread.is_running):
- try:
- print("[?] Turboing - {:,} attempts".format(thread.attempts), end="\r", flush=True)
- time.sleep(0.1) # Update attempts every 100ms
- except KeyboardInterrupt:
- thread.terminate(True)
- thread.join()
- if (__name__ == "__main__"):
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement