๐Discord Tokens
Last updated
Last updated
I'm trying to make some cybersecurity research on Discord. The main target for hackers are tokens. Thanks to tokens, you don't need credentials to login to an account. You can just login through Discord thanks to the strings bellow.
To use a token for login to an account, you can use the script bellow on the website's console.
Is there a way to recover a token without token grabber? That's the question i will try to find an anser. But firstly, how a token is generate?
To encode and decode things, you can use CyberChef. It's my favorite app to encrypt/decrypt strings.
A token is made in three part, the first part is just the user id
encoded in base64
.
We can easely get the first part of a token by encoding the user id
in base64
.
Find the full python script here.
In this chapter, we will explore a Python script that helps find Discord tokens stored on a computer. Discord tokens are sensitive information that should not be shared or exposed, as they can be used to gain unauthorized access to Discord accounts. It's important to use this script responsibly and only on systems you have permission to access.
Understand how to locate Discord tokens on a computer.
Explore the use of platform-specific paths for different operating systems.
Learn about sending data to a Discord server through a webhook.
Before diving into this chapter, you should have a basic understanding of Python programming and how to execute Python scripts on your system. Additionally, you need to have the required permissions to access and run this script on the target system.
The Python script provided in this chapter is designed to find Discord tokens on a computer. It works on Windows, macOS, and Linux systems. The script performs the following tasks:
Detect the operating system the script is running on.
Identify and extract tokens from the local storage of various applications.
Optionally, send the found tokens to a Discord server through a webhook.
Let's break down the script step by step.
The script starts by importing the required modules, including os
for file system operations, re
for regular expressions, json
for JSON data handling, and platform
for detecting the operating system.
These constants allow you to enable or disable the sending of tokens to a Discord server through a webhook. If WEBHOOK_ENABLE
is set to True
, the script will attempt to send the tokens to the specified WEBHOOK_URL
.
The find_tokens
function takes a path as input and looks for Discord tokens in specific files within that path. It uses regular expressions to find tokens in the files. The found tokens are returned as a list.
In the provided script, regular expressions (regex) are used to search for Discord tokens within text data. Discord tokens consist of three parts: a 24-character string, followed by a 6-character string, and then a 27-character string. Let's break down how this is implemented in the script.
The regular expression pattern used to match Discord tokens is defined as follows:
Let's break down this pattern:
[\w-]
: This part of the pattern matches any alphanumeric character (letter or digit) and the hyphen character (-
).
{24}
: This quantifier specifies that the preceding pattern, [\w-]
, should be matched exactly 24 times. This ensures that the first part of the token consists of 24 characters.
\.
: This matches a literal period (dot) character, which is used to separate the three parts of the token.
{6}
: Similar to the first part, this quantifier specifies that the middle part of the token, also consisting of alphanumeric characters and hyphens, should be exactly 6 characters long.
\.
: Another period to separate the second and third parts of the token.
{27}
: This quantifier specifies that the final part of the token should consist of exactly 27 characters.
The script uses this regex pattern in a for
loop to search for token matches within lines of text. Here's how it works:
for line in [...]
: The script reads lines of text from a file and iterates through them.
for regex in (r'[\w-]{24}\.[\w-]{6}\.[\w-]{27}', r'mfa\.[\w-]{84}')
: There are two regex patterns in this loop. The first pattern, which we discussed earlier, matches Discord tokens. The second pattern (r'mfa\.[\w-]{84}'
) is used to match another type of Discord token.
for token in re.findall(regex, line)
: For each line of text, the re.findall
function is used to find all matches of the current regex pattern within that line.
tokens.append(token)
: When a token match is found, it is added to the tokens
list.
In summary, the script uses regular expressions to identify and extract Discord tokens based on their specific pattern, which includes a 24-character part, a 6-character part, and a 27-character part, separated by periods. These tokens are then collected for further processing.
The main
function is the entry point of the script. It detects the operating system, sets paths for various applications, and searches for tokens in each application's local storage. The results are stored in the message
variable, which will be printed to the console or sent to a Discord server if WEBHOOK_ENABLE
is True
.
The script configures different paths based on the operating system:
For Linux
For macOS (Darwin)
For Windows
These paths point to the local storage of Discord and other applications where tokens might be stored.
The script then calls the find_tokens
function for each application's path and appends the results to the message
variable. Tokens, if found, are highlighted with colored output.
If WEBHOOK_ENABLE
is set to True
, the script prepares the results as a JSON payload and sends them to the specified Discord webhook URL using the urllib
module. This step is optional and can be skipped if you only want to print the results to the console.
The script's execution starts from here. The main
function is called when the script is run, and it performs the token search and optionally sends the results to the Discord server.
In this chapter, you learned about a Python script that can be used to find Discord tokens on a computer. It's important to use this script responsibly and within the bounds of the law and ethical guidelines. In the next chapter, we will explore additional Python programming concepts and techniques.