Analyzing Office 365 Audit Logs for Compromise
Overview
Business Email Compromise (BEC) attacks often leave traces in Office 365 audit logs: suspicious inbox rule creation, email forwarding to external addresses, mailbox delegation changes, and unauthorized OAuth application consent grants. This skill uses the Microsoft Graph API to query the Unified Audit Log, enumerate inbox rules across mailboxes, detect forwarding configurations, and identify compromised account indicators.
When to Use
Trigger phrases:
"analyzing office365 audit logs for compromise"
"Parse Office 365 Unified Audit Logs via Microsoft Graph API to detect email forw"
When investigating security incidents that require analyzing office365 audit logs for 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
- Azure AD app registration with
AuditLog.Read.All, MailboxSettings.Read, Mail.Read (application permissions)
- Python 3.9+ with
msal, requests
- Client secret or certificate for authentication
- Global Reader or Security Reader role
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()}
- Authenticate to Microsoft Graph using MSAL client credentials flow
- Query Unified Audit Log for suspicious operations (Set-Mailbox, New-InboxRule)
- Enumerate inbox rules across mailboxes and flag forwarding rules
- Detect mailbox delegation changes (Add-MailboxPermission)
- Identify OAuth consent grants to suspicious applications
- Check for suspicious sign-in patterns from audit logs
- Generate compromise indicator report with timeline
Expected Output
- JSON report listing forwarding rules, delegation changes, OAuth grants, and suspicious audit events with risk scores
- Timeline of compromise indicators with affected mailboxes
When NOT to Use
- You need to perform the attack, not analyze it (use performing-* skills)
- Task is about detection, not analysis (use detecting-* skills)
- You need to implement controls (use implementing-* skills)
- Task is about threat hunting, not post-incident analysis (use hunting-* skills)
- You don't have access to the artifacts/logs to analyze
- Task requires real-time monitoring (use SOC tools)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Treating compliance checklists as security guarantees rather than minimum baselines
- Failing to document exceptions and risk acceptance decisions
- Relying on point-in-time audits instead of continuous monitoring
Process
- Scope — Define research questions, identify data sources, set time boundaries
- Gather — Collect data from primary sources, APIs, and public records
- Synthesize — Analyze findings, identify patterns, produce actionable report
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Vulnerabilities reproduced with proof-of-concept and impact analysis
- False positives filtered out through manual verification
- Fix recommendations include code-level remediation guidance
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: analyzing-office365-audit-logs-for-compromise3description: Use when parse Office 365 Unified Audit Logs via Microsoft Graph API to detect email forwarding rule creation, inbox delegation, suspicious OAuth app grants, and other indicators of account compromise. Use when working with analyzing office365 audit logs for compromise.4license: Apache-2.05---678# Analyzing Office 365 Audit Logs for Compromise910## Overview1112Business Email Compromise (BEC) attacks often leave traces in Office 365 audit logs: suspicious inbox rule creation, email forwarding to external addresses, mailbox delegation changes, and unauthorized OAuth application consent grants. This skill uses the Microsoft Graph API to query the Unified Audit Log, enumerate inbox rules across mailboxes, detect forwarding configurations, and identify compromised account indicators.131415## When to Use16**Trigger phrases:**17- "analyzing office365 audit logs for compromise"18- "Parse Office 365 Unified Audit Logs via Microsoft Graph API to detect email forw"192021- When investigating security incidents that require analyzing office365 audit logs for compromise22- When building detection rules or threat hunting queries for this domain23- When SOC analysts need structured procedures for this analysis type24- When validating security monitoring coverage for related attack techniques2526## Prerequisites2728- Azure AD app registration with `AuditLog.Read.All`, `MailboxSettings.Read`, `Mail.Read` (application permissions)29- Python 3.9+ with `msal`, `requests`30- Client secret or certificate for authentication31- Global Reader or Security Reader role3233## Steps3435```python36# Example: IOC detection37import re3839IOC_PATTERNS = {40 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",41 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",42 "hash_md5": r"\b[a-f0-9]{32}\b",43 "hash_sha256": r"\b[a-f0-9]{64}\b",44}4546def extract_iocs(text: str) -> dict:47 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}48```49501. Authenticate to Microsoft Graph using MSAL client credentials flow512. Query Unified Audit Log for suspicious operations (Set-Mailbox, New-InboxRule)523. Enumerate inbox rules across mailboxes and flag forwarding rules534. Detect mailbox delegation changes (Add-MailboxPermission)545. Identify OAuth consent grants to suspicious applications556. Check for suspicious sign-in patterns from audit logs567. Generate compromise indicator report with timeline5758## Expected Output5960- JSON report listing forwarding rules, delegation changes, OAuth grants, and suspicious audit events with risk scores61- Timeline of compromise indicators with affected mailboxes62## When NOT to Use6364- You need to perform the attack, not analyze it (use performing-* skills)65- Task is about detection, not analysis (use detecting-* skills)66- You need to implement controls (use implementing-* skills)67- Task is about threat hunting, not post-incident analysis (use hunting-* skills)68- You don't have access to the artifacts/logs to analyze69- Task requires real-time monitoring (use SOC tools)707172## Red Flags7374- Performing actions without explicit written authorization from the asset owner75- Testing against production systems without a defined scope and rules of engagement76- Treating compliance checklists as security guarantees rather than minimum baselines77- Failing to document exceptions and risk acceptance decisions78- Relying on point-in-time audits instead of continuous monitoring7980## Process81821. **Scope** — Define research questions, identify data sources, set time boundaries831. **Gather** — Collect data from primary sources, APIs, and public records841. **Synthesize** — Analyze findings, identify patterns, produce actionable report8586## Verification8788- All steps executed successfully against a test environment before production use89- Output documented with screenshots or logs demonstrating expected behavior90- Vulnerabilities reproduced with proof-of-concept and impact analysis91- False positives filtered out through manual verification92- Fix recommendations include code-level remediation guidance9394## Anti-Rationalization Table9596| Rationalization | Reality |97|---|---|98| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |99| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |100| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |