A malicious package named “pycord-self” was discovered on the Python Package Index (PyPI), designed to target Discord developers by stealing authentication tokens and setting up a backdoor for remote system access. The package, which closely mimics the legitimate “discord.py-self” library, has been downloaded 885 times since its upload in June of last year. The official “discord.py-self” library is widely used by developers to automate interactions with Discord, including messaging, bot creation, and data retrieval. By impersonating this popular tool, the malicious package was able to trick developers into installing it, despite its malicious functionality.
The pycord-self package contains two key malicious features:
First, it steals Discord authentication tokens from the victim’s system and sends them to an external server. These tokens allow attackers to hijack the victim’s Discord account without needing login credentials, even if two-factor authentication is enabled. The second feature of the package is a backdoor mechanism that establishes a persistent connection to a remote server through port 6969. This backdoor enables the attacker to access the system continuously, with the malicious code launching a shell (“bash” on Linux or “cmd” on Windows) to grant remote control over the victim’s device.
Once the backdoor is set up, the attacker can maintain stealthy access to the compromised machine. The backdoor runs in a separate thread, making it difficult to detect, while the pycord-self package continues to function as expected, allowing attackers to avoid suspicion. This technique allows the attacker to have continuous control over the victim’s system, enabling further exploitation. The use of such tactics poses significant risks to developers who may unknowingly install the package, leaving their systems vulnerable to ongoing attacks.
To protect against similar threats, developers are advised to take extra precautions when installing third-party packages. It is important to ensure that the package comes from an official or trusted source and to verify the package name to avoid falling victim to typosquatting. Reviewing the package’s code for any obfuscated or suspicious functions can also help in identifying malicious behavior. Additionally, scanning tools can aid in detecting and blocking harmful packages, reducing the likelihood of a successful attack on a developer’s system.