From 7eabd8def1f51a47f3b3432010fe3224890c5bf6 Mon Sep 17 00:00:00 2001 From: Blueberet Date: Tue, 6 Jun 2023 12:34:01 +0700 Subject: [PATCH] feat: add custom callback for every new connection --- Core/settings.py | 4 ++++ Core/villain_core.py | 24 ++++++++++++++++++++++++ Villain.py | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Core/settings.py b/Core/settings.py index c4cc735..fd08a4f 100644 --- a/Core/settings.py +++ b/Core/settings.py @@ -77,6 +77,10 @@ class TCP_Sock_Handler_Settings: # Max failed echo response requests before a connection is characterized as lost fail_count = 3 +class Callback_Settings: + callback_file = None + callback_function = None + class Payload_Generator_Settings: diff --git a/Core/villain_core.py b/Core/villain_core.py index 35e472c..702bb6b 100644 --- a/Core/villain_core.py +++ b/Core/villain_core.py @@ -1095,6 +1095,14 @@ def do_GET(self): Sessions_Manager.active_sessions[session_id]['Username'] = url_split[2] print_to_prompt(f'\r[{GREEN}Shell{END}] Backdoor session established on {ORANGE}{self.client_address[0]}{END}') + if Callback_Settings.callback_file != None: + print_to_prompt(f'\r{GREEN}[Callback]{END} Executing callback function...{Callback_Settings.callback_file}') + + if Callback_Settings.callback_function(Sessions_Manager.active_sessions[session_id]): + print_to_prompt(f'\r{GREEN}[Callback]{END} Callback function executed successfully.') + else: + print_to_prompt(f'\r{WARN}[Callback]{END} Callback function failed to execute.') + try: Thread(target = self.monitor_shell_state, args = (session_id,), name = f'session_state_monitor_{self.client_address[0]}', daemon = True).start() except: @@ -1591,6 +1599,14 @@ def sock_handler(self, conn, address): del decrypted_data, new_session_id Core_Server.send_msg(conn, self.response_ack(sibling_id)) + if Callback_Settings.callback_file != None: + print_to_prompt(f'\r{GREEN}[Callback]{END} Executing callback function...{Callback_Settings.callback_file}') + + if Callback_Settings.callback_function(Sessions_Manager.active_sessions[session_id]): + print_to_prompt(f'\r{GREEN}[Callback]{END} Callback function executed successfully.') + else: + print_to_prompt(f'\r{WARN}[Callback]{END} Callback function failed to execute.') + elif decrypted_data[0] == 'shell_session_status_update': @@ -2462,6 +2478,14 @@ def nc_shell_handler(self, conn, address, iface): print_to_prompt(f'\r[{GREEN}Shell{END}] Backdoor session established on {ORANGE}{address[0]}{END}') print_to_prompt(f'\r[{WARN}] Failed to resolve hostname. Use "repair" to declare it manually.') if hostname_undefined else chill() + if Callback_Settings.callback_file != None: + print_to_prompt(f'\r{GREEN}[Callback]{END} Executing callback function...{Callback_Settings.callback_file}') + + if Callback_Settings.callback_function(Sessions_Manager.active_sessions[session_id]): + print_to_prompt(f'\r{GREEN}[Callback]{END} Callback function executed successfully.') + else: + print_to_prompt(f'\r{WARN}[Callback]{END} Callback function failed to execute.') + new_session_data = deepcopy(Sessions_Manager.active_sessions[session_id]) new_session_data['session_id'] = session_id new_session_data['self_owned'] = False diff --git a/Villain.py b/Villain.py index a52a714..c551932 100644 --- a/Villain.py +++ b/Villain.py @@ -7,9 +7,10 @@ import argparse +import importlib.util from subprocess import check_output from Core.common import * -from Core.settings import Hoaxshell_Settings, Core_Server_Settings, TCP_Sock_Handler_Settings, File_Smuggler_Settings +from Core.settings import Hoaxshell_Settings, Core_Server_Settings, TCP_Sock_Handler_Settings, File_Smuggler_Settings, Callback_Settings # -------------- Arguments -------------- # @@ -23,6 +24,7 @@ parser.add_argument("-k", "--keyfile", action="store", help = "Path to the private key for your certificate (for HoaxShell https server).") parser.add_argument("-u", "--update", action="store_true", help = "Pull the latest version from the original repo.") parser.add_argument("-q", "--quiet", action="store_true", help = "Do not print the banner on startup.") +parser.add_argument("-cb", "--callback", action="store", help="Path to a custom python callback script that will be executed once a new session is created. This file should have a function called 'callback' that takes a single argument (session object) and return boolean (success/failure).") args = parser.parse_args() @@ -32,6 +34,17 @@ Hoaxshell_Settings.ssl_support = True if (args.certfile and args.keyfile) else False Hoaxshell_Settings.bind_port = args.hoax_port if args.hoax_port else Hoaxshell_Settings.bind_port +# Parse the callback +if args.callback: + Callback_Settings.callback_file = args.callback + # load the file and check if it has a function called 'callback' + filename = Callback_Settings.callback_file.split('/')[-1] + spec = importlib.util.spec_from_file_location(filename, Callback_Settings.callback_file) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + Callback_Settings.callback_function = getattr(module, 'callback') + if Hoaxshell_Settings.ssl_support: Hoaxshell_Settings.bind_port_ssl = args.hoax_port if args.hoax_port else Hoaxshell_Settings.bind_port_ssl