Compare commits

...
Author SHA1 Message Date
Marshall Hallenbeck 45573e662e feat(helpers): add module loot and logging helpers
Add nxc/helpers/modules.py with functions for creating module-specific
log/loot directories and saving loot data. Update example_module to
demonstrate add_loot_data usage and fix module name to use underscore.
2026-03-14 11:56:43 -04:00
2 changed files with 50 additions and 2 deletions

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import datetime
import logging
from os import makedirs
from nxc.paths import NXC_PATH
def create_log_dir(module_name):
makedirs(f"{NXC_PATH}/logs/{module_name}", exist_ok=True)
def create_loot_dir(module_name):
makedirs(f"{NXC_PATH}/loot/{module_name}", exist_ok=True)
def generate_module_log_file(module_name):
create_log_dir(module_name)
return f"{NXC_PATH}/logs/{module_name}/{datetime.datetime.now().strftime('%Y-%m-%d')}.log"
def create_module_logger(module_name):
log_file = generate_module_log_file(module_name)
module_logger = logging.getLogger(module_name)
module_logger.propagate = False
module_logger.setLevel(logging.INFO)
module_file_handler = logging.FileHandler(log_file)
module_file_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
module_logger.addHandler(module_file_handler)
return module_logger
def add_loot_data(module_name, filename, data):
create_loot_dir(module_name)
loot_file = get_loot_data_filepath(module_name, filename)
with open(loot_file, "a") as file:
file.write(data)
def get_loot_data_filepath(module_name, filename):
return f"{NXC_PATH}/loot/{module_name}/{filename}"
def get_loot_data_folder(module_name):
return f"{NXC_PATH}/loot/{module_name}"
+6 -2
View File
@@ -1,4 +1,5 @@
from nxc.helpers.misc import CATEGORY
from nxc.helpers.modules import add_loot_data
class NXCModule:
@@ -8,7 +9,7 @@ class NXCModule:
Module by @yomama
"""
name = "example module"
name = "example_module" # Make sure this is unique and one word (no spaces)
description = "I do something"
supported_protocols = [] # Example: ['smb', 'mssql']
category = CATEGORY.ENUMERATION # Must be one of "Enumeration", "Privilege Escalation" or "Credential Dumping". Use what fits best.
@@ -45,8 +46,11 @@ class NXCModule:
except Exception as e:
context.log.exception(f"Exception occurred: {e}") # This will display an exception traceback screen after an exception was raised and should only be used for critical errors
# Use this function to add loot data you want to save to $NXC_PATH/loot/$MODULE_NAME/$FILENAME
add_loot_data(self.name, "custom_loot_file.txt", "Data can be anything you want, passwords, hashes, or anything")
def on_admin_login(self, context, connection):
"""Concurrent.
Required if on_login is not present
This gets called on each authenticated connection with Administrative privileges
This gets called on each authenticated connection with Administrative privileges
"""