Detect compromised O365 and Google Workspace email accounts by analyzing Unified Audit Logs and Azure AD sign-in logs for impossible travel, inbox rule creation/deletion (Set-InboxRule, New-InboxRule), external mail forwarding rules, and unusual Microsoft Graph API access or OAuth token use. Use when investigating suspected business email compromise (BEC), account takeover, or mailbox persistence via malicious inbox rules.
Start a fresh conversation. Replace the highlighted placeholders.
Use detecting-email-account-compromise to analyze [audit and sign-in logs] for suspected mailbox compromise and produce a severity-scored indicators report covering forwarding rules, suspicious sign-ins, OAuth grants, and correlated users; Microsoft 365 audit logging and the documented Graph access are required.
Required inputs
[audit and sign-in logs]
User-approved starter prompt based on a pinned source version; check current skill requirements before running. Task evidence ↗
SKILL.md
name: detecting-email-account-compromisedescription: Detect compromised O365 and Google Workspace email accounts by analyzing Unified Audit Logs and Azure AD sign-in logs for impossible travel, inbox rule creation/deletion (Set-InboxRule, New-InboxRule), external mail forwarding rules, and unusual Microsoft Graph API access or OAuth token use. Use when investigating suspected business email compromise (BEC), account takeover, or mailbox persistence via malicious inbox rules.domain: cybersecuritysubdomain: incident-responsetags: - email-compromise- office365- microsoft-graph- bec- inbox-rules- sign-in-analysis- account-takeovermitre_attack: - T1486- T1490- T1070- T1078- T1566version: '1.0'author: mahipallicense: Apache-2.0nist_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
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
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)