Skip to content
medium severityMicrosoft Defender XDR

Detect LDAP reconnaissance in AD (KQL)

Before moving laterally, attackers map Active Directory — users, groups, computers and trusts — usually over LDAP. Tools like BloodHound and SharpHound generate a burst of LDAP queries from a single account and host. This IdentityQueryEvents query (Defender for Identity) counts LDAP queries per account and host each hour and flags high query volumes or many distinct targets.

It turns a noisy, legitimate-looking protocol into a tunable enumeration signal by focusing on volume and breadth rather than any single query.

The query

IdentityQueryEvents
| where Timestamp > ago(24h)
| where Protocol == "Ldap"
| where isnotempty(QueryTarget)
| summarize
    Queries = count(),
    DistinctTargets = dcount(QueryTarget),
    SampleQueries = make_set(Query, 20)
    by AccountName, DeviceName, bin(Timestamp, 1h)
| where Queries >= 50 or DistinctTargets >= 20
| sort by Queries desc

Line-by-line explanation

  • | where Protocol == "Ldap"

    Scopes to LDAP, the protocol most AD enumeration uses. IdentityQueryEvents also records Samr and Dns, which have their own recon patterns.

  • by AccountName, DeviceName, bin(Timestamp, 1h)

    Groups per account and source host each hour so a burst of enumeration collapses into one row.

  • | where Queries >= 50 or DistinctTargets >= 20

    Flags high query volume or broad targeting — the hallmarks of automated recon rather than an app doing a few lookups.

Required tables and columns

  • ProtocolQuery protocol; Ldap for directory enumeration.
  • QueryThe query text or filter issued, sampled for triage.
  • QueryTargetThe object the query sought; distinct targets measure breadth.
  • AccountNameThe account performing the queries — the subject of the recon.

MITRE ATT&CK mapping

Tuning and false positives

  • Baseline and exclude legitimate heavy LDAP consumers (identity sync, vulnerability scanners, directory-aware apps) by AccountName or DeviceName.
  • Tune the thresholds to your directory size; large tenants need higher counts to stay meaningful.

Limitations

  • Requires Defender for Identity sensors on domain controllers; coverage gaps leave blind spots.
  • Low-and-slow enumeration under the hourly thresholds will not trigger; widen the window to catch it.

References

Last reviewed 2026-11-18.