analyzing-office365-audit-logs-for-compromise skill (Anthropic-Cybersecurity-Skills)
- Install
- SKILL.md (verbatim)
- Overview
- When to Use
- Prerequisites
- Steps
- Expected Output
- Other files in this skill
- references/api-reference.md (verbatim)
- Libraries Used
- CLI Interface
- Core Functions
- getaccesstoken(tenantid, clientid, clientsecret) — MSAL auth
- queryauditlogs(token, days) — Suspicious operation detection
- checkinboxrules(token, userid) — Forwarding rule detection
- checkmailboxforwarding(token, userid) — SMTP forwarding check
- checkoauthgrants(token) — OAuth consent audit
- fullaudit(token, users, days) — Comprehensive compromise analysis
- Microsoft Graph Endpoints
- Inbox Rule Risk Scoring
- Suspicious Operations Monitored
- Dependencies
What it does. Parse Office 365 Unified Audit Logs via Microsoft Graph API to detect Part of mukul975/Anthropic-Cybersecurity-Skills (817 security skills) (mukul975/Anthropic-Cybersecurity-Skills).
| Upstream | mukul975/Anthropic-Cybersecurity-Skills |
| Skill file | skills/analyzing-office365-audit-logs-for-compromise/SKILL.md |
| License | Apache-2.0 (skill folder LICENSE) |
| Author | mukul975 |
| Fetched | 2026-09-10 |
Install
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-office365-audit-logs-for-compromise, or copy the skill folder into~/.claude/skills/analyzing-office365-audit-logs-for-compromise/.- Raw file:
curl -sL https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/HEAD/skills/analyzing-office365-audit-logs-for-compromise/SKILL.md
SKILL.md (verbatim)
name: analyzing-office365-audit-logs-for-compromise
description: 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.
domain: cybersecurity
subdomain: cloud-security
tags:
- Office365
- Microsoft-Graph
- audit-logs
- email-compromise
- inbox-rules
- OAuth
- BEC
version: '1.0'
author: mahipal
license: Apache-2.0
nist_csf:
- PR.IR-01
- ID.AM-08
- GV.SC-06
- DE.CM-01
mitre_attack:
- T1114.002
- T1098.002
- T1556.006
- T1078.004
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
- 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
- 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
Other files in this skill
references/api-reference.md (verbatim)
API Reference — Analyzing Office 365 Audit Logs for Compromise
Libraries Used
- msal: Microsoft Authentication Library — client credentials flow for Graph API
- requests: HTTP client for Graph API calls with pagination
CLI Interface
python agent.py --tenant-id T --client-id C --client-secret S audit-logs --days 7
python agent.py --tenant-id T --client-id C --client-secret S inbox-rules --user user@domain.com
python agent.py --tenant-id T --client-id C --client-secret S forwarding --user user@domain.com
python agent.py --tenant-id T --client-id C --client-secret S oauth
python agent.py --tenant-id T --client-id C --client-secret S full --users user1@d.com user2@d.com --days 7
Core Functions
get_access_token(tenant_id, client_id, client_secret) — MSAL auth
Uses ConfidentialClientApplication.acquire_token_for_client() with
https://graph.microsoft.com/.default scope.
query_audit_logs(token, days) — Suspicious operation detection
Queries /auditLogs/directoryAudits for 11 suspicious operations:
New-InboxRule, Set-InboxRule, Set-Mailbox, Add-MailboxPermission,
UpdateInboxRules, New-TransportRule, etc.
check_inbox_rules(token, user_id) — Forwarding rule detection
GET /users/{id}/mailFolders/inbox/messageRules. Checks actions for
forwardTo, forwardAsAttachmentTo, redirectTo. Flags external forwards
and delete-after-forward patterns.
check_mailbox_forwarding(token, user_id) — SMTP forwarding check
GET /users/{id}/mailboxSettings. Checks auto-reply status and external audience.
check_oauth_grants(token) — OAuth consent audit
GET /oauth2PermissionGrants. Flags grants with Mail.Read, Mail.ReadWrite,
Mail.Send, Files.ReadWrite.All, MailboxSettings.ReadWrite.
full_audit(token, users, days) — Comprehensive compromise analysis
Microsoft Graph Endpoints
| Endpoint | Method | Permission |
|---|---|---|
/auditLogs/directoryAudits |
GET | AuditLog.Read.All |
/users/{id}/mailFolders/inbox/messageRules |
GET | MailboxSettings.Read |
/users/{id}/mailboxSettings |
GET | MailboxSettings.Read |
/oauth2PermissionGrants |
GET | Directory.Read.All |
Inbox Rule Risk Scoring
| Factor | Points |
|---|---|
| Forwarding rule present | +40 |
| Delete after forward | +25 |
| External forward address | +20 |
| Mark as read + forward | +15 |
Suspicious Operations Monitored
New-InboxRule, Set-InboxRule, Set-Mailbox, Add-MailboxPermission, Set-MailboxJunkEmailConfiguration, Set-OwaMailboxPolicy, New-TransportRule, Add-RecipientPermission, Set-TransportRule, UpdateInboxRules, Set-MailboxAutoReplyConfiguration
Dependencies
msal>= 1.24.0requests>= 2.28.0- Azure AD app with
AuditLog.Read.All,MailboxSettings.Read,Mail.Read
Back to mukul975/Anthropic-Cybersecurity-Skills (817 security skills) or Agent skills.