Custom detection rule

Runge, Larry 20 Reputation points
2024-06-07T21:32:24.7433333+00:00

We see that 90% of the SPAM geared toward students comes from fake Gmail accounts. In Advanced Hunting I created a KQL query to find any Gmail account that sent more than 40 emails from the same account I saved it as a Custom Detection Rule.  EmailEvents

| where ingestion_time() > ago(3h)

| where SenderFromDomain == "gmail.com"

| summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), EmailCount = count() by SenderFromAddress, DeliveryLocation ,Subject

| where EmailCount >= 40

| sort by EmailCount

This is working great and after a month of testing/running, I wanted to change this so it would trigger the rule to automatically soft delete the emails found. I added the necessary tables (NetworkMessageId, RecipientEmailAddress), which caused the query to fail.

Below is the updated query: EmailEvents

| where ingestion_time() > ago(3h)

| where SenderFromDomain == "gmail.com"

| summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), EmailCount = count() by SenderFromAddress, DeliveryLocation ,Subject, NetworkMessageId, RecipientEmailAddress

| where EmailCount >= 40

| sort by EmailCount

What am I doing wrong?

Microsoft Security | Microsoft Sentinel
{count} votes

Accepted answer
  1. Andrew Blumhardt 10,051 Reputation points Microsoft Employee
    2024-06-12T12:54:42.1366667+00:00

    Both queries work in my lab. I am using union Email* since I was unsure of the target table. Try this.

    union Email*
    | where ingestion_time() > ago(3h)
    | where SenderFromDomain contains "gmail"
    | summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), EmailCount = count() by SenderFromAddress, DeliveryLocation ,Subject, NetworkMessageId, RecipientEmailAddress
    | where EmailCount >= 40
    | sort by EmailCount
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.