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

PR: ntlmrelayx.py ignores URL parameters provided in targets #1910 #1911

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions impacket/examples/ntlmrelayx/clients/httprelayclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def initConnection(self):
self.path = '/'
else:
self.path = self.target.path
self.query = self.target.query
return True

def sendNegotiate(self,negotiateMessage):
#Check if server wants auth
self.session.request('GET', self.path)
if self.query:
self.session.request('GET', self.path + '?' + self.query)
else:
self.session.request('GET', self.path)
res = self.session.getresponse()
res.read()
if res.status != 401:
Expand All @@ -79,7 +83,10 @@ def sendNegotiate(self,negotiateMessage):
#Negotiate auth
negotiate = base64.b64encode(negotiateMessage).decode("ascii")
headers = {'Authorization':'%s %s' % (self.authenticationMethod, negotiate)}
self.session.request('GET', self.path ,headers=headers)
if self.query:
self.session.request('GET', self.path + '?' + self.query, headers=headers)
else:
self.session.request('GET', self.path, headers=headers)
res = self.session.getresponse()
res.read()
try:
Expand All @@ -100,7 +107,10 @@ def sendAuth(self, authenticateMessageBlob, serverChallenge=None):
token = authenticateMessageBlob
auth = base64.b64encode(token).decode("ascii")
headers = {'Authorization':'%s %s' % (self.authenticationMethod, auth)}
self.session.request('GET', self.path,headers=headers)
if self.query:
self.session.request('GET', self.path + '?' + self.query, headers=headers)
else:
self.session.request('GET', self.path, headers=headers)
res = self.session.getresponse()
if res.status == 401:
return None, STATUS_ACCESS_DENIED
Expand Down Expand Up @@ -132,6 +142,7 @@ def initConnection(self):
self.path = '/'
else:
self.path = self.target.path
self.query = self.target.query
try:
uv_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
self.session = HTTPSConnection(self.targetHost,self.targetPort, context=uv_context)
Expand Down
5 changes: 4 additions & 1 deletion impacket/examples/ntlmrelayx/utils/targetsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def registerTarget(self, target, gotRelay = False, gotUsername = None):
# We have data about the username we relayed the connection for,
# for a target that didn't have username specified.
# Let's log it
newTarget = urlparse('%s://%s@%s%s' % (target.scheme, gotUsername.replace('/','\\'), target.netloc, target.path))
if target.query:
newTarget = urlparse('%s://%s@%s%s?%s' % (target.scheme, gotUsername.replace('/','\\'), target.netloc, target.path, target.query))
Comment on lines +120 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetsutils is also used by LDAP and SMB relay clients, afaik target.query is only valid for HTTP targets. the condition must also specify that target.scheme is HTTP/HTTPS

else:
newTarget = urlparse('%s://%s@%s%s' % (target.scheme, gotUsername.replace('/','\\'), target.netloc, target.path))
if gotRelay:
self.finishedAttacks.append(newTarget)
else:
Expand Down