National Cyber Warfare Foundation (NCWF)login

telegram-bot-dumper for measuring the blast radius of leaked Telegram bot tokens


0 user ratings
2026-11-02 11:30:11
milo
Red Team (CNA)
"telegram-bot-dumper

telegram-bot-dumper extracts full chat history, media, and user rosters from a Telegram bot given only its token, letting authorized pentesters evidence the real impact of a hard-coded credential finding.








Toolsoxoj/telegram-bot-dumper — Python forensic CLI and web viewer that dumps all Telegram bot chats, media, and user data from a bot token
CategoryOSINT / pentest evidence collection for Telegram Bot API
Primary UseQuantifying impact of a leaked bot token discovered on an engagement (repo commits, CI logs, app bundles, configs) by dumping chats, users.csv rosters, and media into a searchable archive
Safe UseUse only in authorized penetration tests, incident response, and lab environments against bot tokens you own or are contractually permitted to assess; on a client engagement this is post-finding evidence gathering, not exploitation
Telemetry NoteEvery run authenticates to Telegram's servers with the bot token via Telethon, creating an API session file; Telegram-side logs will show the token actively fetching history and media — defenders should treat unexpected getMessages-heavy bot API activity as a token-compromise indicator and revoke tokens via @BotFather

telegram-bot-dumper by soxoj is a Python tool that answers a very specific question that comes up constantly on real engagements: you found a Telegram bot token hard-coded in a mobile app, committed to a repo, or leaked in a CI log — now what does that actually cost the client? The tool takes only that token as input and produces the full picture: bot metadata, every private chat's text history with media, and the profile information of every user who ever talked to the bot. With 422 stars, an MIT license, and topics spanning osint, cti, and pentesting, it occupies the niche of impact-evidence tooling rather than mass-harvesting tooling, and the README is unusually candid about the pentesting framing: a bare token reads as a low-severity finding until you can show that the bot is a corporate support desk where employees paste hostnames, VPN profiles, and credentials.


Architecturally the tool is built on Telethon, the popular async Python client for Telegram's MTProto API, and it needs a registered Telegram application's API_ID and API_HASH from my.telegram.org alongside the bot token itself — a two-credential model worth understanding: the app credentials identify your client software, the token identifies the victim bot. The core enumeration trick is id-space walking. Telegram message ids are sequential integers, so the default mode walks ids 1..∞ upward in batches of 200 via messages.getMessages, downloading every message, media attachment, and user profile photo it finds, then optionally keeps listening for new incoming traffic. The README documents that an upward walk fails on busy bots because old ids get pruned server-side, which is why the tool also walks --down.


The --down mode is the more interesting piece of engineering: it auto-probes the upper bound of the id space using powers of ten up to 10⁹, lands on the highest non-empty message id, and walks downward through recent, still-retained history. The README includes an honest empirical limit — in the author's tests a busy bot exposed roughly the last 500K messages before messages.getMessages returned only MessageEmpty for older ids, and no flag recovers history Telegram has already pruned server-side. For an analyst this matters: the tool cannot see beyond what Telegram retains, so findings about historical exposure should be scoped accordingly in a report.


Resilience features are thoughtful for a forensic tool. A downward walk checkpoints its next batch boundary to /last_message_id.txt, so after a crash or a Telegram FloodWait rate-limit you can resume with --resume in the existing dump folder without re-probing — the saved chat history and the session file are preserved. The resume flag is deliberately incompatible with --listen-only and --start-from-id and implies a downward walk, with a validation error before connecting if the checkpoint is missing or invalid. Batch size is tunable via --batch-size (values up to 1000 work), trading log feedback latency against round-trip count when scanning sparse id ranges, and --lookahead N keeps scanning past an all-empty batch — a direct mitigation for the documented failure mode where a batch of user-deleted messages makes the upward walk give up early.


Output structure is dump-per-bot: a / directory containing per-chat _history.txt files, per-user /.json records, media, and profile photos. Group and supergroup messages are tagged inline as [from:USER][group:CHAT] and outgoing bot replies as [to:USER], which preserves conversational context that a flat dump would lose — critical when you need to demonstrate that an employee actually sent a credential to the bot rather than the bot merely echoing. User resolution happens both for incoming messages and for outgoing bot replies, so you get the full two-sided picture of who the bot served and what it said back.


