githubEdit

LDAP (Lightweight Directory Access Protocol) Pentesting

LDAP is a standard protocol designed to maintain and access "directory services" within a network. Default ports are 389 (LDAP), 636 (LDAPS), 3268 (LDAP connection to Global Catalog), 3269 (LDAP connection to Global Catalog over SSL).

Enumeration

# Nmap
nmap --script ldap-brute --script-args ldap.base='"cn=users,dc=cqure,dc=net"' -p 389 <target-ip>
nmap --script ldap-search -p 389 <target-ip>
nmap --script ldap-* -p 389 <target-ip>
nmap --script "ldap* and not brute" -p 389 <target-ip>

# NetExec
# -k: Use Kerberos authentication
netexec ldap <target-ip> -u usernames.txt -k
# --trusted-for-delegation: Enumerate computers and users with the flag `TRUSTED_FOR_DELEGATION`
# reference: https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/useraccountcontrol-manipulate-account-properties#property-flag-descriptions
netexec ldap <target-ip> -u username -p password --trusted-for-delegation

# Users
ldapsearch -x -H ldap://10.0.0.1 -D "username@example.local" -w "password" -b "dc=example,dc=local" "(objectclass=user)" sAMAccountName memberOf
# Groups
ldapsearch -x -H ldap://10.0.0.1 -D "username@example.local" -w "password" -b "dc=example,dc=local" "(objectClass=group)" name member

Dump Active Directory Information

If you have the credential, you can get the Active Directory information via LDAP.

Connect

AD CS (Active Directory Certificate Services)

LAPS (Local Administrator Password Solution)

Pass-Back Attack

Attack against the network devices such as printers. For example, access http://printer.sub.example.com/settings.aspx

Open a listener for connecting back to your local machine.

In your browser, test LDAP settings where you input username and password.

Host Rogue LDAP Server

If we cannot connect back in local machine by netcat, we need to create a rogue LDAP server. Install the dependencies at first.

Configure your own rogue LDAP server by executing the following command.

We need to make your rogue LDAP server to be vulnerable by downgrading the supported authentication mechanism. Create the config file named "config.ldif".

Now we can use the config file to patch the LDAP server.

We can verify that the rogue LDAP server’s configuration has been applied:

For capturing the credentials, run the following command.

In browser, test the printer settings and capture the credentials via tcpdump.

Last updated