Skip to content

Commit 08ad1cc

Browse files
authored
Merge pull request Pennyw0rth#1041 from Wyndoo/module-get-scriptpath
2 parents d2342db + 37194c6 commit 08ad1cc

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

nxc/modules/get-scriptpath.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import json
2+
from nxc.helpers.misc import CATEGORY
3+
from nxc.parsers.ldap_results import parse_result_attributes
4+
5+
6+
class NXCModule:
7+
"""
8+
Get the scriptPath attribute of users
9+
10+
Module by @wyndoo
11+
"""
12+
name = "get-scriptpath"
13+
description = "Get the scriptPath attribute of all users."
14+
supported_protocols = ["ldap"]
15+
category = CATEGORY.ENUMERATION
16+
17+
def options(self, context, module_options):
18+
"""
19+
FILTER Apply the FILTER (grep-like) (default: '')
20+
OUTPUTFILE Path to a file to save the results (default: None)
21+
"""
22+
self.filter = ""
23+
self.outputfile = None
24+
25+
if "FILTER" in module_options:
26+
self.filter = module_options["FILTER"]
27+
28+
if "OUTPUTFILE" in module_options:
29+
self.outputfile = module_options["OUTPUTFILE"]
30+
31+
def on_login(self, context, connection):
32+
# Building the search filter
33+
resp = connection.search(
34+
searchFilter="(scriptPath=*)",
35+
attributes=["sAMAccountName", "scriptPath"]
36+
)
37+
38+
context.log.debug(f"Total of records returned {len(resp)}")
39+
answers = parse_result_attributes(resp)
40+
context.log.debug(f"Filtering for scriptPath containing: {self.filter}")
41+
filtered_answers = list(filter(lambda x: self.filter in x["scriptPath"], answers))
42+
43+
if filtered_answers:
44+
context.log.success("Found the following attributes: ")
45+
for answer in filtered_answers:
46+
context.log.highlight(f"User: {answer['sAMAccountName']:<20} ScriptPath: {answer['scriptPath']}")
47+
48+
# Save the results to a file
49+
if self.outputfile:
50+
self.save_to_file(context, filtered_answers)
51+
else:
52+
context.log.fail("No results found after filtering.")
53+
54+
def save_to_file(self, context, answers):
55+
"""Save the results to a JSON file."""
56+
try:
57+
# Format answers as a list of dictionaries for JSON output
58+
json_data = [{"sAMAccountName": answer["sAMAccountName"], "scriptPath": answer["scriptPath"]} for answer in answers]
59+
60+
# Save the JSON data to the specified file
61+
with open(self.outputfile, "w") as f:
62+
json.dump(json_data, f, indent=4)
63+
context.log.success(f"Results successfully saved to {self.outputfile}")
64+
65+
except Exception as e:
66+
context.log.error(f"Failed to save results to file: {e}")

tests/e2e_commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M user-de
234234
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M whoami
235235
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M dump-computers
236236
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M raisechild
237+
netexec ldap TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -M get-scriptpath
237238
##### WINRM
238239
netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS # need an extra space after this command due to regex
239240
netexec winrm TARGET_HOST -u LOGIN_USERNAME -p LOGIN_PASSWORD KERBEROS -X ipconfig

0 commit comments

Comments
 (0)