name: detecting-email-account-compromise description: Detect compromised O365 and Google Workspace email accounts by analyzing inbox rule creation, suspicious sign-in locations, mail forwarding rules, and unusual API access patterns via Microsoft Graph and audit logs. domain: cybersecurity subdomain: incident-response tags:
- email-compromise
- office365
- microsoft-graph
- bec
- inbox-rules
- sign-in-analysis
- account-takeover mitre_attack:
- T1114
- T1566
- T1078
- T1534 version: '1.0' author: mahipal license: Apache-2.0 nist_csf:
- RS.MA-01
- RS.MA-02
- RS.AN-03
- RC.RP-01
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
- 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
Detection Gaps & Validation
- OAuth persistence outlives the password reset: the most-missed BEC foothold is an illicit app consent grant, not an inbox rule. Resetting the password and revoking sessions does nothing to a refresh token. Pull
Consent to application/Add app role assignmentfrom the UAL and audit/servicePrincipalsfor apps withMail.ReadWriteorMail.Send. - Forwarding rules hide in three places: mailbox inbox rules (
New-InboxRule/Set-InboxRule), transport rules, and the mailbox-levelForwardingSMTPAddress/ForwardingAddress. Attackers also setDeleteMessagerules that match "invoice"/"payment"/"wire" to hide replies. Enumerate all three, not just inbox rules. - Cross-corroborate, don't trust one signal: an "impossible travel" alert alone is noisy (VPNs, mobile roaming). Confirm a hit by tying the suspect sign-in to a non-interactive token, a legacy-auth protocol (IMAP/POP/SMTP AUTH,
python-requests/curlUA), AND a follow-on action (rule creation, mass read, send). One without the others is a candidate, not a confirmation. - FP tuning: baseline each user's normal ASNs, clients, and forwarding to a corporate archive before flagging. Treat admin-set org-wide journaling and known marketing connectors as allowlist entries so they don't drown real external auto-forwards.
- Don't conclude clean until you've checked: UAL retention may be shorter than dwell time — corroborate against Azure AD sign-in logs and message trace, and verify MFA method registration (
Update user/Register security info) since attackers add their own authenticator to keep access after a reset.
Prerequisites
- Microsoft 365 with Unified Audit Logging enabled
- Azure AD P1/P2 for risk detection APIs
- Python 3.9+ with
requests,msallibraries - Microsoft Graph API application registration with Mail.Read, AuditLog.Read.All permissions
- Understanding of OAuth2 client credential flows
Steps
- 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/signInsfor 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.