Skip to content

Commit b7b454e

Browse files
authored
Update ldap.py
Signed-off-by: termanix <50464194+termanix@users.noreply.github.com>
1 parent b8dfb52 commit b7b454e

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,32 @@ def resolve_and_display_hostname(name, domain_name=None):
848848
self.logger.display(f"Skipping non-Active Directory trust '{trust_name}' with type: {trust_type_text} and direction: {direction_text}")
849849
self.logger.info("Domain Controller enumeration complete.")
850850

851+
def active_users(self):
852+
if len(self.args.active_users) > 0:
853+
self.logger.debug(f"Dumping users: {', '.join(self.args.active_users)}")
854+
search_filter = f"(|{''.join(f'(sAMAccountName={user})' for user in self.args.active_users)})"
855+
else:
856+
self.logger.debug("Trying to dump all users")
857+
search_filter = "(sAMAccountType=805306368)"
858+
859+
# Default to these attributes to mirror the SMB --users functionality
860+
request_attributes = ["sAMAccountName", "description", "badPwdCount", "pwdLastSet", "userAccountControl"]
861+
resp = self.search(search_filter, request_attributes, sizeLimit=0)
862+
863+
if resp:
864+
all_users = parse_result_attributes(resp)
865+
# Filter disabled users (ignore accounts without userAccountControl value)
866+
active_users = [user for user in all_users if not (int(user.get("userAccountControl", UF_ACCOUNTDISABLE)) & UF_ACCOUNTDISABLE)]
867+
868+
self.logger.display(f"Total records returned: {len(all_users)}, total {len(all_users) - len(active_users):d} user(s) disabled")
869+
self.logger.highlight(f"{'-Username-':<30}{'-Last PW Set-':<20}{'-BadPW-':<9}{'-Description-':<60}")
870+
871+
for user in active_users:
872+
pwd_last_set = user.get("pwdLastSet", "")
873+
if pwd_last_set:
874+
pwd_last_set = "<never>" if pwd_last_set == "0" else datetime.fromtimestamp(self.getUnixTime(int(pwd_last_set))).strftime("%Y-%m-%d %H:%M:%S")
875+
self.logger.highlight(f"{user.get('sAMAccountName', ''):<30}{pwd_last_set:<20}{user.get('badPwdCount', ''):<9}{user.get('description', '')}")
876+
851877
def asreproast(self):
852878
if self.password == "" and self.nthash == "" and not self.kerberos:
853879
return False

0 commit comments

Comments
 (0)