Abstract:
ArticleController.java 文件將未驗證的數據傳遞給第 135 行的 HTTP 重定向函數。如果允許未驗證的輸入控制重定向機制所使用的 URL,可能會有利於攻擊者發動釣魚攻擊。
Explanation:
通過重定向,Web 應用程序能夠引導用戶訪問同一應用程序內的不同網頁或訪問外部站點。應用程序利用重定向來幫助進行站點導航,有時還跟蹤用戶退出站點的方式。當 Web 應用程序將客戶端重定向到攻擊者可以控制的任意 URL 時,就會發生 Open redirect 漏洞:
攻擊者可以利用 Open redirect 漏洞誘騙用戶訪問某個可信賴站點的 URL,並將他們重定向到惡意站點。攻擊者通過對 URL 進行編碼,使最終用戶很難注意到重定向的惡意目標,即使將這一目標作為 URL 參數傳遞給可信賴的站點時也會發生這種情況。因此,Open redirect 常被作為釣魚手段的一種而濫用,攻擊者通過這種方式來獲取最終用戶的敏感數據。
這種情況下,系統會通過 ArticleController.java 的第 122 行中的 getParameterMap() 接受客戶端即將被重定向到的 URL。
數據通過 ArticleController.java 的第 135 行中的 sendRedirect() 傳送。
例 1:以下 JSP 代碼會在用戶打開鏈接時,指示用戶瀏覽器打開從 dest 請求參數中解析的 URL。
<%
...
String strDest = request.getParameter("dest"); pageContext.forward(strDest);
...
%>
如果受害者收到一封電子郵件,指示該用戶打開 "
http://trusted.example.com/ecommerce/redirect.asp?dest=www.wilyhacker.com" 鏈接,用戶有可能會打開該鏈接,因為他會認為這個鏈接將轉到可信賴的站點。然而,一旦用戶打開該鏈接,上面的代碼會將瀏覽器重定向至 "
http://www.wilyhacker.com"。
很多用戶都被告知,要始終監視通過電子郵件收到的 URL,以確保鏈接指向一個他們所熟知的可信賴站點。盡管如此,如果攻擊者對目標 URL 進行 16 進制編碼:
"
http://trusted.example.com/ecommerce/redirect.asp?dest=%77%69%6C%79%68%61%63%6B%65%72%2E%63%6F%6D"
那么,即使再聰明的最終用戶也可能會被欺騙,打開該鏈接。
Instance ID: 0ED5FA23F1BE6AFDBB4F5A9F7F9C4318
Priority Metadata Values:
IMPACT: 4.0
LIKELIHOOD: 2.8
Legacy Priority Metadata Values:
SEVERITY: 4.0
CONFIDENCE: 5.0
Remediation Effort: 3.0
Recommendations:
不應當允許未驗證的用戶輸入控制重定向機制中的目標 URL。而應采用間接方法:創建一份合法 URL 列表,用戶可以指定其中的內容並且只能從中進行選擇。利用這種方法,就絕不會直接使用用戶提供的輸入來指定要重定向到的 URL。
例 2:以下代碼引用了一個通過有效 URL 傳播的數組。用戶單擊的鏈接將通過與所需 URL 對應的數組索引來傳遞。
<%
...
try { int strDest = Integer.parseInt(request.getParameter("dest")); if((strDest >= 0) && (strDest <= strURLArray.length -1 )) { strFinalURL = strURLArray[strDest]; pageContext.forward(strFinalURL); } } catch (NumberFormatException nfe) { // Handle exception
...
}
...
%>
但在某些情況下,這種方法並不可行,因為這樣一份合法 URL 列表過於龐大、難以跟蹤。這種情況下,有一種類似的方法也能限制用於重定向用戶的域,這種方法至少可以防止攻擊者向用戶發送惡意的外部站點。
Tips:
1. 許多現代 Web 框架都提供對用戶輸入執行驗證的機制。其中包括 Struts 和 Spring MVC。為了突出顯示未經驗證的輸入源,HPE Security Fortify 安全編碼規則包會降低 HPE Security Fortify Static Code Analyzer(HPE Security Fortify 靜態代碼分析器)報告的問題被利用的可能性,並在使用框架驗證機制時提供相應的依據,以動態重新調整問題優先級。我們將這種功能稱之為上下文敏感排序。為了進一步幫助 HPE Security Fortify 用戶執行審計過程,HPE Security Fortify 軟件安全研究團隊提供了數據驗證項目模板,該模板會根據應用於輸入源的驗證機制,將問題分組到多個文件夾中。
2. Fortify RTA adds protection against this category.
References:
[1] INPUT-1: Validate inputs, Oracle,
http://www.oracle.com/technetwork/java/seccodeguide-139067.html#5
[2] Standards Mapping - Common Weakness Enumeration, CWE ID 601
[3] Standards Mapping - FIPS200, SI
[4] Standards Mapping - NIST Special Publication 800-53 Revision 4, SI-10 Information Input Validation (P1)
[5] Standards Mapping - OWASP Mobile Top 10 Risks 2014, M1 Weak Server Side Controls
[6] Standards Mapping - OWASP Top 10 2004, A1 Unvalidated Input
[7] Standards Mapping - OWASP Top 10 2010, A10 Unvalidated Redirects and Forwards
[8] Standards Mapping - OWASP Top 10 2013, A10 Unvalidated Redirects and Forwards
[9] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1, Requirement 6.5.1
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2, Requirement 6.3.1.1
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0, Requirement 6.5.1
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0, Requirement 6.5.1
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1, Requirement 6.5.1
[14] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2, Requirement 6.5.1
[15] Standards Mapping - SANS Top 25 2010, Insecure Interaction - CWE ID 601
[16] Standards Mapping - SANS Top 25 2011, Insecure Interaction - CWE ID 601
[17] Standards Mapping - Security Technical Implementation Guide Version 3.1, APP3510 CAT I, APP3600 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.10, APP3510 CAT I, APP3600 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 3.4, APP3510 CAT I, APP3600 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 3.5, APP3510 CAT I, APP3600 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 3.6, APP3510 CAT I, APP3600 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 3.7, APP3510 CAT I, APP3600 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 3.9, APP3510 CAT I, APP3600 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.1, APSC-DV-002560 CAT I
[25] Standards Mapping - Web Application Security Consortium 24 + 2, Content Spoofing
[26] Standards Mapping - Web Application Security Consortium Version 2.00, URL Redirector Abuse (WASC-38)
