Skip to content

Commit

Permalink
"small changes" lol
Browse files Browse the repository at this point in the history
  • Loading branch information
itschasa committed Jun 6, 2023
1 parent 4b107aa commit 0ae9e65
Show file tree
Hide file tree
Showing 10 changed files with 578 additions and 548 deletions.
212 changes: 85 additions & 127 deletions backup.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cfgload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Config():
"Ex: `config.threads`"
def __init__(self) -> None:
args = yaml.safe_load(open("config.yml"))
data = yaml.safe_load(open("config.yml"))

for arg, val in args.items():
exec(f"self.{arg} = val")
self.colour = data['colour']
self.group_chat_msg = data['group_chat_msg']
110 changes: 110 additions & 0 deletions client_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2021 github.com/ItsChasa
#
# This source code has been released under the GNU Affero General Public
# License v3.0. A copy of this license is available at
# https://www.gnu.org/licenses/agpl-3.0.en.html

import base64
import re
import json

# browser data
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
sec_ch_ua = '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"'
browser_version = "113.0.0.0"
request_client_identifier = "chrome_113" # tls_client uses this to determine what "Client Hello" to use

# discord data
from main import request_client

def get_client_build_number():
client_request = request_client.get(f'https://discord.com/app', headers={'User-Agent': 'Mozilla/5.0'}).text
jsFileRegex = re.compile(r'([a-zA-z0-9]+)\.js', re.I)
for asset in jsFileRegex.findall(client_request)[::-1]:
if asset != "invisible":
break

assetFileRequest = request_client.get(f'https://discord.com/assets/{asset}.js', headers={'User-Agent': 'Mozilla/5.0'}).text
try:
build_info_regex = re.compile(r'Build Number: "\)\.concat\("([0-9]{4,8})"')
build_info_strings = build_info_regex.findall(assetFileRequest)
build_num = build_info_strings[0]
except (RuntimeError, TypeError, NameError):
raise Exception(f"couldn't fetch discord build num from {asset}.js")

return int(build_num)

discord_build = get_client_build_number()
super_properties = {
"os": "Windows",
"browser": "Chrome",
"device": "",
"system_locale": "en-US",
"browser_user_agent": user_agent,
"browser_version": browser_version,
"os_version": "10",
"referrer": "",
"referring_domain": "",
"referrer_current": "",
"referring_domain_current": "",
"release_channel": "stable",
"client_build_number": discord_build,
"client_event_source": None
}
b64_super_properties = base64.b64encode(json.dumps(super_properties, separators=(',', ':')).encode()).decode()


def build_headers(
method,
superprop=False,
debugoptions=False,
discordlocale=False,
authorization=False,
origin=False,
referer="https://discord.com/channels/@me",
context=False,
timezone=False
):
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Cookie": "locale=en-GB",
"Referer": referer,
"Sec-Ch-Ua": sec_ch_ua,
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": '"Windows"',
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": user_agent
}

if referer is False:
del headers["Referer"]

if method != "get":
headers["Content-Type"] = "application/json"
if origin is not False:
headers["Origin"] = origin

if authorization is not False:
headers["Authorization"] = authorization
if debugoptions is True:
headers["X-Debug-Options"] = "bugReporterEnabled"
if discordlocale is True:
headers["X-Discord-Locale"] = "en-US"
if superprop is True:
headers["X-Super-Properties"] = b64_super_properties
if context is True:
headers["X-Context-Properties"] = context
if timezone is True:
headers["X-Discord-Timezone"] = "Europe/London"

keyssorted = sorted(headers.keys(), key=lambda x:x.lower())
newheaders={}
for key in keyssorted:
newheaders[key] = headers[key]

return headers
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ colour: purple


# group chat backup:
# if last message is older than _ seconds, dont create invite:
# if last message is older than _ seconds, dont create invite
# format: seconds
# set to 0 to disable it
# default: 1209600 (2 weeks)
Expand Down
16 changes: 8 additions & 8 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
# License v3.0. A copy of this license is available at
# https://www.gnu.org/licenses/agpl-3.0.en.html

import startup
from main import colours

