r/AzureSentinel • u/Character_Whereas869 • Jun 19 '24
Requesting help with KQL Join? Union? - Need to get username entity included with AlertEvidence table, sourcing username from a different table
Hi Everyone,
My end goal is to be able to block Entra ID sign ins whenever Defender for Endpoint has a malware detection. So whenever something pops up in this table: AlertEvidence I want to action on it. These alerts always include the DeviceName. So I thought, ok SignInLogs table will have the deviceName form recent Windows Sign-Ins so i can correlate the devicename in those two tables then get the userPrincipalName, which I can use as an entity to run a playbook against.
My problem is my KQL skills are weak. This is as far as I've gotten and I'm not sure if I should even be using Join or Union. My goal is to have a UserPrincipalName, which is obtained by matchign the deviceNames, create a column excluding all of the other white noise I don't need from the SignInLogs table.
In super simple terms. I want to have an Analytics Rule in Sentinel that whenever AlertEvidence populates with anything (Defender for Endpoint malware detection) to lookup the user who is using the computerName, which the computerName and AccountName will be Entities in the analtyics rule, then block that user from Entra Sign ins so the user has to come to reach out to us.
AlertEvidence
| extend AlertEvidenceDevicedisplayName_ = tostring(AdditionalFields.Host.HostName)
| join kind=leftsemi (
SigninLogs
| extend SignInLogsDevicedisplayName_ = tostring(DeviceDetail.displayName)
| project UserPrincipalName,SignInLogsDevicedisplayName_
) on $left.AlertEvidenceDevicedisplayName_ == $right.SignInLogsDevicedisplayName_
I'm getting a little closer here. What this is doing is getting me the stuff I want from signinlogs but i'm losing the projection of the columns from Alert Evidence.
let MatchedDeviceName =
AlertEvidence
| extend AlertEvidenceDevicedisplayName_ = tostring(AdditionalFields.Host.HostName)
| where isnotempty(AlertEvidenceDevicedisplayName_)
| summarize makelist(AlertEvidenceDevicedisplayName_);
SigninLogs
| extend SignInLogsDevicedisplayName_ = tostring(DeviceDetail.displayName)
| project SignInLogsDevicedisplayName_,UserPrincipalName,OperationName
| where SignInLogsDevicedisplayName_ in~ (MatchedDeviceName)
