Skip to content

Commit

Permalink
ldap: Add option to specify custom port
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnAndOnlyZenomat committed Nov 25, 2024
1 parent 3ce41be commit 7cf8cba
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions impacket/ldap/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@


class LDAPConnection:
def __init__(self, url, baseDN='', dstIp=None):
def __init__(self, url, baseDN='', dstIp=None, dstPort=None):
"""
LDAPConnection class
Expand All @@ -85,16 +85,21 @@ def __init__(self, url, baseDN='', dstIp=None):
self._baseDN = baseDN
self._dstIp = dstIp

if dstPort is not None and not dstPort.isdigit():
raise LDAPSessionError(errorString="Port is not a valid port: '%s'" % dstPort)
if dstPort is not None and 0 < int(dstPort) < 65535:
raise LDAPSessionError(errorString="Port is not in valid port range: '%s'" % dstPort)

if url.startswith('ldap://'):
self._dstPort = 389
self._dstPort = 389 if dstPort is None else int(dstPort)
self._SSL = False
self._dstHost = url[7:]
elif url.startswith('ldaps://'):
self._dstPort = 636
self._dstPort = 636 if dstPort is None else int(dstPort)
self._SSL = True
self._dstHost = url[8:]
elif url.startswith('gc://'):
self._dstPort = 3268
self._dstPort = 3268 if dstPort is None else int(dstPort)
self._SSL = False
self._dstHost = url[5:]
else:
Expand Down

0 comments on commit 7cf8cba

Please sign in to comment.