Detecting Email Account Compromise
Overview
Email account compromise (EAC) is a prevalent attack vector where adversaries gain unauthorized access to mailboxes to exfiltrate sensitive data, conduct business email compromise (BEC), or establish persistence through inbox rule manipulation. Attackers commonly create forwarding rules to siphon emails, delete rules to hide evidence, or use OAuth tokens for persistent access. Detection relies on analyzing Microsoft 365 Unified Audit Logs, Azure AD sign-in logs for impossible travel or suspicious locations, inbox rule creation events (Set-InboxRule, New-InboxRule), and Microsoft Graph API access patterns. Key indicators include forwarding rules to external addresses, rules that delete or move messages matching keywords like "invoice" or "payment", and sign-ins from unusual user agents such as python-requests.
When to Use
Trigger phrases:
"detecting email account compromise"
"Detect compromised O365 and Google Workspace email accounts by analyzing inbox r"
When investigating security incidents that require detecting email account compromise
When building detection rules or threat hunting queries for this domain
When SOC analysts need structured procedures for this analysis type
When validating security monitoring coverage for related attack techniques
Prerequisites
- Microsoft 365 with Unified Audit Logging enabled
- Azure AD P1/P2 for risk detection APIs
- Python 3.9+ with
requests, msal libraries
- Microsoft Graph API application registration with Mail.Read, AuditLog.Read.All permissions
- Understanding of OAuth2 client credential flows
Steps
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Export audit logs or connect to Microsoft Graph API using MSAL authentication
- Query inbox rules for all monitored mailboxes via
/users/{id}/mailFolders/inbox/messageRules
- Analyze rules for external forwarding (ForwardTo, RedirectTo external addresses)
- Detect suspicious rule patterns: deletion rules, keyword-matching rules targeting financial terms
- Query sign-in logs via
/auditLogs/signIns for unusual locations and impossible travel
- Check for suspicious user agent strings (python-requests, PowerShell, curl)
- Identify OAuth application consent grants for suspicious third-party apps
- Correlate findings across users to detect campaign-level compromise
- Generate compromise indicators report with severity scores
Expected Output
A JSON report listing compromised or suspicious accounts, malicious inbox rules detected, impossible travel events, suspicious OAuth grants, and recommended containment actions with severity ratings.
When NOT to Use
- You need to perform the attack to test detection (use performing-* skills)
- Task is about analyzing past incidents (use analyzing-* skills)
- You need to implement detection rules (use implementing-* skills)
- Task is about threat hunting proactively (use hunting-* skills)
- You don't have access to logs or monitoring data
- Task requires incident response (use IR skills)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Sharing sensitive findings or credentials in unencrypted communications
- Failing to properly scope and contain the assessment before starting
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Results validated against known-good baselines or reference implementations
- Documentation complete enough for another analyst to reproduce findings
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: detecting-email-account-compromise3description: Use when detect compromised O365 and Google Workspace email accounts4 by analyzing inbox rule creation, suspicious sign-in locations, mail forwarding5 rules, and unusual API access patterns via Microsoft Graph and audit logs. Use when6 detecting compromised o365 and google workspace email accounts by analyzing.7domain: cybersecurity8subdomain: incident-response9tags:10- email-compromise11- office36512- microsoft-graph13- bec14- inbox-rules15- sign-in-analysis16- account-takeover17mitre_attack:18- T111419- T156620- T107821- T153422version: '1.0'23author: oyi7724license: Apache-2.025nist_csf:26- RS.MA-0127- RS.MA-0228- RS.AN-0329- RC.RP-0130category: cybersecurity31metadata:32 source: https://skillmd.com/skills/oyi77/detecting-email-account-compromise33---3435# Detecting Email Account Compromise3637## Overview3839Email account compromise (EAC) is a prevalent attack vector where adversaries gain unauthorized access to mailboxes to exfiltrate sensitive data, conduct business email compromise (BEC), or establish persistence through inbox rule manipulation. Attackers commonly create forwarding rules to siphon emails, delete rules to hide evidence, or use OAuth tokens for persistent access. Detection relies on analyzing Microsoft 365 Unified Audit Logs, Azure AD sign-in logs for impossible travel or suspicious locations, inbox rule creation events (Set-InboxRule, New-InboxRule), and Microsoft Graph API access patterns. Key indicators include forwarding rules to external addresses, rules that delete or move messages matching keywords like "invoice" or "payment", and sign-ins from unusual user agents such as python-requests.404142## When to Use43**Trigger phrases:**44- "detecting email account compromise"45- "Detect compromised O365 and Google Workspace email accounts by analyzing inbox r"464748- When investigating security incidents that require detecting email account compromise49- When building detection rules or threat hunting queries for this domain50- When SOC analysts need structured procedures for this analysis type51- When validating security monitoring coverage for related attack techniques5253## Prerequisites5455- Microsoft 365 with Unified Audit Logging enabled56- Azure AD P1/P2 for risk detection APIs57- Python 3.9+ with `requests`, `msal` libraries58- Microsoft Graph API application registration with Mail.Read, AuditLog.Read.All permissions59- Understanding of OAuth2 client credential flows6061## Steps6263```python64# Example: IOC detection65import re6667IOC_PATTERNS = {68 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",69 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",70 "hash_md5": r"\b[a-f0-9]{32}\b",71 "hash_sha256": r"\b[a-f0-9]{64}\b",72}7374def extract_iocs(text: str) -> dict:75 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}76```77781. Export audit logs or connect to Microsoft Graph API using MSAL authentication792. Query inbox rules for all monitored mailboxes via `/users/{id}/mailFolders/inbox/messageRules`803. Analyze rules for external forwarding (ForwardTo, RedirectTo external addresses)814. Detect suspicious rule patterns: deletion rules, keyword-matching rules targeting financial terms825. Query sign-in logs via `/auditLogs/signIns` for unusual locations and impossible travel836. Check for suspicious user agent strings (python-requests, PowerShell, curl)847. Identify OAuth application consent grants for suspicious third-party apps858. Correlate findings across users to detect campaign-level compromise869. Generate compromise indicators report with severity scores8788## Expected Output8990A JSON report listing compromised or suspicious accounts, malicious inbox rules detected, impossible travel events, suspicious OAuth grants, and recommended containment actions with severity ratings.91## When NOT to Use9293- You need to perform the attack to test detection (use performing-* skills)94- Task is about analyzing past incidents (use analyzing-* skills)95- You need to implement detection rules (use implementing-* skills)96- Task is about threat hunting proactively (use hunting-* skills)97- You don't have access to logs or monitoring data98- Task requires incident response (use IR skills)99100101## Red Flags102103- Performing actions without explicit written authorization from the asset owner104- Testing against production systems without a defined scope and rules of engagement105- Sharing sensitive findings or credentials in unencrypted communications106- Failing to properly scope and contain the assessment before starting107108## Process1091101. **Reconnaissance** — Gather target information, identify attack surface, enumerate services1111. **Analysis/Exploitation** — Execute the technique, analyze results, document findings1121. **Reporting** — Document IOCs, write findings, provide remediation recommendations113114## Verification115116- All steps executed successfully against a test environment before production use117- Output documented with screenshots or logs demonstrating expected behavior118- Results validated against known-good baselines or reference implementations119- Documentation complete enough for another analyst to reproduce findings120121## Anti-Rationalization Table122123| Rationalization | Reality |124|---|---|125| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |126| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |127| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |