Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update httprelayserver.py - re-encode username and domain #1822

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions impacket/examples/ntlmrelayx/servers/httprelayserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ def do_local_auth(self, messageType, token, proxy):
authenticateMessage = ntlm.NTLMAuthChallengeResponse()
authenticateMessage.fromString(token)

if authenticateMessage['flags'] & ntlm.NTLMSSP_NEGOTIATE_UNICODE:
self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('utf-16le'),
if not (authenticateMessage['flags'] & ntlm.NTLMSSP_NEGOTIATE_UNICODE):
authenticateMessage['domain_name'] = authenticateMessage['domain_name'].decode('ascii').encode('utf-16le')
authenticateMessage['user_name'] = authenticateMessage['user_name'].decode('ascii').encode('utf-16le')

self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('utf-16le'),
authenticateMessage['user_name'].decode('utf-16le'))).upper()
else:
self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('ascii'),
authenticateMessage['user_name'].decode('ascii'))).upper()

self.target = self.server.config.target.getTarget(identity = self.authUser)
if self.target is None:
Expand Down Expand Up @@ -440,15 +440,14 @@ def do_relay(self, messageType, token, proxy, content = None):
authenticateMessage = ntlm.NTLMAuthChallengeResponse()
authenticateMessage.fromString(token)

if self.server.config.disableMulti:
if authenticateMessage['flags'] & ntlm.NTLMSSP_NEGOTIATE_UNICODE:
self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('utf-16le'),
authenticateMessage['user_name'].decode('utf-16le'))).upper()
else:
self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('ascii'),
authenticateMessage['user_name'].decode('ascii'))).upper()
if not (authenticateMessage['flags'] & ntlm.NTLMSSP_NEGOTIATE_UNICODE):
authenticateMessage['domain_name'] = authenticateMessage['domain_name'].decode('ascii').encode('utf-16le')
authenticateMessage['user_name'] = authenticateMessage['user_name'].decode('ascii').encode('utf-16le')

self.authUser = ('%s/%s' % (authenticateMessage['domain_name'].decode('utf-16le'),
authenticateMessage['user_name'].decode('utf-16le'))).upper()

target = '%s://%s@%s' % (self.target.scheme, self.authUser.replace("/", '\\'), self.target.netloc)
target = '%s://%s@%s' % (self.target.scheme, self.authUser.replace("/", '\\'), self.target.netloc)

if not self.do_ntlm_auth(token, authenticateMessage):
LOG.error("Authenticating against %s://%s as %s FAILED" % (self.target.scheme, self.target.netloc,
Expand Down
Loading