class prnt():
def __init__(self, clnt : startup.Setup) -> None:
self.clnt = clnt
def __init__(self) -> None:
pass

def success(self, content, end="\n", indent=0):
ind = ""
for _ in range(indent): ind += " "
print(f"{ind}{self.clnt.green}>{self.clnt.white} {content}", end=end)
print(f"{ind}{colours['green']}>{colours['white']} {content}", end=end)

def info(self, content, end="\n", indent=0):
ind = ""
for _ in range(indent): ind += " "
print(f"{ind}{self.clnt.white}> {content}", end=end)
print(f"{ind}{colours['white']}> {content}", end=end)

def fail(self, content, end="\n", indent=0):
ind = ""
for _ in range(indent): ind += " "
print(f"{ind}{self.clnt.red}>{self.clnt.white} {content}", end=end)
print(f"{ind}{colours['light_red']}>{colours['white']} {content}", end=end)

def inp(self, content, end="\n", indent=0):
ind = ""
for _ in range(indent): ind += " "
print(f"{ind}{self.clnt.blue}>{self.clnt.white} {content}", end=end)
print(f"{ind}{colours['light_blue']}>{colours['white']} {content}", end=end)

def warn(self, content, end="\n", indent=0):
ind = ""
for _ in range(indent): ind += " "
print(f"{ind}{self.clnt.yellow}>{self.clnt.white} {content}", end=end)
print(f"{ind}{colours['yellow']}>{colours['white']} {content}", end=end)
32 changes: 9 additions & 23 deletions fetch_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
# License v3.0. A copy of this license is available at
# https://www.gnu.org/licenses/agpl-3.0.en.html

import os, re, requests, base64, json, brotli
import os
import re
import base64
import json
import brotli
from Crypto.Cipher import AES
from win32crypt import CryptUnprotectData

from client_info import build_headers
from main import request_client

def fetch():
"""[[token, user#tag], ...] """

Expand Down Expand Up @@ -37,33 +44,12 @@ def get_decryption_key(path) -> str:

return decryption_key

def getheaders(token):
headers = {
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"authorization": token,
"cookie": "locale=en-GB",
"referer": "https://discord.com/channels/@me",
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"x-debug-options": "bugReporterEnabled",
"x-discord-locale": "en-GB",
"x-super-properties": "eyJvcyI6IldpbmRvd3MiLCJicm93c2VyIjoiQ2hyb21lIiwiZGV2aWNlIjoiIiwic3lzdGVtX2xvY2FsZSI6ImVuLVVTIiwiYnJvd3Nlcl91c2VyX2FnZW50IjoiTW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEwMC4wLjQ4OTYuMTI3IFNhZmFyaS81MzcuMzYiLCJicm93c2VyX3ZlcnNpb24iOiIxMDAuMC40ODk2LjEyNyIsIm9zX3ZlcnNpb24iOiIxMCIsInJlZmVycmVyIjoiIiwicmVmZXJyaW5nX2RvbWFpbiI6IiIsInJlZmVycmVyX2N1cnJlbnQiOiIiLCJyZWZlcnJpbmdfZG9tYWluX2N1cnJlbnQiOiIiLCJyZWxlYXNlX2NoYW5uZWwiOiJzdGFibGUiLCJjbGllbnRfYnVpbGRfbnVtYmVyIjoxMjY0NjIsImNsaWVudF9ldmVudF9zb3VyY2UiOm51bGx9"
}
return headers

def reqJSON(req) -> dict:
try: return req.json()
except: return json.loads(brotli.decompress(req.content).decode("utf-8"))

def check_token(tkn, name, ids:list, to_return_tokens:list):
r = requests.get("https://discord.com/api/v9/users/@me", headers=getheaders(tkn))
r = request_client.get("https://discord.com/api/v9/users/@me", headers=build_headers("get", superprop=True, debugoptions=True, discordlocale=True, authorization=tkn, timezone=True))
if r.status_code == 200:
tknid = base64.b64decode((tkn.split('.')[0] + '===').encode('ascii')).decode('ascii')
if (tknid+name) not in ids:
Expand Down
Loading

0 comments on commit 0ae9e65

Please sign in to comment.