Leveraging Telegram as a command & control platform

Leveraging Telegram As A Command

SHARE

Share on facebook
Share on twitter
Share on linkedin

Introduction

At Blaze, we are always looking for new ways to further improve our engagements. As every penetration tester knows, post-exploitation is a crucial step for successful compromise and further penetration deep inside the network. Maintaining a strong foothold within the target organization is key.

Hence, we have created Blaze Telegram Backdoor Tool (bt2), a proof of concept post-exploitation tool in form of a Telegram bot that serves as a backdoor.

Command and control (hereafter referred to as “C&C”) come in different forms, shapes, and flavors. Early C&C infrastructures used IRC protocol to establish a connection between the target and the master. This was also a very common setup in botnets of the early 2000s when IRC was still a thing.

Taking advantage of popular online services and re-purposing them to serve an adversary’s goal has happened before, and will surely happen in the future. Social media-based botnet C&C is not necessarily a new phenomenon – since at least 2009 threat researchers have found and documented bot-based backdoors on Twitter.

bt2 is a Python-based backdoor in form of an IM bot that uses the infrastructure and the feature-rich bot API provided by Telegram, slightly re-purposing its communication platform to act as a C&C.

bt2 features include functionalities common to backdoor-like tools such as command execution, connect-back shell, download, and upload of files, a component to load and execute user-supplied shellcode, and more.

As the proof of concept was developed in Python, it works on multiple platforms with exception of the shellcode execution component (Windows only).

The bot sits on the Telegram network waiting for commands originating from the botmaster. The master can control the bots from any Telegram client, either desktop, command line, or mobile, allowing for unparalleled flexibility when performing post-exploitation against a target.

We have chosen Telegram due to its ever-growing popularity and reliable infrastructure and because it communicates via standard HTTPS protocol, making it extremely useful in circumventing several corporate network filters.

bt2 does not support encryption between the client and the server for the sake of maintaining the aforementioned flexibility. Although possible to implement, an encrypted communication channel will require a purpose-built Telegram client and this is currently not in the future plans for this tool.

The tool can be found in Blaze’s Github.

DISCLAIMER: bt2 is a mere proof of concept and by no means intends to breach the terms and conditions of Telegram. Additionally, it was developed for usage in legitimate penetration testing engagements and neither the author nor Blaze Information Security can be liable for any malicious use of the tool.

Usage

After the initial setup of creating a bot (not discussed here, please refer to this link), all you need is to start a conversation with it.

The command ‘/help‘ provides a self-explanatory list of commands along with basic usage of the tool:

Selection 008

Below you can see the tool in action, taking advantage of its functionality to get information about the system, list commands,  and download a file:

Selection 005

Along with the bot itself, the Github repository contains a script to aid the generation of shellcode in a format the tool will process. Essentially, it is possible to copy your favorite shellcode from Metasploit, paste it inside the tool and it will automatically convert it to a base64’d bytearray format, ready to be sent down the wire and execute the code.

Selection 007

Selection 006

As with any other piece of software, this is not perfect and there are already a few known bugs. Contributions are very welcome, so if you feel like improving upon it just fork the repository and don’t forget to send a pull request.

Conclusion

We hope this tool and the ideas laid out in this article can be beneficial for other information security consultants too.

With this article we wanted to share with the rest of the community some of the tools we use in our engagements and to point out the fact that pretty much every online service can be re-purposed into a C&C, ultimately serving the goal of an attacker.

References

Lenny Zeltser – When bots use social media for command and control
Arbor Networks – Twitter-based Botnet Command Channel

About the author

Blaze Labs

Blaze Labs

RELATED POSTS

Ready to take your security
to the next level?

We are! Let’s discuss how we can work together to create strong defenses against real-life cyber threats.

Stay informed, stay secure

Subscribe to our monthly newsletter

Get notified about new articles, industry insights and cybersecurity news