LDAP Injection




LDAP is the Lightweight Directory Access Protocol (LDAP) is a directory service protocol that runs on a layer above the TCP/IP stack. It provides a mechanism used to connect to, search, and modify Internet directories.
The LDAP directory service is based on a client-server model. The function of LDAP is to enable access to an existing directory "Microsoft".

The major operations can be performed by LDAP :

  • Add : add new data.
  • Bind : Authenticate (Use LDAPS over port 636 not 389)
  • Delete : Delete data.
  • Search and Compare.
  • Unbind : close the connection.
LDAP injection is similar in principle to SQL injection attack, the main objectives of LDAP injection to exploit the web application vulnerabilities in order to exfiltrate login names of users as well as users' information. This step is an important step prior to privilege escalation attack.
Let us suppose that ABC company had an application called Rocky :). IT team have integrated the Rocky app with existing AD through LDAP which allowing the internal user in the company to access the application by their AD login names but the problem here is that developers didn't pay attention to the code quality or didn't sanitize username field which led to LDAP injection vulnerability.

Simple Example of LDAP injections :
  • Original Query: https://www.Rocky.ABC.com/loginsearch.aspx?name=Mubarak 
  • Injected Query: https://www.Rocky.ABC.com/loginsearch.aspx?name=*
If the Rocky application has LDAP injection vulnerability, it will display all of the users' attributes, depending on the permissions of the LDAP user.

The Attackers mostly use a trial-and-error approach to reach the right query, and they use the below parameters in LDAP queries :
  • & = Boolean AND
  • | = Boolean OR 
  • ! = Boolean NOT
  • "=" = Equals
  • "~ =" = Approx
  • > = Greater than
  • < = Less than
  • * = Any character
  • () = Grouping parenthesis

Prevention :

You can refer to OWASP to find primary defenses against LDAP injection, Please visit the latest/updated LDAP Injection Prevention Cheat Sheet on below URL:

https://cheatsheetseries.owasp.org/cheatsheets/LDAP_Injection_Prevention_Cheat_Sheet.html




    Comments

    Popular posts from this blog

    How to Configure Azure MFA with Exchange Server 2013 and ADFS 2012 R2

    How to exclude certain users from MFA in ADFS 3.0