Skip to content

Commit 25fee91

Browse files
committed
Replace share listing with test read on SYSVOL share
1 parent 55cd9bb commit 25fee91

1 file changed

Lines changed: 41 additions & 39 deletions

File tree

nxc/modules/gpp_privileges.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,45 +98,47 @@ def options(self, context, module_options):
9898
self.no_ldap = module_options.get("NO_LDAP", False)
9999

100100
def on_login(self, context, connection):
101-
shares = connection.shares()
102-
for share in shares:
103-
if share["name"] == "SYSVOL" and "READ" in share["access"]:
104-
context.log.display("Searching for GptTmpl.inf files")
105-
106-
paths = connection.spider("SYSVOL", pattern=["GptTmpl.inf"])
107-
108-
if not paths:
109-
context.log.warning("No GptTmpl.inf files found in SYSVOL.")
110-
return
111-
112-
for path in paths:
113-
if "6AC1786C-016F-11D2-945F-00C04fB984F9" in path: # Default Domain Policy
114-
context.log.success(f"Found Default Domain Policy GptTmpl.inf: {path}")
115-
else:
116-
context.log.info(f"Found GptTmpl.inf: {path}")
117-
118-
buf = BytesIO()
119-
connection.conn.getFile("SYSVOL", path, buf.write)
120-
121-
try:
122-
content = buf.getvalue().decode("utf-16le")
123-
except UnicodeDecodeError as e:
124-
context.log.error(f"Failed to decode {path} as UTF-16LE: {e}")
125-
continue
126-
127-
privileges = self.extract_privileges(content)
128-
if privileges:
129-
ldap_connection = None
130-
if not self.no_ldap:
131-
ldap_connection = self.initialize_ldap_connection(context, connection)
132-
133-
context.log.success(f"Privileges extracted from {path}:")
134-
for privilege, sids in privileges.items():
135-
resolved_sids = [self.resolve_sid(context, sid, ldap_connection) for sid in sids]
136-
context.log.highlight(f"{privilege}: {', '.join(resolved_sids)}")
137-
138-
if ldap_connection:
139-
ldap_connection.unbind()
101+
try:
102+
connection.conn.listPath("SYSVOL", "*")
103+
except Exception as e:
104+
context.log.fail(f"Failed to list shares: {e}")
105+
return
106+
107+
context.log.display("Searching for GptTmpl.inf files")
108+
paths = connection.spider("SYSVOL", pattern=["GptTmpl.inf"])
109+
110+
if not paths:
111+
context.log.warning("No GptTmpl.inf files found in SYSVOL.")
112+
return
113+
114+
for path in paths:
115+
if "6AC1786C-016F-11D2-945F-00C04fB984F9" in path: # Default Domain Policy
116+
context.log.success(f"Found Default Domain Policy GptTmpl.inf: {path}")
117+
else:
118+
context.log.info(f"Found GptTmpl.inf: {path}")
119+
120+
buf = BytesIO()
121+
connection.conn.getFile("SYSVOL", path, buf.write)
122+
123+
try:
124+
content = buf.getvalue().decode("utf-16le")
125+
except UnicodeDecodeError as e:
126+
context.log.error(f"Failed to decode {path} as UTF-16LE: {e}")
127+
continue
128+
129+
privileges = self.extract_privileges(content)
130+
if privileges:
131+
ldap_connection = None
132+
if not self.no_ldap:
133+
ldap_connection = self.initialize_ldap_connection(context, connection)
134+
135+
context.log.success(f"Privileges extracted from {path}:")
136+
for privilege, sids in privileges.items():
137+
resolved_sids = [self.resolve_sid(context, sid, ldap_connection) for sid in sids]
138+
context.log.highlight(f"{privilege}: {', '.join(resolved_sids)}")
139+
140+
if ldap_connection:
141+
ldap_connection.unbind()
140142

141143
def extract_privileges(self, content):
142144
"""Parses the content of GptTmpl.inf to extract privilege rights."""

0 commit comments

Comments
 (0)