Man-in-the-Malware: Intercepting Adversarial Comms
This talk demonstrates how to intercept and hijack command-and-control (C2) communications by exploiting operational security (OPSEC) failures in malware that uses the Telegram Bot API. By performing source code analysis on captured infostealer samples, the speaker recovers hardcoded bot tokens and chat IDs to gain unauthorized access to the attacker's C2 infrastructure. The presentation highlights how these OPSEC mistakes, such as storing credentials in plain text or reusing infrastructure, allow defenders to gain significant intelligence on cybercrime operations. The speaker provides practical examples of using Telegram API methods to monitor and exfiltrate data from active threat actor campaigns.
Hijacking C2 Infrastructure: Exploiting Telegram Bot API Misconfigurations
TLDR: Threat actors are increasingly using the Telegram Bot API as a free, encrypted, and highly available command-and-control (C2) channel for their malware. By performing static analysis on captured infostealer samples, researchers can extract hardcoded bot tokens and chat IDs to hijack these C2 channels. This allows for the direct monitoring of attacker operations, credential exfiltration, and the identification of additional malicious infrastructure.
Security researchers often focus on the complexity of custom-built C2 frameworks, but the most dangerous threats are frequently the ones that rely on the simplest, most accessible infrastructure. The shift toward "Living off the Land" (LotL) C2, where attackers abuse legitimate platforms like Telegram, Discord, or Slack, has fundamentally changed the threat landscape. These platforms provide built-in encryption, high availability, and a degree of anonymity that traditional VPS-based C2 setups lack. When an attacker makes a mistake in their operational security (OPSEC) while using these platforms, the results are often catastrophic for their campaign.
The Mechanics of Telegram-Based C2
The core of this technique relies on the Telegram Bot API. An attacker creates a bot via BotFather, which generates a unique API token. This token acts as the authentication credential for the bot. When a victim machine executes an infostealer, the malware uses this token to send stolen data—such as browser cookies, saved passwords, and screenshots—to a specific Telegram chat or group.
The vulnerability arises because many malware developers hardcode these tokens directly into the binary. Whether they are using obfuscation or simple base64 encoding, the token remains retrievable through static analysis. Once a researcher or a security tool like dnSpy extracts the token, they possess the keys to the kingdom.
Using the Telegram API, an attacker can send commands to the bot or receive data from it. A researcher can use the same methods to intercept this traffic. The getUpdates method is particularly useful for enumerating the chat IDs associated with the bot. Once the chat ID is known, the forwardMessage method allows a researcher to silently copy the entire stream of stolen data from the attacker’s channel to their own, effectively performing a man-in-the-middle attack on the malware’s exfiltration path.
From One Sample to a Global Campaign
During a recent analysis of an infostealer sample, I observed the malware using a multi-stage execution chain. The initial vector was a phishing email containing a JavaScript file. When executed, this script downloaded a secondary PowerShell payload, which in turn dropped a .NET-based executable. This executable, identified as a variant of the Snake Keylogger, performed process injection into a legitimate Windows binary, RegAsm.exe, to evade detection.
By de-compiling the .NET binary, I recovered the hardcoded Telegram bot token and the associated chat ID. Using these credentials, I was able to access the attacker’s Telegram channel. The volume of data was staggering. I found hundreds of screenshots and keylog files being exfiltrated in real-time.
The real intelligence win, however, came from pivoting on the infrastructure identified within the stolen data. The attacker had left their FastPanel and Namecheap credentials in plain text files on their own machine. By accessing these management consoles, I mapped out their entire network of phishing domains, SMTP servers, and VPS instances. This is the power of exploiting OPSEC failures: one mistake in the malware’s configuration leads to the total compromise of the attacker’s production environment.
Pentesting and Defensive Implications
For penetration testers, this research highlights the importance of analyzing the C2 communication patterns during an engagement. If you encounter malware that communicates with api.telegram.org, do not just block the traffic. Investigate the payload. If you can extract the bot token, you can potentially gain visibility into the attacker’s exfiltration methods and identify the scope of their campaign.
From a defensive perspective, the reliance on LotL C2 makes traditional network-based detection more difficult, as the traffic blends in with legitimate API calls. However, organizations can implement YARA rules to scan for known infostealer signatures that contain hardcoded Telegram tokens. Furthermore, monitoring for unusual outbound traffic to the Telegram API from non-administrative endpoints can serve as a high-fidelity indicator of compromise.
The most effective defense against this class of threat is a combination of robust endpoint detection and response (EDR) and proactive threat hunting. If you are a defender, look for the artifacts of these campaigns—the phishing emails, the malicious attachments, and the C2 traffic. If you are a researcher, keep looking for these OPSEC failures. Attackers are human, and humans make mistakes. When they do, the data they leave behind is often more valuable than the malware itself.
The next time you find a sample communicating with a public API, take the time to decompile it. You might just find the entire infrastructure of a cybercrime operation waiting for you to take control.
Vulnerability Classes
Attack Techniques
OWASP Categories
All Tags
Up Next From This Conference

DisguiseDelimit: Exploiting Synology NAS with Delimiters and Novel Tricks

Browser Extension Clickjacking: One Click and Your Credit Card Is Stolen

Can't Stop the ROP: Automating Universal ASLR Bypasses for Windows
Similar Talks

Inside the FBI's Secret Encrypted Phone Company 'Anom'

Kill List: Hacking an Assassination Site on the Dark Web

