Defender for Identity - LDAP Ping
MDI LDAP Ping
Query
// This query extracts the source, destination, LDAP filter, account referenced in the filter, and results.
IdentityQueryEvents
| where ActionType == "LDAP ping"
| extend AF = parse_json(AdditionalFields)
| extend
SourceDevice = tostring(AF["FROM.DEVICE"]),
DestinationDevice = tostring(AF["TO.DEVICE"]),
ActorDevice = tostring(AF["ACTOR.DEVICE"]),
LDAPFilter = tostring(AF.Filter),
LDAPResultCode = tostring(AF.ResultCode),
IsResultFound = tobool(AF.IsResultFound),
LDAPCount = tolong(AF.Count)
| extend
QueriedUser = extract(@"User=([^)]*)", 1, LDAPFilter),
QueriedHost = extract(@"Host=([^)]*)", 1, LDAPFilter),
QueriedDomain = extract(@"DnsDomain=([^)]*)", 1, LDAPFilter)
| project
Timestamp,
SourceDevice,
DestinationDevice,
QueriedUser,
QueriedHost,
QueriedDomain,
LDAPResultCode,
IsResultFound,
LDAPCount,
LDAPFilter
| order by Timestamp desc
// Now that we know AdditionalFields.Filter contains the requested username, we can look for sources testing many different usernames.
IdentityQueryEvents
| where ActionType == "LDAP ping"
| extend AF = parse_json(AdditionalFields)
| extend
SourceDevice = tostring(AF["FROM.DEVICE"]),
DestinationDevice = tostring(AF["TO.DEVICE"]),
LDAPFilter = tostring(AF.Filter),
IsResultFound = tobool(AF.IsResultFound)
| extend QueriedUser = extract(@"User=([^)]*)", 1, LDAPFilter)
| where isnotempty(QueriedUser)
| summarize
TotalRequests = count(),
UniqueUsers = dcount(QueriedUser),
UsersQueried = make_set(QueriedUser, 100),
SuccessfulResults = countif(IsResultFound == true),
UnsuccessfulResults = countif(IsResultFound == false)
by SourceDevice, DestinationDevice, bin(Timestamp, 15m)
| where UniqueUsers > 5
| order by UniqueUsers descAbout this query
Explanation
This query is designed for threat hunting using Microsoft Defender for Identity. It focuses on LDAP ping activities, which involve querying user, host, or domain information. The query has two main parts:
-
Detailed Reporting: The first part of the query extracts detailed information about LDAP ping activities. It identifies the source and destination devices, the user, host, or domain being queried, and the results of these queries. This helps in understanding which devices are involved and what information is being requested.
-
Summary of Suspicious Activity: The second part summarizes instances where a source device queries more than five different usernames within a 15-minute window. This behavior might indicate an attempt to enumerate domain accounts, which could be a precursor to malicious activities. However, it could also be legitimate administrative or diagnostic activity.
The query uses the IdentityQueryEvents table from Microsoft Defender XDR to gather data and applies filters to identify potentially suspicious patterns. It also provides guidance on how to interpret the results, emphasizing the need to verify the legitimacy of the activity before concluding it's malicious.