執行不可信賴資源中的命令,或在不可信賴的環境中執行命令,都會導致程序以攻擊者的名義執行惡意命令。
Command Injection 漏洞主要表現為以下兩種形式:
- 攻擊者能夠篡改程序執行的命令:攻擊者直接控制了所執行的命令。
- 攻擊者能夠篡改命令的執行環境:攻擊者間接地控制了所執行的命令。
在這種情況下,我們著重關注第一種情況,即攻擊者控制所執行命令的可能性。這種形式的 Command Injection 漏洞在以下情況下發生:
1. 數據從不可信賴的數據源進入應用程序。
2. 數據被用作代表應用程序所執行命令的字符串,或字符串的一部分。
3. 通過命令的執行,應用程序會授予攻擊者一種原本不該擁有的特權或能力。
例 1:攻擊者可以利用下列代碼通過 cmd 請求參數指定任意指令。
...
<cfset var="#url.cmd#">
<cfexecute name = "C:\windows\System32\cmd.exe"
arguments = "/c #var#"
timeout = "1"
variable="mycmd">
</cfexecute>
...
[1] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A1 Injection
[2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A2 Injection Flaws
[3] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A6 Injection Flaws
[4] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I, APP3570 CAT I
[5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I, APP3570 CAT I
[6] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 77, CWE ID 78
[7] Standards Mapping - SANS Top 25 2010 - (SANS 2010) Insecure Interaction - CWE ID 078
[8] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Insecure Interaction - CWE ID 078
[9] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Insecure Interaction - CWE ID 116
[10] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) OS Commanding
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1, Requirement 6.5.2
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.1
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.6