This script is a Telegram bot written in Python using the python-telegram-bot library. The bot fetches data from the Hack The Box platform and allows users to interact with it using Telegram commands and inline keyboard buttons.
- Python 3.10+ (the bot uses
match/casesyntax and the asyncpython-telegram-botv21+ API)
It's recommended to install the dependencies in a Python virtual environment (venv) to keep them isolated from your system's Python packages.
-
Clone the repository:
git clone https://github.com/vpanal/HTB_Telegram_bot.git cd HTB_Telegram_bot -
Create and activate a virtual environment:
python3 -m venv venv # Linux / macOS source venv/bin/activate # Windows (PowerShell) venv\Scripts\Activate.ps1
-
Install the required packages:
pip install -r requeriments.txt
-
When you're done using the bot, you can deactivate the virtual environment with:
deactivate
The bot is configured using environment variables, loaded from a .env file (via python-dotenv). A .env file keeps your secrets (tokens, IDs, etc.) out of the source code and out of version control — the .gitignore in this repo already excludes .env so you don't accidentally commit it.
-
Copy the example file to create your own
.env:cp .env.example .env
-
Edit
.envand fill in your own values:Variable Description ALLOWED_CHAT_IDSComma-separated Telegram chat IDs allowed to use the bot (e.g. 123456,654321).ADMIN_CHAT_IDSComma-separated Telegram chat IDs with administrator permissions (e.g. 123456).TELEGRAM_BOT_TOKENTelegram bot token obtained from BotFather. HTB_USER_IDSComma-separated Hack The Box user IDs to track (e.g. 1111,2222,3333).HTB_BEARER_TOKENBearer Token obtained from the Hack The Box platform. WIKI_URLURL to your team's Wiki/Notion, shown as a button in the bot menu. PROXY_ENABLEDtrueorfalse. Enables routing HTB API requests through an HTTP(S) proxy (e.g. Burp Suite).PROXY_URLProxy URL to use when PROXY_ENABLED=true(e.g.http://127.0.0.1:8080). -
Make sure you have a working Telegram bot. If you don't have one, create a new bot using BotFather on Telegram and obtain the bot token.
Note: if
TELEGRAM_BOT_TOKENis missing, the bot will refuse to start and remind you to configure your.envfile.
Once you have activated your virtual environment and configured .env, you can run the bot with:
python htb_bot.pyThe bot will start running and listening for incoming messages and interactions.
/start: Start the bot and display the main menu to choose actions./help: Display a help message.
Additional Commands:
/cachedate: Displays the current date and time of the Hack The Box platform's cache from where the data is retrieved./adduser: Adds a new Hack The Box user to the list of users tracked by the bot./purgeuser: Removes a Hack The Box user from the list of users tracked by the bot.
The bot provides the following main features:
- Main Menu: The main menu provides options to access different functionalities.
- Machine Information: The bot can fetch information about released machines, including their name, operating system, difficulty, IP, date, number of user owns, and number of root owns.
- Unreleased Machines: The bot can display information about unreleased machines, including their names, operating systems, and difficulties.
- User Information: The bot can fetch and display the basic profile information for specified Hack The Box users.
- Make sure to keep your bot token and other sensitive information secure and do not share it publicly.
- Never commit your
.envfile — it's already listed in.gitignore. Only.env.example(with placeholder values) should be tracked in version control. - It's recommended to deploy the bot in a secure environment, such as a server, to ensure continuous operation.
python-telegram-botlibrary documentation: python-telegram-bot- Hack The Box platform: Hack The Box
- Hack The Box API: HTB API
Feel free to modify the script to suit your specific requirements. Happy botting!
- vpanal: Pentester.
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. Puedes You can get more information in the LICENSE file.