关于 testing-mobile-api-authentication
用于评估移动应用 API 身份验证的安全测试技能,供授权测试使用。它提供检查 JWT、OAuth 2.0/OIDC 流程、访问控制和会话处理的步骤。
主要功能
- 01梳理身份验证端点
- 02检查 JWT 和不透明令牌安全性
- 03测试身份验证绕过及 BOLA/IDOR
- 04评估会话管理
- 05检查移动端 OAuth 2.0/OIDC 流程
适用场景
- 01对移动应用后端进行渗透测试
- 02检查令牌处理和失效机制
- 03测试对象级访问控制
- 04检查 PKCE 和重定向 URI 防护
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill testing-mobile-api-authentication安装后在 Claude Code 中输入/testing-mobile-api-authentication确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
LICENSEassets/template.mdreferences/api-reference.mdstandards.mdworkflows.mdscripts/agent.pyprocess.py详细介绍
测试移动端 API 身份认证
何时使用
在以下情况下使用本技能:
- 在渗透测试中评估移动应用后端 API 的身份认证
- 测试 JWT 令牌实现中的常见漏洞(none 算法、弱签名)
- 评估移动应用中 OAuth 2.0 / OIDC 流程的重定向、PKCE 和 scope 问题
- 测试 API 端点中是否存在失效的对象级授权(BOLA/IDOR)
请勿在未经明确授权且不了解速率限制的情况下,对生产 API 使用本技能。
前提条件
- 已配置 Burp Suite 或 mitmproxy 作为移动设备代理
- 已在目标应用上绕过 SSL 证书绑定(若已实现)
- 拥有目标应用的有效测试账户凭据
- 使用 Postman 或 curl 构造 API 请求
- 使用 jwt.io 或 PyJWT 进行 JWT 分析与篡改
工作流
步骤 1:梳理身份认证端点
拦截移动应用流量,识别与身份认证相关的端点:
POST /api/v1/auth/login - Initial authentication
POST /api/v1/auth/register - Account registration
POST /api/v1/auth/refresh - Token refresh
POST /api/v1/auth/logout - Session termination
POST /api/v1/auth/forgot-password - Password reset
POST /api/v1/auth/verify-otp - OTP verification
GET /api/v1/auth/me - Authenticated user profile
步骤 2:分析令牌格式与安全性
JWT 分析:
# Decode JWT without verification
echo "eyJhbGciOiJIUzI1NiIs..." | cut -d. -f2 | base64 -d 2>/dev/null
# Check for common JWT vulnerabilities:
# 1. None algorithm attack
# Change header to: {"alg":"none","typ":"JWT"}
# Remove signature: header.payload.
# 2. Algorithm confusion (RS256 to HS256)
# If server uses RS256, try HS256 with public key as secret
# 3. Weak signing key
# Use hashcat or jwt-cracker to brute-force HMAC secret
hashcat -m 16500 jwt.txt wordlist.txt
# 4. Expiration bypass
# Modify "exp" claim to future timestamp
不透明令牌分析:
- Test token length and entropy
- Check if tokens are sequential/predictable
- Test token reuse after logout
- Verify token invalidation on password change
步骤 3:测试身份认证绕过
# Test missing authentication
curl -X GET https://api.target.com/api/v1/users/profile
# Test with empty/null token
curl -X GET https://api.target.com/api/v1/users/profile \
-H "Authorization: Bearer "
curl -X GET https://api.target.com/api/v1/users/profile \
-H "Authorization: Bearer null"
# Test with expired token (should fail)
curl -X GET https://api.target.com/api/v1/users/profile \
-H "Authorization: Bearer <expired_token>"
# Test token from different user
curl -X GET https://api.target.com/api/v1/users/123/profile \
-H "Authorization: Bearer <user_456_token>"
步骤 4:测试 IDOR / 失效的对象级授权
# Change user ID in request path
curl -X GET https://api.target.com/api/v1/users/123/orders \
-H "Authorization: Bearer <user_456_token>"
# Change object ID in request body
curl -X PUT https://api.target.com/api/v1/orders/789 \
-H "Authorization: Bearer <user_456_token>" \
-d '{"status": "cancelled"}'
# Test horizontal privilege escalation
# Access admin endpoints with regular user token
curl -X GET https://api.target.com/api/v1/admin/users \
-H "Authorization: Bearer <regular_user_token>"
步骤 5:测试会话管理
# Test concurrent sessions
# Login from multiple devices simultaneously - should both remain valid?
# Test session invalidation after logout
TOKEN=$(curl -s -X POST https://api.target.com/api/v1/auth/login \
-d '{"email":"[email protected]","password":"pass"}' | jq -r '.token')
# Logout
curl -X POST https://api.target.com/api/v1/auth/logout \
-H "Authorization: Bearer $TOKEN"
# Try using the same token (should fail)
curl -X GET https://api.target.com/api/v1/users/me \
-H "Authorization: Bearer $TOKEN"
# Test session invalidation after password change
# Token obtained before password change should be invalidated
步骤 6:测试 OAuth 2.0 / OIDC 移动端流程
# Test for authorization code interception
# Check if PKCE (Proof Key for Code Exchange) is enforced
# Test with missing code_verifier parameter
# Test redirect URI manipulation
# Try custom scheme hijacking: myapp://callback
# Test with modified redirect_uri parameter
# Test scope escalation
# Request higher privileges than granted
关键概念
| 术语 | 定义 |
|---|---|
| BOLA/IDOR | 失效的对象级授权 - 通过更改标识符访问资源,而服务端未进行授权检查 |
| JWT | JSON Web Token - 自包含的身份认证令牌,由头部、负载和签名三部分组成 |
| PKCE | Proof Key for Code Exchange - OAuth 2.0 扩展,用于防止移动应用中的授权码被拦截 |
| 令牌刷新 | 使用长期有效的刷新令牌获取新访问令牌而无需重新认证的机制 |
| 会话固定 | 攻击者在受害者认证前设置已知会话 ID,随后劫持该会话的攻击方式 |
工具与系统
- Burp Suite:用于拦截和修改身份认证请求的 HTTP 代理
- jwt_tool:用于测试 JWT 漏洞(none 算法、密钥混淆、声明篡改)的 Python 工具
- Postman:用于构造身份认证请求的 API 测试客户端
- hashcat:用于测试 HMAC 签名密钥强度的密码/JWT 密钥破解工具
- Autorize:用于自动化授权测试的 Burp Suite 扩展
常见陷阱
- 速率限制掩盖问题:API 可能会对测试请求进行速率限制。在请求之间加入延迟,并先以测试者的授权视角进行测试。
- 令牌出现在 URL 中:部分移动端 API 通过 URL 查询参数传递令牌,使其暴露在服务器日志和浏览器历史记录中。即使授权功能正常,也应将其标记为发现项。
- 刷新令牌轮换:部分 API 在每次使用后轮换刷新令牌。如果你的测试使刷新令牌失效,可能会导致测试账户被锁定。
- 移动端特有的 OAuth:移动应用使用自定义 URI scheme 进行 OAuth 重定向,注册了相同 scheme 的恶意应用可能拦截该重定向。
评论
支持 Markdown