LDAP Injection
Swapnil Jain
Date: 28 April 2020
#Who Am I
● Security Analyst
● Twitter @swapnil_jn
Overview
● LDAP Injection
● Authentication Bypass
● Demo
● Impact
● Securing Applications against LDAP Injection
LDAP Injection
The Lightweight Directory Access Protocol(LDAP) is used to store
information about users hosts, and many other objects.
LDAP injection is a type of attack on a web application where attackers
place code in a user input field in an attempt to gain unauthorized access
or information.
Basic LDAP Syntax
Common Operators:
● “=” (equal to)
● & (logical and)
● | (logical or)
● ! (logical not)
● * (wildcard)
Filter:
● (cn=sam)
● (cn=s*)
● (|(cn=s*)(cn=t*))
● (&(cn=s*)(sn=*d))
Normal Working
(&(cn=admin)(passwd=secret))
LDAP Server
Admin authenticated
Authentication Bypass
Username: admin)(&)),
Password: ignored
Web
Server
LDAP
Server
Directory Search
AdminSet Cookie:
PHPSESSIONID=admin
Test Case
● <input type="text" size=20
name="name">Enter the
Username to search for</input>
● Searchfilter="(cn="+name+")"
admin)(|(password=*) (cn=admin)(|(password=*) )
Authentication Bypass (Normal Request)
Payload Creation
Original Request :
http://10.90.100.50/ldap_lab/ldap/example2.php?name=hacker&password
=hacker
Payload : name=hacker)(cn=*))%00
Changed request:
http://10.90.100.50/ldap_lab/ldap/example2.php?name=hacker)(cn=*))%0
0&password=hacker
Authentication Bypass(Contd.)
Information Disclosure
Information Disclosure(Contd.)
Impact
● Authentication bypass
● Privilege escalation
● Information disclosure
Countermeasures
● LDAP special characters are safely escaped, including at least ( ) ! | & *
● Use Frameworks that Automatically Protect from LDAP Injection
○ LINQ to Active Directory provides LDAP encoding when building
LDAP queries.
● Least privilege
Thank You

LDAP Injection