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 API4 to detect email forwarding rule creation, inbox delegation, suspicious OAuth app5 grants, and other indicators of account compromise. Use when working with analyzing6 office365 audit logs for compromise.7domain: cybersecurity8subdomain: cloud-security9tags:10- Office36511- Microsoft-Graph12- audit-logs13- email-compromise14- inbox-rules15- OAuth16- BEC17version: '1.0'18author: oyi7719license: Apache-2.020nist_csf:21- PR.IR-0122- ID.AM-0823- GV.SC-0624- DE.CM-0125category: cybersecurity26metadata:27 source: https://skillmd.com/skills/oyi77/analyzing-office365-audit-logs-for-compromise28---293031# Analyzing Office 365 Audit Logs for Compromise3233## Overview3435Business 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.363738## When to Use39**Trigger phrases:**40- "analyzing office365 audit logs for compromise"41- "Parse Office 365 Unified Audit Logs via Microsoft Graph API to detect email forw"424344- When investigating security incidents that require analyzing office365 audit logs for compromise45- When building detection rules or threat hunting queries for this domain46- When SOC analysts need structured procedures for this analysis type47- When validating security monitoring coverage for related attack techniques4849## Prerequisites5051- Azure AD app registration with `AuditLog.Read.All`, `MailboxSettings.Read`, `Mail.Read` (application permissions)52- Python 3.9+ with `msal`, `requests`53- Client secret or certificate for authentication54- Global Reader or Security Reader role5556## Steps5758```python59# Example: IOC detection60import re6162IOC_PATTERNS = {63 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",64 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",65 "hash_md5": r"\b[a-f0-9]{32}\b",66 "hash_sha256": r"\b[a-f0-9]{64}\b",67}6869def extract_iocs(text: str) -> dict:70 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}71```72731. Authenticate to Microsoft Graph using MSAL client credentials flow742. Query Unified Audit Log for suspicious operations (Set-Mailbox, New-InboxRule)753. Enumerate inbox rules across mailboxes and flag forwarding rules764. Detect mailbox delegation changes (Add-MailboxPermission)775. Identify OAuth consent grants to suspicious applications786. Check for suspicious sign-in patterns from audit logs797. Generate compromise indicator report with timeline8081## Expected Output8283- JSON report listing forwarding rules, delegation changes, OAuth grants, and suspicious audit events with risk scores84- Timeline of compromise indicators with affected mailboxes85## When NOT to Use8687- You need to perform the attack, not analyze it (use performing-* skills)88- Task is about detection, not analysis (use detecting-* skills)89- You need to implement controls (use implementing-* skills)90- Task is about threat hunting, not post-incident analysis (use hunting-* skills)91- You don't have access to the artifacts/logs to analyze92- Task requires real-time monitoring (use SOC tools)939495## Red Flags9697- Performing actions without explicit written authorization from the asset owner98- Testing against production systems without a defined scope and rules of engagement99- Treating compliance checklists as security guarantees rather than minimum baselines100- Failing to document exceptions and risk acceptance decisions101- Relying on point-in-time audits instead of continuous monitoring102103## Process1041051. **Scope** — Define research questions, identify data sources, set time boundaries1061. **Gather** — Collect data from primary sources, APIs, and public records1071. **Synthesize** — Analyze findings, identify patterns, produce actionable report108109## Verification110111- All steps executed successfully against a test environment before production use112- Output documented with screenshots or logs demonstrating expected behavior113- Vulnerabilities reproduced with proof-of-concept and impact analysis114- False positives filtered out through manual verification115- Fix recommendations include code-level remediation guidance116117## Anti-Rationalization Table118119| Rationalization | Reality |120|---|---|121| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |122| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |123| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |