KQL Queries
This is a home for KQL queries that I find useful in investigations and other scenarios.
Using Results from One Table in Another
Assign the results of the SecurityAlert
table to the variable names
, then close the query with a ;
Write the query for the table that will use the names
variable directly below it.
Advanced-Joined Rules
Search for Mailboxes of Users who Hit Malicious Links
The following query identifies users who have visited a malicious URL and then checks whether their mailboxes have had any rule modifications. Threat actors commonly use this tactic to maintain access for phishing and credential harvesting attacks while preventing the original target from seeing responses to the phishing email.
Emails
Search Malicious URLs in Emails
The below query will search the EmailUrlInfo table for any emails that contain the malicious URL. This will retrieve the NetworkMessageId from the email, and then feeds that in to the EmailEvents table, where it pulls the email based on the NetworkMessageID.
join kind=inner (badMail) on NetworkMessageId
→ Brings in the identified URL fromEmailUrlInfo
, making it more informative.project IdentifiedUrl
→ Displays the detected URL along with email details.
Last updated