Dimka_lang2

Untitled

Sep 26th, 2021
863
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cloudscraper
  2. import json
  3.  
  4.  
  5. def serializedTransaction(f):
  6.     my_file = open("serializedTransaction.txt", "r")
  7.     d = my_file.readline().replace('[', '').replace(']', '')
  8.     for x in d.split(' '):
  9.         f.append(int(x))
  10.     return f
  11.  
  12.  
  13. def change_file(f, d):
  14.     with open(str(f), 'w') as file:
  15.         json.dump(d, file, indent=4)
  16.         file.close()
  17.  
  18.  
  19. def sessionExecutor():
  20.     data = json.load(open('users.json'))['accounts'][0]
  21.     return {"token_id": data['token_id'],
  22.             "session_token": data['x-access-token']}, [data['username'], data['password']]
  23.  
  24.  
  25. def sessionDump(token, token_id):
  26.     data = json.load(open('users.json'))
  27.     data['accounts'][0].update({"x-access-token": token, "token_id": token_id})
  28.     print(f'New x-access-token: {token}\n'
  29.           f'New token_id: {token_id}')
  30.     change_file('users.json', data)
  31.  
  32.  
  33. def createScrapper():
  34.     scraper = cloudscraper.create_scraper(
  35.         browser={
  36.             'browser': 'firefox',
  37.             'platform': 'windows',
  38.             'mobile': False
  39.         }
  40.     )
  41.     session = sessionExecutor()
  42.     scraper.cookies.update(session[0])
  43.     return waxSessionChecker(scraper, session[1])
  44.  
  45.  
  46. def approvingTrans(scraper):
  47.     data = {
  48.         "serializedTransaction": serializedTransaction([]), "website": "unknown-url.wax.io",
  49.         "description": "jwt is insecure",
  50.         "freeBandwidth": False}
  51.     e = scraper.post('https://public-wax-on.wax.io/wam/sign', json=data,
  52.                      headers={'x-access-token': scraper.cookies._find("session_token")}).json()
  53.     change_file('pyanswer.json', e)
  54.  
  55.  
  56. def wax_mail_confirming(scraper, token):
  57.     while True:
  58.         data = {"code": input('Введите код с почты:  '), "challenge": token}
  59.         r = scraper.post('https://all-access.wax.io/api/session/challenge', data=data).json()
  60.  
  61.         if 'errors' in r:
  62.             print(f'Ошибка при попытке авторизации: {r["errors"][0]["message"]}')
  63.         else:
  64.             scraper.get('https://all-access.wax.io/api/session')
  65.             sessionDump(scraper.cookies._find("session_token"), scraper.cookies._find("token_id"))
  66.             break
  67.  
  68.  
  69. def wax_login(scraper, data):
  70.     data = {"password": data[1], "username": data[0], "redirectTo": ""}
  71.  
  72.     resp = scraper.post('https://all-access.wax.io/api/session', data=data).json()
  73.     if 'challengeToken' in resp:
  74.         wax_mail_confirming(scraper, resp['challengeToken'])
  75.  
  76.  
  77. def waxSessionChecker(scraper, data):
  78.     if 'errors' in scraper.get('https://all-access.wax.io/api/session').json():
  79.         print('Сессия слетела')
  80.         scraper.cookies.clear()
  81.         wax_login(scraper, data)
  82.     else:
  83.         approvingTrans(scraper)
  84.  
  85.  
  86. createScrapper()
RAW Paste Data