Skip to content

Commit 1105dcd

Browse files
357384nMarshall-Hallenbeck
authored andcommitted
Update powershell_history.py
Add export feature and some keywords Signed-off-by: Sébastien Miguel <43112303+357384n@users.noreply.github.com>
1 parent bfed3d4 commit 1105dcd

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

nxc/modules/powershell_history.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ class NXCModule:
1111
multiple_hosts = True
1212

1313
def options(self, context, module_options):
14-
"""Define module options."""
15-
pass
14+
"""Export all the history with -o export=enable"""
15+
context.log.info(f"Received module options: {module_options}")
16+
self.export = module_options.get('EXPORT', 'disable').lower()
17+
context.log.info(f"Option export set to: {self.export}")
1618

1719
def execute_command(self, connection, command):
1820
"""Execute a command on the remote system and return the output."""
@@ -34,7 +36,7 @@ def analyze_history(self, history):
3436
"password", "passwd", "secret", "credential", "key",
3537
"get-credential", "convertto-securestring", "set-localuser",
3638
"new-localuser", "set-adaccountpassword", "new-object system.net.webclient",
37-
"invoke-webrequest", "invoke-restmethod"
39+
"invoke-webrequest", "invoke-restmethod", "pass"
3840
]
3941
sensitive_commands = []
4042
for command in history:
@@ -58,12 +60,20 @@ def on_admin_login(self, context, connection):
5860
context.log.info("No sensitive commands found in PowerShell history.")
5961
else:
6062
context.log.info("No PowerShell history found.")
61-
62-
# Write history to file in current directory
63-
with open("powershell_history.txt", "w") as file:
64-
for cmd in history:
65-
file.write(cmd + "\n")
66-
print("History written to powershell_history.txt")
63+
64+
# Check if export is enabled
65+
context.log.info(f"Export option is set to: {self.export}")
66+
if self.export == 'enable':
67+
host = connection.host # Assuming 'host' contains the target IP or hostname
68+
filename = f"{host}.powershell_history.txt"
69+
context.log.info(f"Export enabled, writing history to {filename}")
70+
try:
71+
with open(filename, "w") as file:
72+
for cmd in history:
73+
file.write(cmd + "\n")
74+
context.log.info(f"History written to {filename}")
75+
except Exception as e:
76+
context.log.fail(f"Failed to write history to {filename}: {e}")
6777

6878
except Exception as e:
6979
context.log.fail(f"UNEXPECTED ERROR: {e}")

0 commit comments

Comments
 (0)