跳到主要内容
uencoder

不安全 Deserialization Prevention Reference

Reference 为不安全 deserialization vulnerabilities 和预防在 various languages.

Vulnerability Mechanism

Insecure deserialization occurs when untrusted data is deserialized into objects, potentially executing attacker-controlled code. Java (ObjectInputStream), Python (pickle), PHP (unserialize), and .NET (BinaryFormatter) are vulnerable. Gadget chains in common libraries enable code execution from crafted payloads. The attack does not require the application to explicitly call dangerous methods; the deserialization process itself triggers them via magic methods (readObject, __wakeup).

Java
ObjectInputStream
readObject gadgets
Python
pickle.loads
__reduce__
PHP
unserialize
__wakeup/__destruct

Prevention

Avoid deserializing untrusted data entirely; use JSON or other data-only formats. If unavoidable, use allowlist-based deserialization (Java ObjectInputFilter, .NET DataContractSerializer with known types). Implement integrity checks (HMAC) on serialized data before deserialization. Monitor and log deserialization events. Keep libraries updated to reduce available gadget chains. Language-specific hardened alternatives: Java SerializationFilter, Python json, PHP json_decode.

avoid
Use JSON instead
data-only formats
allowlist
Known types only
ObjectInputFilter
integrity
HMAC before deserialize
verify signature

相关工具

参考链接