Query Details
let alert_id = "<<<>>>";
let query_period = 1d;
let internet_message_ids = toscalar(
AlertEvidence
| where Timestamp > ago(query_period)
| where AlertId == strcat("dl", alert_id) and EntityType == "MailMessage"
| extend AdditionalFields = todynamic(AdditionalFields)
| summarize make_set(AdditionalFields["InternetMessageId"])// Unix Time
);
CloudAppEvents
| where Timestamp > ago(query_period)
| where ActionType == "AlertTriggered" and tostring(RawEventData["AlertId"]) == alert_id
| extend
AlertId = tostring(RawEventData["AlertId"]),
Data = todynamic(tostring(RawEventData["Data"]))
| extend
UserPrincipalName = tolower(tostring(Data["f3u"])),
Severity = tostring(Data["sev"]),
Workload = tostring(Data["wl"]),
SensitiveInformationContentType = split(tostring(Data["sict"]), ";"),
SensitiveInformationTypeMatchInfo = split(tostring(Data["sitmi"]), ";")
| where Workload == "MicrosoftTeams" and tostring(RawEventData["Category"]) == "DataLossPrevention"
| project
Timestamp,
Application,
ActionType,
AlertId,
UserPrincipalName,
Severity,
Workload,
SensitiveInformationContentType,
SensitiveInformationTypeMatchInfo,
AlertTriggered_RawEventData = RawEventData,
AlertTriggered_ReportId = ReportId,
InternetMessageIds = internet_message_ids// Unix Time
| lookup kind=leftouter (
CloudAppEvents
| where Timestamp > ago(query_period)
| where ActionType == "AlertEntityGenerated" and tostring(RawEventData["AlertId"]) == alert_id
| extend
AlertId = tostring(RawEventData["AlertId"]),
EntityType = tostring(RawEventData["EntityType"]),
Data = todynamic(tostring(RawEventData["Data"]))
| where EntityType == "DlpRuleMatch"
| extend
PolicyId = coalesce(tostring(Data["cid"]), tostring(Data["dpid"])),
PolicyName = tostring(Data["dpn"]),
ManagementRuleId = tostring(Data["dmrid"]),
RuleId = tostring(Data["drid"]),
RuleName = tostring(Data["drn"]),
ProtectionActions = split(tostring(Data["dact"]), ", "),
ObjectName = tostring(Data["von"]),
DMC = split(tostring(Data["dmc"]), ","),
SenderFromAddress = tostring(Data["mfrm"]),
RecipientEmailAddress = split(tostring(Data["to"]), ",")
| project
AlertId,
PolicyId,
PolicyName,
ManagementRuleId,
RuleId,
RuleName,
DMC,
ProtectionActions,
ObjectName,
SenderFromAddress,
RecipientEmailAddress,
AlertEntityGenerated_DlpRuleMatch_RawEventData = RawEventData,
AlertEntityGenerated_DlpRuleMatch_ReportId = ReportId
) on AlertId
| project-away AlertId1
This KQL query is designed to retrieve and correlate data related to a specific alert in Microsoft Teams, focusing on Data Loss Prevention (DLP) events. Here's a simplified breakdown:
Set Variables:
alert_id: A specific alert identifier.query_period: The time range for the query, set to 1 day.Retrieve Internet Message IDs:
AlertEvidence table, find all MailMessage entities related to the given alert_id within the last day.InternetMessageId from the AdditionalFields.Retrieve Alert Triggered Events:
CloudAppEvents table, find all events where an alert was triggered (ActionType == "AlertTriggered") within the last day.alert_id.UserPrincipalName, Severity, Workload, and sensitive information details.MicrosoftTeams and the category is DataLossPrevention.Join with Alert Entity Generated Events:
CloudAppEvents table, find all events where an alert entity was generated (ActionType == "AlertEntityGenerated") within the last day.alert_id and ensure the entity type is DlpRuleMatch.PolicyId, PolicyName, RuleId, RuleName, and other related information.AlertId.Project Final Output:
InternetMessageIds.In summary, this query collects and correlates detailed information about a specific DLP alert in Microsoft Teams, including triggered events and related DLP rule matches, within the last day.

Jose Sebastián Canós
Released: September 19, 2024
Tables
Keywords
Operators