Skip to content

Commit 81a1449

Browse files
committed
Group users when being in both dom admin and enterprise admin group
1 parent 65bd7ae commit 81a1449

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

nxc/modules/presence.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ def on_admin_login(self, context, connection):
6868
user_handle = samr.hSamrOpenUser(dce, domain_handle, samr.MAXIMUM_ALLOWED, rid)["UserHandle"]
6969
username = samr.hSamrQueryInformationUser2(dce, user_handle, samr.USER_INFORMATION_CLASS.UserAllInformation)["Buffer"]["All"]["UserName"]
7070

71-
admin_users.append({"username": username, "sid": f"{domain_sid}-{rid}", "domain": domain, "group": group_name, "in_tasks": False, "in_directory": False})
71+
# If user already exists, append group name
72+
if any(u["sid"] == f"{domain_sid}-{rid}" for u in admin_users):
73+
user = next(u for u in admin_users if u["sid"] == f"{domain_sid}-{rid}")
74+
user["group"].append(group_name)
75+
else:
76+
admin_users.append({"username": username, "sid": f"{domain_sid}-{rid}", "domain": domain, "group": [group_name], "in_tasks": False, "in_directory": False})
7277
context.log.debug(f"Found user: {username} with RID {rid} in group {group_name}")
7378
except Exception as e:
7479
context.log.debug(f"Failed to get user info for RID {rid}: {e!s}")
@@ -116,7 +121,7 @@ def check_users_directory(self, context, connection, admin_users):
116121
if user["username"].lower() in dirs_found or \
117122
(user["username"].lower() == "administrator" and f"{user['username'].lower()}.{user['domain']}" in dirs_found):
118123
user["in_directory"] = True
119-
context.log.debug(f"Found user {user['username']} in directories")
124+
context.log.info(f"Found user {user['username']} in directories")
120125

121126
def check_tasklist(self, context, connection, admin_users):
122127
"""Checks tasklist over rpc."""
@@ -136,7 +141,7 @@ def check_tasklist(self, context, connection, admin_users):
136141
for user in admin_users:
137142
if process["pSid"] == user["sid"]:
138143
user["in_tasks"] = True
139-
context.log.debug(f"Matched process {process['ImageName']} with user {user['username']}")
144+
context.log.info(f"Matched process {process['ImageName']} with user {user['username']}")
140145

141146
def print_grouped_results(self, context, admin_users):
142147
"""Logs all results grouped per host in order"""
@@ -146,13 +151,13 @@ def print_grouped_results(self, context, admin_users):
146151
if dir_users:
147152
context.log.success("Found users in directories:")
148153
for user in dir_users:
149-
context.log.highlight(f"{user['username']} ({user['group']})")
154+
context.log.highlight(f"{user['username']} ({', '.join(user['group'])})")
150155

151156
tasklist_users = [user for user in admin_users if user["in_tasks"]]
152157
if tasklist_users:
153158
context.log.success("Found users in tasklist:")
154159
for user in tasklist_users:
155-
context.log.highlight(f"{user['username']} ({user['group']})")
160+
context.log.highlight(f"{user['username']} ({', '.join(user['group'])})")
156161

157162
# Making this less verbose to better scan large ranges
158163
if not dir_users and not tasklist_users:

0 commit comments

Comments
 (0)