Detection rules › Kusto

Malicious BEC Inbox Rule

Severity
medium
Time window
1d
Group by
ClientIPAddress, Keyword, OfficeObjectId, Operation, OriginatingServer, ResultStatus, RuleDetail, UserId
Source
github.com/Azure/Azure-Sentinel

'Often times after the initial compromise in a BEC attack the attackers create inbox rules to delete emails that contain certain keywords related to their BEC attack. This is done so as to limit ability to warn compromised users that they've been compromised.

MITRE ATT&CK coverage

Event coverage

Rules detecting the same action

Other rules on this platform that filter on the same API call or operation.

Rule body kusto

id: 8ac77493-3cae-4840-8634-15fb23f8fb68
name: Malicious BEC Inbox Rule
description: |
  'Often times after the initial compromise in a BEC attack the attackers create inbox rules to delete emails that contain certain keywords related to their BEC attack.
   This is done so as to limit ability to warn compromised users that they've been compromised. 
severity: Medium
requiredDataConnectors:
  - connectorId: Office365
    dataTypes:
      - OfficeActivity
queryFrequency: 1d
queryPeriod: 1d
triggerOperator: gt
triggerThreshold: 0
tactics:
  - Persistence
  - DefenseEvasion
relevantTechniques:
  - T1098
  - T1078
tags:
  - BEC
query: |
 let BEC_Keywords = dynamic([ 'invoice','payment','paycheck','transfer','bank statement','bank details','closing','funds','bank account','account details','remittance','purchase','deposit',"PO#","Zahlung","Rechnung","Paiement", "virement bancaire","Bankuberweisung",'hacked','phishing']);
 OfficeActivity
 | where Operation =~ "New-InboxRule"
 | where Parameters has "Deleted Items" or Parameters has "Junk Email"  or Parameters has "DeleteMessage"
 | extend Events=todynamic(Parameters)
 | parse Events  with * "SubjectContainsWords" SubjectContainsWords '}'*
 | parse Events  with * "BodyContainsWords" BodyContainsWords '}'*
 | parse Events  with * "SubjectOrBodyContainsWords" SubjectOrBodyContainsWords '}'*
 | where SubjectContainsWords has_any (BEC_Keywords)
  or BodyContainsWords has_any (BEC_Keywords)
  or SubjectOrBodyContainsWords has_any (BEC_Keywords)
 | extend ClientIPAddress = case( ClientIP has ".", tostring(split(ClientIP,":")[0]), ClientIP has "[", tostring(trim_start(@'[[]',tostring(split(ClientIP,"]")[0]))), ClientIP )
 | extend Keyword = iff(isnotempty(SubjectContainsWords), SubjectContainsWords, (iff(isnotempty(BodyContainsWords),BodyContainsWords,SubjectOrBodyContainsWords )))
 | extend RuleDetail = case(OfficeObjectId contains '/' , tostring(split(OfficeObjectId, '/')[-1]) , tostring(split(OfficeObjectId, '\\')[-1]))
 | summarize count(), StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated) by  Operation, UserId, ClientIPAddress, ResultStatus, Keyword, OriginatingServer, OfficeObjectId, RuleDetail
 | extend UserName = split(UserId, '@')[0], DomainName = split(UserId, '@')[1]
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: FullName
        columnName: UserId
      - identifier: Name
        columnName: UserName
      - identifier: UPNSuffix
        columnName: DomainName
  - entityType: IP
    fieldMappings:
      - identifier: Address
        columnName: ClientIPAddress
version: 1.0.2
kind: Scheduled

Stages and Predicates

Let binding: BEC_Keywords

let BEC_Keywords = dynamic([ 'invoice','payment','paycheck','transfer','bank statement','bank details','closing','funds','bank account','account details','remittance','purchase','deposit',"PO#","Zahlung","Rechnung","Paiement", "virement bancaire","Bankuberweisung",'hacked','phishing']);

Stage 1: source

OfficeActivity

Stage 2: where

| where Operation =~ "New-InboxRule"

Stage 3: where

| where Parameters has "Deleted Items" or Parameters has "Junk Email"  or Parameters has "DeleteMessage"

Stage 4: extend

| extend Events=todynamic(Parameters)

Stage 5: parse

| parse Events  with * "SubjectContainsWords" SubjectContainsWords '}'*

Stage 6: parse

| parse Events  with * "BodyContainsWords" BodyContainsWords '}'*

Stage 7: parse

| parse Events  with * "SubjectOrBodyContainsWords" SubjectOrBodyContainsWords '}'*

Stage 8: where

| where SubjectContainsWords has_any (BEC_Keywords)
 or BodyContainsWords has_any (BEC_Keywords)
 or SubjectOrBodyContainsWords has_any (BEC_Keywords)

References BEC_Keywords (defined above).

Stage 9: extend (3 consecutive steps)

| extend ClientIPAddress = case( ClientIP has ".", tostring(split(ClientIP,":")[0]), ClientIP has "[", tostring(trim_start(@'[[]',tostring(split(ClientIP,"]")[0]))), ClientIP )
| extend Keyword = iff(isnotempty(SubjectContainsWords), SubjectContainsWords, (iff(isnotempty(BodyContainsWords),BodyContainsWords,SubjectOrBodyContainsWords )))
| extend RuleDetail = case(OfficeObjectId contains '/' , tostring(split(OfficeObjectId, '/')[-1]) , tostring(split(OfficeObjectId, '\\')[-1]))
ClientIPAddress =
ifClientIP has "."tostring(split(ClientIP, ":")[0])
elifClientIP has "["tostring(trim_start(@'[[]', tostring(split(ClientIP, "]")[0])))
elseClientIP

Stage 10: summarize

| summarize count(), StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated) by  Operation, UserId, ClientIPAddress, ResultStatus, Keyword, OriginatingServer, OfficeObjectId, RuleDetail

Stage 11: extend

| extend UserName = split(UserId, '@')[0], DomainName = split(UserId, '@')[1]

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
BodyContainsWordsmatch
  • Bankuberweisung
  • PO#
  • Paiement
  • Rechnung
  • Zahlung
  • account details
  • bank account
  • bank details
  • bank statement
  • closing
  • deposit
  • funds
  • hacked
  • invoice
  • paycheck
  • payment
  • phishing
  • purchase
  • remittance
  • transfer
  • virement bancaire
Operationeq
  • New-InboxRule
Parametersmatch
  • DeleteMessage transforms: term
  • Deleted Items transforms: term
  • Junk Email transforms: term
SubjectContainsWordsmatch
  • Bankuberweisung
  • PO#
  • Paiement
  • Rechnung
  • Zahlung
  • account details
  • bank account
  • bank details
  • bank statement
  • closing
  • deposit
  • funds
  • hacked
  • invoice
  • paycheck
  • payment
  • phishing
  • purchase
  • remittance
  • transfer
  • virement bancaire
SubjectOrBodyContainsWordsmatch
  • Bankuberweisung
  • PO#
  • Paiement
  • Rechnung
  • Zahlung
  • account details
  • bank account
  • bank details
  • bank statement
  • closing
  • deposit
  • funds
  • hacked
  • invoice
  • paycheck
  • payment
  • phishing
  • purchase
  • remittance
  • transfer
  • virement bancaire

Output fields

Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.

FieldSource
ClientIPAddresssummarize
EndTimeUtcsummarize
Keywordsummarize
OfficeObjectIdsummarize
Operationsummarize
OriginatingServersummarize
ResultStatussummarize
RuleDetailsummarize
StartTimeUtcsummarize
UserIdsummarize
DomainNameextend
UserNameextend