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 Sentinel
Microsoft Sentinel
A scalable, cloud-native solution for security information event management and security orchestration automated response. Previously known as Azure Sentinel.
1,021 questions
Microsoft Defender for Endpoint Training
Microsoft Defender for Endpoint Training
Microsoft Defender for Endpoint: A Microsoft unified security platform for preventative protection, postbreach detection, and automated investigation and response. Previously known as Microsoft Defender Advanced Threat Protection.Training: Instruction to develop new skills.
20 questions
{count} votes

Accepted answer
  1. Andrew Blumhardt 9,676 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