Kuboid
Open Luck·Kuboid.in

MalDAPTIVE: LDAP Obfuscation, De-obfuscation, and Detection

DEFCONConference5,824 views46:42over 1 year ago

This talk demonstrates various techniques for obfuscating LDAP search filters to evade detection by security monitoring tools. It explores how these obfuscated filters are parsed and interpreted by Active Directory, highlighting the discrepancies between client-side and server-side logging. The researchers introduce a new open-source framework, MalDAPTIVE, designed to parse, enrich, and detect these obfuscated LDAP queries. The presentation includes a live demonstration of the tool and a release of a corpus of obfuscated LDAP examples.

Bypassing LDAP Detection: How MalDAPTIVE Exposes the Gaps in Your Monitoring

TLDR: LDAP search filters are frequently used for internal reconnaissance, yet they are often overlooked by security monitoring tools. Researchers have discovered that these filters can be heavily obfuscated using techniques like bitwise manipulation, OID notation, and logical inversion to bypass detection. The newly released MalDAPTIVE framework provides a way to parse, enrich, and detect these complex, obfuscated queries, giving both red and blue teams a clearer view of what is happening in their Active Directory environments.

Active Directory remains the backbone of most enterprise networks, and LDAP is the primary protocol used to query it. During a red team engagement or a penetration test, the ability to query the directory for users, groups, and service principal names is often the difference between a successful lateral movement and getting caught. While many security teams focus on detecting tools like BloodHound or PowerView, they often miss the underlying LDAP queries that these tools generate. This oversight exists because LDAP search filters are deceptively simple, yet they support a surprising amount of complexity that can be used to hide malicious intent.

The Mechanics of LDAP Obfuscation

LDAP search filters are defined by RFC 4511, and they are far more flexible than most security analysts realize. The core of the problem is that security monitoring tools often rely on simple string matching or basic regular expressions to flag suspicious activity. If a tool is looking for (sAMAccountName=*), it will likely miss a query that uses OID notation or bitwise logic to achieve the exact same result.

The research presented at DEF CON 2024 highlights that obfuscation can be applied to almost every component of an LDAP search request, including the filter, the base object, and the attribute selection. For example, attribute names are case-insensitive, but they can also be represented by their Object Identifier (OID). A query for (name=Domain Admins) can be rewritten using the OID for the name attribute, and you can even prepend zeros to that OID without breaking the query.

(1.2.840.113556.1.4.1=Domain Admins)
(001.2.840.113556.1.4.1=Domain Admins)

These techniques are not just theoretical. They work because the Active Directory server is responsible for parsing and normalizing these queries. If the server can resolve the obfuscated query to a valid object, the query succeeds. The security monitoring tool, however, is often left trying to parse a string that it does not recognize as a known pattern.

Bitwise Manipulation and Logical Inversion

Beyond simple string obfuscation, the research dives into the use of bitwise operators and logical structures. Active Directory attributes like userAccountControl use bitwise flags to represent account status. A common red team technique is to query for accounts that are not disabled. Instead of a straightforward query, an attacker can use bitwise logic to construct a filter that is functionally identical but syntactically unrecognizable to standard detection rules.

Logical inversion is another powerful tool. By using the ! operator, an attacker can negate a filter. When combined with De Morgan's laws, you can create complex, nested filters that are mathematically equivalent to a simple query but look like a mess of parentheses and operators to a human or a naive detection engine.

(&(name=Sabi)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))

The MalDAPTIVE framework addresses this by implementing a custom C# state machine parser. It tokenizes the input string, builds a syntax tree, and then performs a recursive descent to decode and normalize the query. This allows the tool to identify the underlying intent of the query regardless of how it was obfuscated.

Real-World Implications for Pentesters

For a penetration tester, this research is a goldmine. If you are performing an internal assessment, you can use these techniques to test the maturity of the client's security operations center. If your standard reconnaissance queries are being flagged, you now have a roadmap to modify your payloads to evade those specific detections.

The impact of this is significant. Many organizations rely on Microsoft Defender for Identity or similar EDR solutions to monitor for directory-based attacks. While these tools are powerful, they are not infallible. By understanding how the underlying LDAP parser works, you can identify blind spots in the monitoring coverage. During an engagement, you should look for opportunities to use these obfuscation techniques to see if your activity remains hidden in the logs.

A Path Forward for Defenders

Defenders should not rely on static string matching for LDAP queries. Instead, the focus must shift toward parsing and normalization. If your security information and event management (SIEM) system is receiving raw LDAP logs, you need a way to normalize those logs before they hit your detection rules.

The MalDAPTIVE tool provides a blueprint for this. By parsing the query into a structured format, you can write detection rules that look for the intent of the query rather than the syntax. For example, instead of alerting on a specific string, you should alert on any query that attempts to access sensitive attributes like ntSecurityDescriptor or servicePrincipalName, regardless of how the filter is constructed.

The research also underscores the importance of visibility. If you are not logging LDAP queries at the domain controller level, you are essentially blind to this type of reconnaissance. Ensure that you have appropriate auditing enabled for directory service access. While this will generate a high volume of logs, it is the only way to gain the necessary visibility to detect these advanced evasion techniques.

The cat-and-mouse game of detection and evasion is constant. As defenders improve their ability to monitor for standard patterns, attackers will inevitably turn to more complex, obfuscated techniques. By building tools that can parse and understand the full complexity of protocols like LDAP, we can stay one step ahead and ensure that our security controls are actually effective. If you are a researcher or a defender, take the time to look at the MalDAPTIVE repository and experiment with the provided corpus of obfuscated examples. Understanding the language of the directory is the first step toward securing it.

Premium Security Audit

We break your app before they do.

Professional penetration testing and vulnerability assessments by the Kuboid Secure Layer team. Securing your infrastructure at every layer.

Get in Touch
Official Security Partner
kuboid.in