Anatomy of a Discord Token Hijack: Why 2FA Isn’t Enough (A Security Post-Mortem)

Engineering · · Updated 2026-10-07

Application SecuritySupply Chain SecurityIncident Response

Article image

It was a regular morning. I had just finished my daily stand-up at work when I noticed a bizarre notification: notification about ignored users.

I hadn’t been active, yet upon checking, I was horrified to see my account blasting scam messages to friends and across multiple servers including my university network and a tech community where I know many people personally. Moments later, my account was locked out entirely. My session token had been hijacked.

The Illusion of Security (and a Slice of Humble Pie)

I had Two-Factor Authentication (2FA) enabled, so I thought my account was an impenetrable fortress. I was wrong. This incident was incredibly humbling.

Just eight months ago, I completed an internship as a Cybersecurity Engineer. You would think I’d be immune to this, but hubris is a developer’s worst enemy. It was a harsh reminder that no matter how secure you think your system is, missing a single due diligence check on a side project can leave a backdoor wide open.

The Root Cause: A Supply Chain Attack

The culprit was a malicious NPM package I had installed for a personal project. I failed to audit the dependencies, and the package executed a malicious postinstall script in the background.

Here is the fundamental architectural flaw: the official Discord .deb installation on Linux stores session data inside ~/.config/discord/Local Storage/leveldb. Crucially, this data—including the active session token—is stored as plain text.

Hackers do not need to bypass your 2FA; they simply use Regular Expressions (Regex) to extract the active token directly from your local machine.

Proof of Concept: How Easy It Is

To demonstrate the vulnerability, I wrote a simple Python script to scan the LevelDB directory. (Note: The actual regex pattern is redacted for obvious security reasons).

Code
import os  
import re  
# Linux: "~/.config/discord/Local Storage/leveldb"  
# Windows: %appdata%/discord/Local Storage/leveldb/  
target_path = "~/.config/discord/Local Storage/leveldb"  
  
def scan_for_tokens(directory):      
    tokens = []  
   
    for file_name in os.listdir(directory):  
        if not file_name.endswith('.log') and not file_name.endswith('.ldb'):  
            continue  
        full_path = os.path.join(directory, file_name)  
        with open(full_path, errors='ignore') as f:  
            for line in (x.strip() for x in f if x.strip()):  
             #regex used  
                for regex in (r"bla bla whatever"):  
                    for token in re.findall(regex, line):  
                        tokens.append(token)  
              
    return tokens  
  
if __name__ == "__main__":  
    path = os.path.expanduser(target_path)  
    if not os.path.exists(path):  
        print(f"Directory not found: {path}")  
    else:  
        found_tokens = scan_for_tokens(path)  
        if found_tokens:  
            print("Token found:")  
            for token in found_tokens:  
                print(token)  
        else:  
            print("No tokens found.")

Even within a web browser, a simple console script can expose the token (only test this on your own account)

Code
(function(){var i = document.createElement('iframe'); document.body.appendChild(i); console.log(i.contentWindow.localStorage.token)})()

The Forensic Investigation

To confirm the attack vector, I audited my terminal history.

Article image

I tracked down the malicious process by scanning my node_modules for hidden post-install scripts:

Code
find node_modules -name "package.json" -exec grep -H '"postinstall"' {} +

I also searched for obfuscated payload executions (a common hallmark of malware) using this command:

Code
`grep -rn 'node_modules' -e "eval(Buffer.from" -e "0x"`

To be honest, the results were alarming. The command outputted a massive amount of strange, obfuscated code deeply buried in the dependencies.

To completely eradicate this threat from my machine and prevent it from infecting future projects, I immediately wiped my package manager’s global cache. Sure enough, after running the cleanup, the obfuscated footprints were completely gone

Mitigation: Securing the Local Environment

This was an expensive lesson in local environment security. Moving forward, I have implemented strict mitigation steps that I highly recommend to all developers:

  1. Disable Auto-Scripts: When installing packages using Bun or NPM, strictly block background scripts from executing automatically. This is your best defense against zero-click local exploits.
Code
bun install --ignore-scripts
  1. Mandatory Audits: Always verify the integrity of your dependency tree before running a project.
Code
bun audit

The “Why”: Social Engineering at Scale

You might wonder, why go through the trouble of a supply chain attack just to steal a Discord token? The answer is social engineering.

Hackers know that developers are part of high-value tech, crypto, and university servers. By hijacking legitimate account, the attackers exploited established trust within those communities to distribute scam links and phishing campaigns, making the scam highly effective.

Stay safe, audit your packages, and remember that 2FA only protects the front door not the windows.

https://checkmarx.com/blog/lofygang-software-supply-chain-attackers-organized-persistent-and-operating-for-over-a-year/

https://nhimg.org/faq/why-do-malicious-packages-that-harvest-discord-tokens-create-such-a-high-impact/