@@ -122,7 +122,12 @@ def on_login(self, context, connection):
122122 else :
123123 self .context .db .add_credential ("plaintext" , target_domain , target_username , self .newpass )
124124 except Exception as e :
125- context .log .fail (f"SMB-SAMR password change failed: { e } " )
125+ if "STATUS_ACCESS_DENIED" in str (e ):
126+ self .context .log .fail (f"STATUS_ACCESS_DENIED while changing password for user: { target_username } " )
127+ elif "STATUS_NONE_MAPPED" in str (e ):
128+ self .context .log .fail (f"User '{ target_username } ' not found or not resolvable" )
129+ else :
130+ context .log .fail (f"SMB-SAMR password change failed: { e } " )
126131 finally :
127132 self .dce .disconnect ()
128133
@@ -145,13 +150,9 @@ def _smb_samr_change(self, context, connection, target_username, target_domain,
145150 context .log .success (f"Successfully changed password for { target_username } " )
146151
147152 def _hSamrOpenUser (self , connection , username ):
148- """Get handle to the user object"""
149- try :
150- # Connect to the target server and retrieve handles
151- server_handle = samr .hSamrConnect (self .dce , connection .host + "\x00 " )["ServerHandle" ]
152- domain_sid = samr .hSamrLookupDomainInSamServer (self .dce , server_handle , connection .domain )["DomainId" ]
153- domain_handle = samr .hSamrOpenDomain (self .dce , server_handle , domainId = domain_sid )["DomainHandle" ]
154- user_rid = samr .hSamrLookupNamesInDomain (self .dce , domain_handle , (username ,))["RelativeIds" ]["Element" ][0 ]
155- return samr .hSamrOpenUser (self .dce , domain_handle , userId = user_rid )["UserHandle" ]
156- except Exception as e :
157- self .context .log .fail (f"Failed to open user: { e } " )
153+ """Connect to the target server and retrieve the user handle"""
154+ server_handle = samr .hSamrConnect (self .dce , connection .host + "\x00 " )["ServerHandle" ]
155+ domain_sid = samr .hSamrLookupDomainInSamServer (self .dce , server_handle , connection .domain )["DomainId" ]
156+ domain_handle = samr .hSamrOpenDomain (self .dce , server_handle , domainId = domain_sid )["DomainHandle" ]
157+ user_rid = samr .hSamrLookupNamesInDomain (self .dce , domain_handle , (username ,))["RelativeIds" ]["Element" ][0 ]
158+ return samr .hSamrOpenUser (self .dce , domain_handle , userId = user_rid )["UserHandle" ]
0 commit comments