There is a lightweight mode aimed squarely at the scoping phase: --down --users-csv --no-photos --no-media --no-history skips all media and per-chat text and writes a single /users.csv with columns id, username, first_name, last_name, phone, lang_code, bot, premium, verified, scam, fake. That roster is often the most reportable artifact on its own — a phone-number-bearing list of every employee or customer who messaged a corporate bot is a privacy and regulatory finding independent of message content. For quieter collection there is --listen-only, which captures only new messages in real time and offers a downward dump from the first observed id; the --tor flag routes everything through a local Tor SOCKS5 proxy on 127.0.0.1:9050, which analysts should note is also a detectable network signature.


The web viewer is where the tool stops being a script and becomes an analysis environment. It presents a Telegram-Web-like browser UI over a dump: chat list, full message history with inline media, user profiles with photo carousels, and global search across every conversation at once. Live mode streams new messages into the browser as the dumper runs in the background, and any conversation can be exported as dump__.zip preserving the // directory structure. The viewer ships as a prebuilt Docker image — docker run --rm -p 127.0.0.1:8010:8010 soxoj/telegram-bot-dumper-web — or can be run from source with python webapp/server.py, and read-only viewing of an existing dump needs no API credentials at all, just a token matching the dump's bot.json.


The security posture of the viewer itself deserves a paragraph because it is unusually well-reasoned for an offensive tool. Enabling new dumps (--allow-new-dumps / ALLOW_NEW_DUMPS=1) lets anyone who can reach the page make your server dump any bot under your API_ID, so the viewer refuses to start with that flag on a non-loopback HOST. Since Docker forces HOST=0.0.0.0 inside the container, an explicit ALLOW_PUBLIC=1 opt-in is required on top, and the documentation consistently shows the port bound to 127.0.0.1. API_ID/API_HASH are passed via environment or a local .env, never baked into the image. This is a tool whose author has thought about the operator accidentally becoming the victim.


Known limitations are documented rather than hidden. messages.getMessages only returns the bot's private-message history; supergroup history needs per-channel calls bots typically cannot make. However, if the bot was added to a group with Telegram's privacy mode disabled — the setting that lets bots see all group traffic instead of just commands, mentions, and replies — --listen-only will dump those group messages in real time, which is a meaningful configuration-dependent escalation of exposure worth checking on any client bot. There is also a faster Golang port, telegram-bot-dumper-go by ScBoln, and full documentation hosted on telegram-bot-dumper.readthedocs.io for operators who want depth beyond the README.


For defenders, this tool is best read as a threat model in source form. It proves that a bot token is not a single credential but a bulk-read primitive over every conversation the bot has ever had, within Telegram's retention window — which is why token hygiene for corporate bots (support desks, IT/DevOps helpers, AI assistants) matters as much as any API key. The README even closes with a nod to how these tokens surface, referencing GitHub code-search dorks for telepot.bot tokens. The defensive takeaway for authorized teams is direct: rotate bot tokens via @BotFather, keep them out of client bundles and repos, enable privacy mode on group bots, and alert on anomalous bulk history-fetch patterns against production bot tokens.


Setup is minimal — Python >= 3.6, a pinned Telethon from requirements.txt, and application credentials from my.telegram.org. The author also ships an offline test suite that runs without network or token (pytest tests/ --ignore=tests/bot_test.py), plus an optional integration test against a real bot gated behind TEST_TOKEN, which is a good sign of maintainable code. Whether you use it to evidence a finding during an authorized assessment, to scope a leaked-token incident in response, or simply to understand what a bot token is worth on the offensive market, telegram-bot-dumper is one of the cleanest demonstrations available that credential severity is decided by what the credential can read, not by what it is called.



Official project repository for soxoj/telegram-bot-dumper.

Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.






Source: OffensiveSec
Source Link: https://www.offsecblog.com/2026/11/telegram-bot-dumper-for-measuring-blast.html


Comments
new comment
Nobody has commented yet. Will you be the first?
 
Forum
Red Team (CNA)



Copyright 2012 through 2026 - National Cyber Warfare Foundation - All rights reserved worldwide.