Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[t3l3machus/Villain#106] add custom callback for every new connection resolve #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions Core/villain_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion Villain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------- #
Expand All @@ -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()

Expand All @@ -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

Expand Down