CAPEC-136 - LDAP Injection

An attacker manipulates or crafts an LDAP query for the purpose of undermining the security of the target. Some applications use user input to create LDAP queries that are processed by an LDAP server. For example, a user might provide their username during authentication and the username might be inserted in an LDAP query during the authentication process. An attacker could use this input to inject additional commands into an LDAP query that could disclose sensitive information. For example, entering a * in the aforementioned query might return information about all users on the system. This attack is very similar to an SQL injection attack in that it manipulates a query to gather additional information or coerce a particular return value.

Severity

Likelihood

Confidentiality

Integrity

Availability

  • Attack Methods 1
  • Injection
  • Purposes 2
  • Penetration
  • Exploitation
  • Sec Principles 3
  • Reluctance to Trust
  • Defense in Depth
  • Failing Securely
  • Scopes 9
  • DoS: crash / exit / restart
  • Availability
  • DoS: instability
  • Availability
  • Modify files or directories
  • Integrity
  • Read files or directories
  • Confidentiality
  • Modify application data
  • Integrity
  • Read application data
  • Confidentiality
  • Execute unauthorized code or commands
  • Authorization
  • Gain privileges / assume identity
  • Non-Repudiation
  • Authorization
  • Authentication
  • Accountability
  • Bypass protection mechanism
  • Authorization
  • Access_Control

Medium level:

The target application must accept a string as user input, fail to sanitize characters that have a special meaning in LDAP queries in the user input, and insert the user-supplied string in an LDAP query which is then processed.

Handle All Errors Safely

Never Use Input as Part of a Directive to any Internal Component

Step 1 - Survey application

The attacker takes an inventory of the entry points of the application..

Tecnique ID: 1 - Environment(s) env-Web

Spider web sites for all available links

Tecnique ID: 2 - Environment(s) env-All

Sniff network communications with application using a utility such as WireShark.

Outcome ID: 1

Type: Success

At least one data input to application identified.

Outcome ID: 2

Type: Failure

No inputs to application identified. Note that just because no inputs are identified does not mean that the application will not accept any.



Step 1 - Determine user-controllable input susceptible to LDAP injection

For each user-controllable input that the attacker suspects is vulnerable to LDAP injection, attempt to inject characters that have special meaning in LDAP (such as a single quote character, etc.). The goal is to create a LDAP query with an invalid syntax.

Tecnique ID: 1 - Environment(s) env-Web

Use web browser to inject input through text fields or through HTTP GET parameters

Tecnique ID: 2 - Environment(s) env-Web

Use a web application debugging tool such as Tamper Data, TamperIE, WebScarab,etc. to modify HTTP POST parameters, hidden fields, non-freeform fields, or other HTTP header.

Tecnique ID: 3 - Environment(s) env-Web

Use modified client (modified by reverse engineering) to inject input.

Indicator ID: 1 - Environment(s) env-Web env-Peer2Peer env-CommProtocol env-ClientServer

Type: Negative

Attacker receives normal response from server.

Indicator ID: 2 - Environment(s) env-Web env-CommProtocol env-ClientServer

Type: Positive

Attacker receives an error message from target indicating a problem with the LDAP Query

Indicator ID: 3 - Environment(s) env-Web env-CommProtocol env-ClientServer

Type: Negative

Server sends a specific error message that indicates programmatic parsing of the input data (e.g. NumberFormatException)


Security Control ID: 1

Type: Detective

Search for and alert on unexpected LDAP constructs in application logs, e.g. (email=*)) etc.).

Security Control ID: 2

Type: Preventative

Input validation of user-controlled data before including it in a LDAP query


Outcome ID: 1

Type: Success

At least user controllable data input to application identified.

Outcome ID: 2

Type: Failure

No inputs susceptible to injection into the application were identified..


Step 2 - Try to exploit the LDAP injection vulnerability

After determining that a given input is vulnerable to LDAP Injection, hypothesize what the underlying query looks like. Possibly using a tool, iteratively try to add logic to the query to extract information from the LDAP, or to modify or delete information in the LDAP..

Tecnique ID: 1 - Environment(s) env-Web

Add logic to the LDAP query to change the meaning of that command. Automated tools could be used to generate the LDAP injection strings.

Tecnique ID: 2 - Environment(s) env-Web

Use a web application debugging tool such as Tamper Data, TamperIE, WebScarab,etc. to modify HTTP POST parameters, hidden fields, non-freeform fields, or other HTTP header.

Indicator ID: 1 - Environment(s) env-Web env-Peer2Peer env-CommProtocol env-ClientServer

Type: Positive

Attacker receives normal response from server.

Indicator ID: 2 - Environment(s) env-Web env-CommProtocol env-ClientServer

Type: Positive

Probing via LDAP syntax injection was successful in identifying vulnerable input.

Indicator ID: 3 - Environment(s) env-Web env-CommProtocol env-ClientServer

Type: Negative

Probing via LDAP syntax injection failed in identifying vulnerable input.


Security Control ID: 1

Type: Detective

Search for and alert on unexpected LDAP constructs in application logs, e.g. (email=*)) etc.).

Security Control ID: 2

Type: Preventative

Input validation of user-controlled data before including it in a LDAP query


Outcome ID: 1

Type: Success

Attacker achieves goal of unauthorized information access, etc.

Outcome ID: 2

Type: Failure

Attacker unable to exploit LDAP Injection vulnerability.



Special characters in user-controllable input must be escaped before use by the application.

Custom error pages must be used to handle exceptions such that they do not reveal any information about the architecture of the application or the LDAP structure.

Strong input validation - All user-controllable input must be validated and filtered for illegal characters as well as LDAP content.

Use of custom error pages - Attackers can glean information about the nature of queries from descriptive error messages. Input validation must be coupled with customized error pages that inform about an error without disclosing information about the LDAP or application.