通過用戶輸入構造的動態 LDAP 篩選器允許攻擊者修改指令的含義。
LDAP injection 錯誤在以下情況下出現:
1. 數據從一個不可信賴的數據源進入程序。
在這種情況下,HP Fortify Static Code Analyzer(HP Fortify 靜態代碼分析器)不能確定數據源的可信性。
2. 該數據用于動態構造一個 LDAP 篩選器。
例 1:以下代碼動態構造一個 LDAP 查詢,并對其加以執行,該查詢可以檢索所有報告給指定經理的雇員記錄。該經理的名字是從 HTTP 請求中讀取的,因此不可信任。
...
DirContext ctx = new InitialDirContext(env);
String managerName = request.getParameter("managerName");
//retrieve all of the employees who report to a manager
String filter = "(manager=" + managerName + ")";
NamingEnumeration employees = ctx.search("ou=People,dc=example,dc=com",
filter);
...
(manager=Smith, John)
managerName 不包含任何 LDAP 元字符時才能正常運行。如果攻擊者在 managerName 字段中輸入字符串 Hacker, Wiley)(|(objectclass=*),那么該查詢將變成以下形式:
(manager=Hacker, Wiley)(|(objectclass=*))
|(objectclass=*) 條件會導致篩選器與目錄中的所有輸入都匹配,而且會使攻擊者檢索到有關用戶輸入池的信息。根據執行 LDAP 查詢的權限大小,此次攻擊的影響范圍可能會有所差異,但是如果攻擊者能夠控制查詢的命令結構,那么這樣的攻擊至少會影響執行 LDAP 查詢的用戶可以訪問的所有記錄。
[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
[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 90
[7] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Insecure Interaction - CWE ID 116
[8] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) LDAP Injection
[9] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1, Requirement 6.5.2
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.1
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.6
[12] Standards Mapping - FIPS200 - (FISMA) SI