NetExec icon indicating copy to clipboard operation
NetExec copied to clipboard

NetExec LDAP is using System's DNS

Open bmigette opened this issue 4 months ago • 11 comments

Describe the bug When using NetExec with ldap protocol, netexec is doing some dns resolutions that uses system's DNS and will cause failure. There's numerous case where we should be able to :

  • Specify DNS server manually
  • Or automatically dectect it (assume Domain Conntroller is doing DNS)

Also, the error is misleading. In my particular case, the target IP (172.16.230.10) can be used for LDAP, but because netexec resolved this to a different IP using public DNS, connection failed.

To Reproduce Command: netexec --debug ldap 172.16.230.10 -u myuser -p 'mypass'

Resulted in:

$ netexec --debug ldap 172.16.230.10 -u myuser -p 'mypass'
[16:59:18] DEBUG    PYTHON VERSION: 3.11.7 (main, Dec  8 2023, 14:22:46) [GCC 13.2.0]                                                           netexec.py:89
           DEBUG    RUNNING ON: Linux Release: 6.6.9-amd64                                                                                      netexec.py:90
           DEBUG    Passed args: Namespace(threads=100, timeout=None, jitter=None, no_progress=False, verbose=False, debug=True, version=False, netexec.py:91
                    protocol='ldap', target=['172.16.230.10'], cred_id=[], username=['myuser'], password=['mypass'],
                    ignore_pw_decoding=False, kerberos=False, no_bruteforce=False, continue_on_success=False, use_kcache=False, log=None,
                    aesKey=None, kdcHost=None, gfail_limit=None, ufail_limit=None, fail_limit=None, module=None, module_options=[],
                    list_modules=False, show_module_options=False, server='https', server_host='0.0.0.0', server_port=None,
                    connectback_host=None, hash=[], port=389, no_smb=False, domain=None, local_auth=False, asreproast=None, kerberoasting=None,
                    trusted_for_delegation=False, password_not_required=False, admin_count=False, users=False, groups=False, dc_list=False,
                    get_sid=False, active_users=False, gmsa=False, gmsa_convert_id=None, gmsa_decrypt_lsa=None, bloodhound=False,
                    nameserver='172.16.230.10', collection=None)
           DEBUG    Protocol: ldap                                                                                                             netexec.py:145
           DEBUG    Protocol Path: /home/babadmin/.local/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/protocols/ldap.py                 netexec.py:148
           DEBUG    Protocol DB Path: /home/babadmin/.local/pipx/venvs/netexec/lib/python3.11/site-packages/nxc/protocols/ldap/database.py     netexec.py:150
[16:59:19] DEBUG    Protocol Object: <class 'protocol.ldap'>                                                                                   netexec.py:153
           DEBUG    Protocol DB Object: <class 'protocol.database'>                                                                            netexec.py:155
           DEBUG    DB Path: /home/babadmin/.nxc/workspaces/default/ldap.db                                                                    netexec.py:158
           DEBUG    Using selector: EpollSelector                                                                                       selector_events.py:54
           DEBUG    Creating ThreadPoolExecutor                                                                                                 netexec.py:47
           DEBUG    Creating thread for <class 'protocol.ldap'>                                                                                 netexec.py:50
           INFO     Socket info: host=172.16.230.10, hostname=172.16.230.10, kerberos=False, ipv6=False, link-local ipv6=False              connection.py:103
           DEBUG    Kicking off proto_flow                                                                                                  connection.py:163
           DEBUG    Creating smbv1 connection object                                                                                              ldap.py:637
           DEBUG    Error creating SMBv1 connection to 172.16.230.10: Error while reading from remote                                             ldap.py:648
           DEBUG    Creating smbv3 connection object                                                                                              ldap.py:653
           DEBUG    SMBv3 Connection successful                                                                                                   ldap.py:658
           DEBUG    Created connection object                                                                                               connection.py:166
           INFO     Connecting to ldap://172.16.230.10 with no baseDN                                                                             ldap.py:166
           DEBUG    Connecting to 172.16.230.10, port 389, SSL False                                                                              ldap.py:107
           DEBUG    ldap_connection: <impacket.ldap.ldap.LDAPConnection object at 0x7f8904022910>                                                 ldap.py:170
           DEBUG    Target: DC01.mydomain.com; target_domain: mydomain.com; base_dn: DC=mydomain,DC=com                                              ldap.py:208
           DEBUG    Creating smbv1 connection object                                                                                              ldap.py:637
           DEBUG    Error creating SMBv1 connection to 172.16.230.10: Error while reading from remote                                             ldap.py:648
           DEBUG    Creating smbv3 connection object                                                                                              ldap.py:653
           DEBUG    SMBv3 Connection successful                                                                                                   ldap.py:658
           DEBUG    Printing host info for LDAP                                                                                                   ldap.py:295
SMB         172.16.230.10   445    DC01             [*] Windows Server 2022 Build 20348 x64 (name:DC01) (domain:mydomain.com) (signing:True) (SMBv1:False)
           INFO     SMB         172.16.230.10   445    DC01             [*] Windows Server 2022 Build 20348 x64 (name:DC01)                     logger.py:145
                    (domain:mydomain.com) (signing:True) (SMBv1:False)
           DEBUG    Trying to authenticate using plaintext with domain                                                                      connection.py:406
           DEBUG    Connecting to ldap://DC01.mydomain.com - DC=mydomain,DC=com [3]                                                                 ldap.py:481
           DEBUG    Connecting to DC01.mydomain.com, port 389, SSL False                                                                           ldap.py:107
LDAP        172.16.230.10   445    DC01             [-] mydomain.com\myuser:mypass Error connecting to the domain, are you sure LDAP service is running on the target?
Error: [Errno 111] Connection refused
           INFO     LDAP        172.16.230.10   445    DC01             [-] mydomain.com\myuser:mypass Error connecting to the domain, are you logger.py:145
                    sure LDAP service is running on the target?
                    Error: [Errno 111] Connection refused

Expected behavior DNS resolution should use a custom server (like the -ns option for bloodhound), or find the domain DNS automatically. Using System's DNS assume everytime we do a ldap test we need to adjust system's DNS.

Lastly, in the above example, the domain was resolved by public DNS to a public IP that was filtered. The logs never showed any attempt to connect to this public IP and I had to do a TCPDump capture to understand what's going on.

NetExec info

  • OS: Kali Linux
  • Version of nxc: 1.1.0 - nxc4u
  • Installed from: pipx

Additional context None

bmigette avatar Feb 19 '24 16:02 bmigette