Fix custom LDAP port specification and improve scheme handling#1203
Fix custom LDAP port specification and improve scheme handling#1203emilyastranova wants to merge 2 commits intoPennyw0rth:mainfrom
Conversation
|
Hi and thanks for the bug fix PR! Looking at the patch I am kinda not happy that we have to introduce a Regarding the custom port, please contribute this fix to impacket. When that is merged we can just supply the port properly. |
|
Agree with you @NeffIsBack , this is something I have been struggling before with Impacket but I wouldn't monkey patch it for NetExec. I'd rather modify the LDAP logic so that it connects to the submitted port via LDAPS first, then fallback to LDAP in case it didn't work ^^ |
Will do, figured I'd get this created for anyone who needs it now. Impacket merges are... not quick 😆 |
Fair point😁 |
Description
This PR addresses an issue where custom ports specified with
nxc ldap --portwere not being properly respected or passed to the underlying Impacket LDAP connection. Additionally, it allows the user to manually specify protocol scheme (ldapvsldaps) and defaults to LDAPS.Key Changes
impacket.ldap.ldap.LDAPConnectionto support custom ports in the connection URL (ldap://host:portorldaps://host:port), which is not natively supported by Impacket.proto_args.pyto use--schemeinstead of capturing the protocol under a conflictingschemedestination.nxc/protocols/ldap.pylogging statements to use the dynamically computed scheme and port instead of hardcoding protocol names based on standard port numbers.How and why we fixed
I tried to use the
--portoption in an environment where a DC had a custom LDAP port set, not a standard one (no idea why) and realized only the default LDAP and LDAPs ports worked, not ports like1111. I leaned onsocatuntil I managed to write this patch. Much easier after this patch.Type of change
Setup guide for the review
Any target with an LDAP service running on a non-standard port, I used
1111.Testing Performed
Tests run:
Verified that
nxc ldap <ip> --port <custom_port>connects to the correct custom port.Verified that
nxc ldap <ip> --scheme ldapdefaults to connecting to port 389.Verified that
nxc ldap <ip> --scheme ldaps(or the default behavior) defaults to connecting to port 636.Checklist:
tests/e2e_commands.txtfile if necessary