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 attacks4 in cloud environments, focusing on Microsoft Entra ID (Azure AD) token protection,5 conditional access policies, and sign-in anomaly detection. Covers access token6 theft, refresh token replay, Primary Refresh Token (PRT) abuse, and pass-the-cookie7 attacks. Activates for requests involving OAuth token theft detection, token replay8 prevention, Azure AD conditional access token protection, or cloud identity attack9 investiga...10domain: cybersecurity11tags:12- oauth13- token-theft14- azure-ad15- entra-id16- conditional-access17- token-replay18- identity-security19- PRT20subdomain: cloud-security21version: 1.0.022author: oyi7723license: Apache-2.024nist_csf:25- PR.IR-0126- ID.AM-0827- GV.SC-0628- DE.CM-0129category: cybersecurity30metadata:31 source: https://skillmd.com/skills/oyi77/detecting-oauth-token-theft32---3334# Detecting Oauth Token Theft3536## Overview3738Cybersecurity skill for detecting oauth token theft. Follows industry best practices and security standards.3940## When to Use41**Trigger phrases:**42- "detecting oauth token theft"43- "Detects and responds to OAuth token theft and replay attacks in cloud environmen"444546- Investigating alerts for impossible travel or anomalous token usage in Microsoft Entra ID47- Responding to a suspected session hijacking or pass-the-cookie attack48- Configuring proactive defenses against OAuth token theft in an Azure/M365 environment49- Detecting OAuth device code phishing campaigns that bypass MFA50- Analyzing sign-in logs for token replay indicators51- Implementing Token Protection conditional access policies to bind tokens to devices5253**Do not use** for on-premises Kerberos ticket attacks (pass-the-ticket, golden ticket); use Active Directory-specific investigation techniques for those scenarios.545556## When NOT to Use5758- When you lack proper authorization for testing59- For production systems without change management60- When the task requires legal or compliance expertise beyond technical scope616263## Prerequisites6465- Microsoft Entra ID P2 license (required for Identity Protection risk detections and conditional access)66- Global Administrator or Security Administrator role in the Entra admin center67- Microsoft Defender for Cloud Apps (MDCA) license for session anomaly detection68- Access to Entra ID Sign-in Logs and Audit Logs (requires Diagnostic Settings configured to Log Analytics or Sentinel)69- Familiarity with OAuth 2.0 authorization flows (authorization code, device code, client credentials)70- Microsoft Sentinel or equivalent SIEM ingesting Entra ID sign-in and audit logs7172## Workflow7374```python75# Example: IOC detection76import re7778IOC_PATTERNS = {79 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",80 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",81 "hash_md5": r"\b[a-f0-9]{32}\b",82 "hash_sha256": r"\b[a-f0-9]{64}\b",83}8485def extract_iocs(text: str) -> dict:86 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}87```88891. **Define Detection Scope** — Identify the specific oauth token theft techniques or indicators to hunt. Map to MITRE ATT&CK tactics/techniques where applicable.902. **Collect Baseline Data** — Gather historical logs and establish normal behavior patterns for oauth token theft.913. **Build Detection Queries** — Write detection rules, Sigma rules, or SIEM queries targeting oauth token theft indicators.924. **Execute Hunts** — Run queries against the collected data, starting with broad filters and narrowing down.935. **Triage Results** — Investigate alerts, filter false positives, and validate findings against known-good behavior.946. **Document Findings** — Record confirmed detections, IOCs, and affected systems. Update detection rules based on findings.9596## Tools9798- **SIEM Platform** — Central log aggregation and query execution99- **Sigma Rules** — Vendor-agnostic detection rule format100- **MITRE ATT&CK Navigator** — Technique mapping and coverage analysis101102103## Process1041051. **Reconnaissance** — Gather target information, identify attack surface, enumerate services1061. **Analysis/Exploitation** — Execute the technique, analyze results, document findings1071. **Reporting** — Document IOCs, write findings, provide remediation recommendations108109## Verification110111- [ ] All oauth token theft procedures executed completely and documented112- [ ] Findings validated against multiple data sources113- [ ] False positives identified and filtered114- [ ] Results documented with evidence and timestamps115- [ ] Recommendations provided with risk-based prioritization116117## 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. |