利用用戶輸入生成的動態 LDAP 篩選器可以讓攻擊者借機修改指令的含義。
LDAP injection 錯誤在以下情況下出現:
1. 數據從一個不可信賴的數據源進入程序。
在這種情況下,HP Fortify Static Code Analyzer(HP Fortify 靜態代碼分析器)不能確定數據源的可信性。
2. 該數據用于動態構造一個 LDAP 篩選器。
例 1:以下代碼動態構造一個 LDAP 查詢,并對其加以執行,該查詢可以檢索所有報告給指定經理的雇員記錄。該經理的名字是從網絡套接字中讀取的,因此不可信任。
fgets(manager, sizeof(manager), socket);
snprintf(filter, sizeof(filter, "(manager=%s)", manager);
if ( ( rc = ldap_search_ext_s( ld, FIND_DN, LDAP_SCOPE_BASE,
filter, NULL, 0, NULL, NULL, LDAP_NO_LIMIT,
LDAP_NO_LIMIT, &result ) ) == LDAP_SUCCESS ) {
...
(manager=Smith, John)
manager 不包含任何 LDAP 元字符時才能正常運行。如果攻擊者為 manager 輸入字符串 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