Skip to content

Commit 95ae5de

Browse files
Merge branch 'main' into marshall-db-ip-fix
2 parents 9259825 + f8293d1 commit 95ae5de

File tree

8 files changed

+164
-363
lines changed

8 files changed

+164
-363
lines changed

nxc/modules/group-mem.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class NXCModule:
1919
answers = []
2020

2121
def options(self, context, module_options):
22-
"""
22+
r"""
23+
[REMOVED] Use the ldap flag '--groups "Administrators"' instead of the module group-mem.
24+
2325
group-mem: Specify group-mem to call the module
2426
GROUP: Specify the GROUP option to query for that group's members
2527
Usage: nxc ldap $DC-IP -u Username -p Password -M group-mem -o GROUP="domain admins"
@@ -34,6 +36,9 @@ def options(self, context, module_options):
3436
sys.exit(1)
3537

3638
def on_login(self, context, connection):
39+
self.logger.fail("[REMOVED] Use the ldap flag '--groups \"Administrators\"' instead of the module group-mem.")
40+
return None
41+
3742
# First look up the SID of the group passed in
3843
search_filter = "(&(objectCategory=group)(cn=" + self.GROUP + "))"
3944
attribute = "objectSid"

nxc/protocols/ldap.py

+36-13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
UF_TRUSTED_FOR_DELEGATION,
2222
UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION,
2323
UF_SERVER_TRUST_ACCOUNT,
24+
SAM_MACHINE_ACCOUNT,
2425
)
2526
from impacket.krb5 import constants
2627
from impacket.krb5.kerberosv5 import getKerberosTGS, SessionKeyDecryptionError
@@ -678,25 +679,47 @@ def users(self):
678679

679680
def groups(self):
680681
# Building the search filter
681-
search_filter = "(objectCategory=group)"
682-
attributes = ["name"]
682+
if self.args.groups:
683+
self.logger.debug(f"Dumping group: {self.args.groups}")
684+
search_filter = f"(cn={self.args.groups})"
685+
attributes = ["member"]
686+
else:
687+
search_filter = "(objectCategory=group)"
688+
attributes = ["cn", "member"]
683689
resp = self.search(search_filter, attributes, 0)
684-
if resp:
685-
self.logger.debug(f"Total of records returned {len(resp):d}")
690+
resp_parsed = parse_result_attributes(resp)
691+
self.logger.debug(f"Total of records returned {len(resp):d}")
686692

687-
for item in resp:
688-
if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True:
689-
continue
690-
name = ""
693+
if self.args.groups:
694+
if not resp_parsed:
695+
self.logger.fail(f"Group {self.args.groups} not found")
696+
elif not resp_parsed[0]:
697+
self.logger.fail(f"Group {self.args.groups} has no members")
698+
else:
699+
# Fix if group has only one member
700+
if not isinstance(resp_parsed[0]["member"], list):
701+
resp_parsed[0]["member"] = [resp_parsed[0]["member"]]
702+
for user in resp_parsed[0]["member"]:
703+
self.logger.highlight(user.split(",")[0].split("=")[1])
704+
else:
705+
for item in resp_parsed:
691706
try:
692-
for attribute in item["attributes"]:
693-
if str(attribute["type"]) == "name":
694-
name = str(attribute["vals"][0])
695-
self.logger.highlight(f"{name}")
707+
# Fix if group has only one member
708+
if not isinstance(item.get("member", []), list):
709+
item["member"] = [item["member"]]
710+
self.logger.highlight(f"{item['cn']:<40} membercount: {len(item.get('member', []))}")
696711
except Exception as e:
697712
self.logger.debug("Exception:", exc_info=True)
698713
self.logger.debug(f"Skipping item, cannot process due to error {e}")
699-
return
714+
715+
def computers(self):
716+
resp = self.search(f"(sAMAccountType={SAM_MACHINE_ACCOUNT})", ["name"], 0)
717+
resp_parse = parse_result_attributes(resp)
718+
719+
if resp:
720+
self.logger.display(f"Total records returned: {len(resp_parse)}")
721+
for item in resp_parse:
722+
self.logger.highlight(item["name"] + "$")
700723

701724
def dc_list(self):
702725
# Building the search filter

nxc/protocols/ldap/proto_args.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def proto_args(parser, parents):
2222
vgroup.add_argument("--password-not-required", action="store_true", help="Get the list of users with flag PASSWD_NOTREQD")
2323
vgroup.add_argument("--admin-count", action="store_true", help="Get objets that had the value adminCount=1")
2424
vgroup.add_argument("--users", nargs="*", help="Enumerate enabled domain users")
25-
vgroup.add_argument("--groups", action="store_true", help="Enumerate domain groups")
25+
vgroup.add_argument("--groups", nargs="?", const="", help="Enumerate domain groups, if a group is specified than its members are enumerated")
26+
vgroup.add_argument("--computers", action="store_true", help="Enumerate domain computers")
2627
vgroup.add_argument("--dc-list", action="store_true", help="Enumerate Domain Controllers")
2728
vgroup.add_argument("--get-sid", action="store_true", help="Get domain sid")
2829
vgroup.add_argument("--active-users", nargs="*", help="Get Active Domain Users Accounts")

0 commit comments

Comments
 (0)