MalwareBotReplayer is a toolchain to extract Telegram malware bots from VirusTotal telemetry, invite them into your own Telegram group, and automatically mirror their messages there.
It consists of four main steps:
- Download VirusTotal pages (
get_tg_connection_files.py) - Extract malware bots and save them in PocketBase (
get_bot.py) - Invite bots to a group & forward messages (
prepare_bot.py) - Forward messages
forward_message.py
⚠️ Note: With a standard VirusTotal license (500 requests/day), processing all bots/files can take a very long time (months to years) depending on the amount of data. The scripts respect the rate limits and work sequentially.
- Searches VirusTotal file analyses for stealer/keylogger indicators
- Fetches
/contacted_urlsof samples from VirusTotal API - Extracts Telegram Bot API URLs (
https://api.telegram.org/bot...) - Validates bot tokens with Telegram (
getMe,can_join_groups) - Saves recognized bots in a PocketBase collection
- Uses a Telegram user account (Telethon) to invite bots to your target group
- Forwards messages from bot source chats to your group via Bot API
High-level workflow:
-
Getting contected Files from telegram api url:
get_tg_connections_files.py- gets all the files which contacted telegram.api.org
- use
/contacted_urls?limit=40so allways 40 files/json - uses
next_urlto make sure not file is downloaded twice. - Saves each page as
page_<n>.jsoninVT_OUTPUT_DIR.
-
get botid and chat id:
get_bot.pyprocesses each file:- parses all the json files in lexicographical order
- Extracts the filid from the json
- getting contacted urls from the file from VT
- parses botid/chat
- check with
getmeif bot can be used - Stores valid bots as records in PocketBase
-
Preparation:
prepare_bot.py:- Loads records from PocketBase with
state='detected' - check with
getmeif bot can be used (yes again) - Removes webhook temporarily if needed
- Invites the bot into your specified Telegram group via Telethon
- Updates PocketBase record with
state='preparing_successful_done'andtargetchatid - invites max 30 Bots per run
- Loads records from PocketBase with
-
Forwarding:
forward_message.py:- Loads records with
state='preparing_successful_done'andnotworking != true - Uses Bot API
forwardMessagesto mirror messages fromsourcechatidto your target group - Works in message ID blocks, respects 429 rate limits
- Saves progress in
lastmessageid - Updates record
state='forwarding'
- Loads records with
You need a running PocketBase instance.
- Download PocketBase binary from https://pocketbase.io
- Start it, e.g.
./pocketbase serve(adjust for your OS) - Open the admin UI (usually
http://127.0.0.1:8090/_/) - Create a collection named e.g.
TI
Create a collection (e.g. TI) with the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
id |
String | optional | Auto-generated if not set |
botname |
String | optional | Telegram username of the bot |
bottoken |
String | optional | Bot token, stored as bot<token> |
malwarefilehash |
String | optional | Hash of the VT sample (e.g. SHA256) |
lastmessageid |
String | optional | Last message ID that was forwarded |
sourcechatid |
String | optional | Original chat ID where the bot was seen |
targetchatid |
String | optional | Target group chat ID (your group) |
state |
String | optional | Workflow state (e.g. detected, preparing_successful_done, forwarding) |
notworking |
Boolean | optional | Marks invalid or defunct bots |
setting up the API Rules wisely to get a connection to the Database
Create a .env file in your project folder with the following settings:
PB_URL="" # pocketbase url "http://127.0.0.1:8090
PB_COLLECTION="" # pocketbase collection name
PB_AUTH_TOKEN="" # pb auth token
TG_API_ID= # telegram ap id
TG_API_HASH= # telegram api hash
TG_SESSION_NAME= # session name from telegram
VT_API_KEY="" # VirusTotal API Key
VT_OUTPUT_DIR="" # where the json from get_tg_connections_files.py will be saved
VT_FIN_FOLDER="" # where the processed json will be saved should not be the same as the output folderpython3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcurl --request GET \
--url 'https://www.virustotal.com/api/v3/domains/api.telegram.org/communicating_files?limit=10' \
--header 'accept: application/json' \
--header 'x-apikey: <your key> -o page_1.json- save the file to the VT_OUTPUT_DIR Directory
python get_tg_connection_files.pypython get_bot.py- create some telegram groups !Take care by this, allways check the anonym button in the admin setting in the group setting - its off by default!
- get the invite link from a group
python3 prepare_bot.py <groupname-or-invite-link>python3 forward_message.py- Can have dublicates in db -> todo
- inviting only works well by invivte link -> todo with group name
- Standard API key limits to 500 requests/day from VirusTotal
- Full processing of all pages & contacted URLs can take months depending on data volume.
- Flood wait errors from Telegarm may cause long delays during bot additions.
- This project is intended for research, incident response, and threat intelligence purposes only.
- Inviting and forwarding malware bot messages should only be done in controlled environments and in compliance with applicable laws.