Skip to content

Fails to Forward Requests via SOCKS5 Proxy — “Can't contact LDAP server” Error #3

@camlischke1

Description

@camlischke1

I'm running LDAPx locally attempting to forward LDAP queries to a domain controller via a SOCKS5 proxy. The SOCKS proxy is listening on 127.0.0.1:30006 and tunnels traffic through an SSH connection to a machine which can reach the target domain controller.

Here's how I run LDAPx:

> ldapx -t 172.31.79.105 -l :11389 -F 5 -R 5 -N --socks socks5://127.0.0.1:30006
2025/09/23 15:58:05 [+] LDAP Proxy listening on ':11389', forwarding to '172.31.79.105:389' (T) via 'socks5://127.0.0.1:30006'
2025/09/23 15:58:05 [+] BaseDNMiddlewares: []
2025/09/23 15:58:05 [+] FilterMiddlewares: []
2025/09/23 15:58:05 [+] AttrListMiddlewares: []
2025/09/23 15:58:05 [+] AttrEntriesMiddlewares: []

2025/09/23 15:58:12 Failed to connect to target LDAP server: server does not respond properly

And here's a sample search query routed through the LDAPx server running on port 11389

> ldapsearch -H ldap://127.0.0.1:11389 -x -D "CN=Administrator,CN=Users,DC=cam,DC=com" -W -b "CN=Users,DC=cam,DC=com" -d 5
ldap_url_parse_ext(ldap://127.0.0.1:11389)
ldap_create
ldap_url_parse_ext(ldap://127.0.0.1:11389/??base)
Enter LDAP Password: 
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP 127.0.0.1:11389
ldap_new_socket: 3
ldap_prepare_socket: 3
ldap_connect_to_host: Trying 127.0.0.1:11389
ldap_pvt_connect: fd: 3 tm: -1 async: 0
attempting to connect: 
connect success
ldap_open_defconn: successful
ldap_send_server_request
ber_scanf fmt ({it) ber:
ber_scanf fmt ({i) ber:
ber_flush2: 85 bytes to sd 3
ldap_result ld 0x5a84a12afb90 msgid 1
wait4msg ld 0x5a84a12afb90 msgid 1 (infinite timeout)
wait4msg continue ld 0x5a84a12afb90 msgid 1 all 1
** ld 0x5a84a12afb90 Connections:
* host: 127.0.0.1  port: 11389  (default)
* from: IP=127.0.0.1:49524
  refcnt: 2  status: Connected
  last used: Tue Sep 23 15:58:12 2025


** ld 0x5a84a12afb90 Outstanding Requests:
 * msgid 1,  origid 1, status InProgress
   outstanding referrals 0, parent count 0
  ld 0x5a84a12afb90 request count 1 (abandoned 0)
** ld 0x5a84a12afb90 Response Queue:
   Empty
  ld 0x5a84a12afb90 response count 0
ldap_chkResponseList ld 0x5a84a12afb90 msgid 1 all 1
ldap_chkResponseList returns ld 0x5a84a12afb90 NULL
ldap_int_select
read1msg: ld 0x5a84a12afb90 msgid 1 all 1
ber_get_next
ldap_err2string
ldap_result: Can't contact LDAP server (-1)
ldap_do_free_request: asked to free lr 0x5a84a12b0180 msgid 1 refcnt 0
ldap_free_connection 1 1
ldap_free_connection: actually freed

When I don't use LDAPx at all and instead configure proxychains paired with the above ldapsearch query, works fine.

When I try to use proxychains with ldapx instead of the native --socks option, the connection times out.

What I’ve Tried:

  • Verified that the SOCKS proxy is reachable and working.
  • Verified that bypassing ldapx completely and just using proxychains ldapsearch query works fine.
  • Confirmed that the LDAP proxy is listening and accepting connections.
  • Tried both "127.0.0.1:30006" and "socks5://127.0.0.1:30006" as the socksServer string.
  • Ensured that the domain controller supports plain LDAP on port 389 (not LDAPS).

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions