HTTP 響應頭文件中包含未驗證的數據會引發 cache-poisoning、cross-site scripting、cross-user defacement、page hijacking、cookie manipulation 或 open redirect。
以下情況中會出現 Header Manipulation 漏洞:
1. 數據通過一個不可信賴的數據源進入 Web 應用程序,最常見的是 HTTP 請求。
2. 數據包含在一個 HTTP 響應頭文件里,未經驗證就發送給了 Web 用戶。
如同許多軟件安全漏洞一樣,Header Manipulation 只是通向終端的一個途徑,它本身并不是終端。從本質上看,這些漏洞是顯而易見的:一個攻擊者將惡意數據傳送到易受攻擊的應用程序,且該應用程序將數據包含在 HTTP 響應頭文件中。
其中最常見的一種 Header Manipulation 攻擊是 HTTP Response Splitting。為了成功地實施 HTTP Response Splitting 盜取,應用程序必須允許將那些包含 CR(回車,由 %0d 或 \r 指定)和 LF(換行,由 %0a 或 \n 指定)的字符輸入到頭文件中。攻擊者利用這些字符不僅可以控制應用程序要發送的響應剩余頭文件和正文,還可以創建完全受其控制的其他響應。
如今的許多現代應用程序服務器可以防止 HTTP 頭文件感染惡意字符。例如,當新行傳遞到 header() 函數時,最新版本的 PHP 將生成一個警告并停止創建頭文件。如果您的 PHP 版本能夠阻止設置帶有換行符的頭文件,則其具備對 HTTP Response Splitting 的防御能力。然而,單純地過濾換行符可能無法保證應用程序不受 Cookie Manipulation 或 Open Redirects 的攻擊,因此必須在設置帶有用戶輸入的 HTTP 頭文件時采取措施。
例如:下段代碼會從 HTTP 請求讀取位置,并將其設置到 HTTP 響應的位置字段的頭文件中。
<?php
$location = $_GET['some_location'];
...
header("location:$location");
?>
HTTP/1.1 200 OK
...
location:index.html
...
some_location 的值不包含任何 CR 和 LF 字符時,響應才會保留這種形式。如果攻擊者提交的是一個惡意字符串,比如 "index.html\r\nHTTP/1.1 200 OK\r\n...",那么此 HTTP 響應就會被分割成以下形式的兩個響應:
HTTP/1.1 200 OK
...
location:index.html
HTTP/1.1 200 OK
...
[1] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A1 Injection
[2] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A1 Unvalidated Input
[3] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A2 Injection Flaws
[4] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I
[5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I
[6] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 113
[7] A. Klein Divide and Conquer:HTTP Response Splitting, Web Cache Poisoning Attacks, and Related Topics
[8] D. Crab HTTP Response Splitting
[9] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) HTTP Response Splitting
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1, Requirement 6.5.2
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.1
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.1
[13] Standards Mapping - FIPS200 - (FISMA) SI