Detecting Oauth Token Theft
Overview
Cybersecurity skill for detecting oauth token theft. Follows industry best practices and security standards.
When to Use
Trigger phrases:
"detecting oauth token theft"
"Detects and responds to OAuth token theft and replay attacks in cloud environmen"
Investigating alerts for impossible travel or anomalous token usage in Microsoft Entra ID
Responding to a suspected session hijacking or pass-the-cookie attack
Configuring proactive defenses against OAuth token theft in an Azure/M365 environment
Detecting OAuth device code phishing campaigns that bypass MFA
Analyzing sign-in logs for token replay indicators
Implementing Token Protection conditional access policies to bind tokens to devices
Do not use for on-premises Kerberos ticket attacks (pass-the-ticket, golden ticket); use Active Directory-specific investigation techniques for those scenarios.
When NOT to Use
- When you lack proper authorization for testing
- For production systems without change management
- When the task requires legal or compliance expertise beyond technical scope
Prerequisites
- Microsoft Entra ID P2 license (required for Identity Protection risk detections and conditional access)
- Global Administrator or Security Administrator role in the Entra admin center
- Microsoft Defender for Cloud Apps (MDCA) license for session anomaly detection
- Access to Entra ID Sign-in Logs and Audit Logs (requires Diagnostic Settings configured to Log Analytics or Sentinel)
- Familiarity with OAuth 2.0 authorization flows (authorization code, device code, client credentials)
- Microsoft Sentinel or equivalent SIEM ingesting Entra ID sign-in and audit logs
Workflow
# 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()}
- Define Detection Scope — Identify the specific oauth token theft techniques or indicators to hunt. Map to MITRE ATT&CK tactics/techniques where applicable.
- Collect Baseline Data — Gather historical logs and establish normal behavior patterns for oauth token theft.
- Build Detection Queries — Write detection rules, Sigma rules, or SIEM queries targeting oauth token theft indicators.
- Execute Hunts — Run queries against the collected data, starting with broad filters and narrowing down.
- Triage Results — Investigate alerts, filter false positives, and validate findings against known-good behavior.
- Document Findings — Record confirmed detections, IOCs, and affected systems. Update detection rules based on findings.
Tools
- SIEM Platform — Central log aggregation and query execution
- Sigma Rules — Vendor-agnostic detection rule format
- MITRE ATT&CK Navigator — Technique mapping and coverage analysis
Process
- Reconnaissance — Gather target information, identify attack surface, enumerate services
- Analysis/Exploitation — Execute the technique, analyze results, document findings
- Reporting — Document IOCs, write findings, provide remediation recommendations
Verification
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: detecting-oauth-token-theft3description: Use when detecting and responding to OAuth token theft and replay attacks in cloud environments, focusing on Microsoft Entra ID (Azure AD) token protection, conditional access policies, and sign-in anomaly detection. Covers access token theft, refresh token replay, Primary Refresh Token (PRT) abuse, and pass-the-cookie attacks. Activates for requests involving OAuth token theft detection, token replay prevention, Azure AD conditional access token protection, or cloud identity attack investiga...4license: Apache-2.05---67# Detecting Oauth Token Theft89## Overview1011Cybersecurity skill for detecting oauth token theft. Follows industry best practices and security standards.1213## When to Use14**Trigger phrases:**15- "detecting oauth token theft"16- "Detects and responds to OAuth token theft and replay attacks in cloud environmen"171819- Investigating alerts for impossible travel or anomalous token usage in Microsoft Entra ID20- Responding to a suspected session hijacking or pass-the-cookie attack21- Configuring proactive defenses against OAuth token theft in an Azure/M365 environment22- Detecting OAuth device code phishing campaigns that bypass MFA23- Analyzing sign-in logs for token replay indicators24- Implementing Token Protection conditional access policies to bind tokens to devices2526**Do not use** for on-premises Kerberos ticket attacks (pass-the-ticket, golden ticket); use Active Directory-specific investigation techniques for those scenarios.272829## When NOT to Use3031- When you lack proper authorization for testing32- For production systems without change management33- When the task requires legal or compliance expertise beyond technical scope343536## Prerequisites3738- Microsoft Entra ID P2 license (required for Identity Protection risk detections and conditional access)39- Global Administrator or Security Administrator role in the Entra admin center40- Microsoft Defender for Cloud Apps (MDCA) license for session anomaly detection41- Access to Entra ID Sign-in Logs and Audit Logs (requires Diagnostic Settings configured to Log Analytics or Sentinel)42- Familiarity with OAuth 2.0 authorization flows (authorization code, device code, client credentials)43- Microsoft Sentinel or equivalent SIEM ingesting Entra ID sign-in and audit logs4445## Workflow4647```python48# Example: IOC detection49import re5051IOC_PATTERNS = {52 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",53 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",54 "hash_md5": r"\b[a-f0-9]{32}\b",55 "hash_sha256": r"\b[a-f0-9]{64}\b",56}5758def extract_iocs(text: str) -> dict:59 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}60```61621. **Define Detection Scope** — Identify the specific oauth token theft techniques or indicators to hunt. Map to MITRE ATT&CK tactics/techniques where applicable.632. **Collect Baseline Data** — Gather historical logs and establish normal behavior patterns for oauth token theft.643. **Build Detection Queries** — Write detection rules, Sigma rules, or SIEM queries targeting oauth token theft indicators.654. **Execute Hunts** — Run queries against the collected data, starting with broad filters and narrowing down.665. **Triage Results** — Investigate alerts, filter false positives, and validate findings against known-good behavior.676. **Document Findings** — Record confirmed detections, IOCs, and affected systems. Update detection rules based on findings.6869## Tools7071- **SIEM Platform** — Central log aggregation and query execution72- **Sigma Rules** — Vendor-agnostic detection rule format73- **MITRE ATT&CK Navigator** — Technique mapping and coverage analysis747576## Process77781. **Reconnaissance** — Gather target information, identify attack surface, enumerate services791. **Analysis/Exploitation** — Execute the technique, analyze results, document findings801. **Reporting** — Document IOCs, write findings, provide remediation recommendations8182## Verification8384- [ ] All oauth token theft procedures executed completely and documented85- [ ] Findings validated against multiple data sources86- [ ] False positives identified and filtered87- [ ] Results documented with evidence and timestamps88- [ ] Recommendations provided with risk-based prioritization8990## Anti-Rationalization Table9192| Rationalization | Reality |93|---|---|94| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |95| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |96| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |