11from impacket .ldap import ldapasn1 as ldapasn1_impacket
22from impacket .ldap import ldap as ldap_impacket
33from nxc .logger import nxc_logger
4+ from nxc .parsers .ldap_results import parse_result_attributes
45
56
67class NXCModule :
@@ -20,7 +21,7 @@ def options(self, context, module_options):
2021 """
2122
2223 def on_login (self , context , connection ):
23- searchFilter = "(objectclass=user )"
24+ searchFilter = "(userPassword=* )"
2425
2526 try :
2627 context .log .debug (f"Search Filter={ searchFilter } " )
@@ -37,27 +38,10 @@ def on_login(self, context, connection):
3738 nxc_logger .debug (e )
3839 return False
3940
40- answers = []
41- context .log .debug (f"Total of records returned { len (resp )} " )
42- for item in resp :
43- if isinstance (item , ldapasn1_impacket .SearchResultEntry ) is not True :
44- continue
45- sAMAccountName = ""
46- userPassword = []
47- try :
48- for attribute in item ["attributes" ]:
49- if str (attribute ["type" ]) == "sAMAccountName" :
50- sAMAccountName = str (attribute ["vals" ][0 ])
51- elif str (attribute ["type" ]) == "userPassword" :
52- userPassword = [str (i ) for i in attribute ["vals" ]]
53- if sAMAccountName != "" and len (userPassword ) > 0 :
54- answers .append ([sAMAccountName , userPassword ])
55- except Exception as e :
56- context .log .debug ("Exception:" , exc_info = True )
57- context .log .debug (f"Skipping item, cannot process due to error { e !s} " )
58- if len (answers ) > 0 :
41+ if resp :
42+ resp_parsed = parse_result_attributes (resp )
5943 context .log .success ("Found following users: " )
60- for answer in answers :
61- context .log .highlight (f"User: { answer [ 0 ]} userPassword : { answer [ 1 ]} " )
44+ for user in resp_parsed :
45+ context .log .highlight (f"User: { user [ 'sAMAccountName' ]} unixUserPassword : { user [ 'userPassword' ]} " )
6246 else :
63- context .log .fail ("No userPassword Found" )
47+ context .log .fail ("No unixUserPassword Found" )
0 commit comments