Detailed Technical Analysis of "Creating your own Telegram Bot for Recon & Bug Bounty"

Overview:
Santosh D Bobade's write-up takes the reader through the process of creating a Telegram bot specifically tailored for reconnaissance in bug bounty programs. It details the technical steps involved in setting up the bot, integrating it with various recon tools, and automating the recon process.

Key Technical Details:

  1. Setting Up the Telegram Bot:

    • BotFather: Initial bot creation is done using the Telegram BotFather, which provides an API token necessary for interacting with Telegram's API. This step is straightforward but essential for authentication and further interaction.
    • Python & Libraries: The primary language used is Python, leveraging 'python-telegram-bot' for interacting with the Telegram API and 'requests' for making HTTP requests to external services.
  2. Installing Required Libraries:

    bash pip install python-telegram-bot requests This command installs the necessary Python libraries. python-telegram-bot provides a wrapper to interact with Telegram APIs seamlessly, while requests allows HTTP requests to interact with recon tools/APIs.

  3. Basic Bot Structure:

    • Initialization: The bot is initialized with the API token obtained from BotFather. ```python from telegram.ext import Updater, CommandHandler

    updater = Updater("YOUR_TELEGRAM_BOT_API_TOKEN", use_context=True) dispatcher = updater.dispatcher `` - **Command Handlers**: Various command handlers are defined to respond to specific commands like/start,/subdomain,/screenshot`, etc. Each command triggers a specific functionality or tool.

    ```python def start(update, context): update.message.reply_text("Hello! I am your bot for reconnaissance.")

    start_handler = CommandHandler('start', start) dispatcher.add_handler(start_handler) ```

  4. Integrating Recon Tools:

    • Subdomain Enumeration: Using tools like Sublist3r, the bot can enumerate subdomains. ```python import sublist3r

    def subdomain(update, context): domain = context.args[0] subdomains = sublist3r.main(domain, 40, savefile=None, ports=None, silent=True, verbose=False, enable_bruteforce=False, engines=None) update.message.reply_text('\n'.join(subdomains))

    subdomain_handler = CommandHandler('subdomain', subdomain) dispatcher.add_handler(subdomain_handler) ``` This segment demonstrates how the bot accepts a domain as input and returns subdomains by invoking Sublist3r.

    • Screenshot Functionality: Tools like webscreenshot (or similar headless browser setups) can be used to capture webpage screenshots. ```python import os

    def screenshot(update, context): url = context.args[0] filename = f"{url}.png" os.system(f"webscreenshot {url} -o {filename}") update.message.reply_photo(photo=open(filename, 'rb'))

    screenshot_handler = CommandHandler('screenshot', screenshot) dispatcher.add_handler(screenshot_handler) ``` Here, the bot captures a screenshot of the provided URL and sends it back to the user.

  5. Enhancing Functionality:

    • Error Handling: It's essential to handle possible exceptions, especially network or API related issues. ```python def error(update, context): update.message.reply_text('An error occurred while processing your request.')

    dispatcher.add_error_handler(error) ``` This helps in ensuring smooth user experience even when things go wrong.

    • Additional Recon Tools: You can integrate additional tools like Nmap for network scanning or WhoIs lookup for domain information. These integrations would follow a similar pattern as above, invoking the tool and processing the output before sending it back to the user.
  6. Deploying the Bot:

    • Running Locally: During development, the bot can be run locally. python if __name__ == '__main__': updater.start_polling() updater.idle()
    • Production Deployment: For continuous operation, deploying on cloud platforms (AWS, GCP, Heroku, etc.) ensures availability and reliability.

Key Takeaways:

Conclusion:

The write-up provides clear, actionable steps to build and deploy a functional Telegram bot for reconnaissance tasks. By integrating common recon tools, the bot can automate tedious tasks and provide real-time updates, significantly benefiting bug bounty hunters in the data-gathering phase.

For full details, check the original blog post here.