Skip to content

LDAP search filters with escaped bytes of 0x80 or higher send the wrong value #2357

Done

Description

@RaphaelFakhri

Configuration

impacket version: master (b35fd9a), also 0.13.x
Python version: 3.13
Target OS: any LDAP server (Active Directory)

Debug output with command line

from impacket.ldap.ldap import LDAPConnection

c = LDAPConnection.__new__(LDAPConnection)
f = c._parseFilter(r'(objectGUID=\a1\00\ff)')
print(bytes(f['equalityMatch']['assertionValue']).hex())
# c2a100c3bf  (expected a100ff)

f = c._parseFilter(r'(cn=Jos\c3\a9)')
print(bytes(f['equalityMatch']['assertionValue']))
# b'Jos\xc3\x83\xc2\xa9'  (expected b'Jos\xc3\xa9')

Description

RFC 4515 defines each \XX escape in a filter value as one octet. LDAPConnection._processLdapString() turns each escape into the code point chr(0xXX). Since #1980, AssertionValue encodes str values as UTF-8, so any escaped byte of 0x80 or higher becomes two bytes on the wire.

As a result, filters on binary attributes such as objectGUID or objectSid (for example (objectGUID=\a1\b2...)) and filters that escape UTF-8 characters (for example (cn=Jos\c3\a9)) return no entries, even though the same filter works with ldapsearch or Get-ADObject -LDAPFilter. Escapes below 0x80, such as \28, \29, \2a and \00, are not affected.

Before #1980, pyasn1's default latin-1 encoding mapped chr(0xXX) back to the original byte, so binary escapes worked but unescaped non-ASCII values did not.

Activity

  1. added
    in review
    on Nov 11, 2026
  2. added
    bug
    and removed
    in review
    on Nov 25, 2026
  3. anadrianmanrique commented on Nov 25, 2026

    @anadrianmanrique
    Collaborator

    fixed at #2358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions