如果沒有適當的 access control ,就會執行一個包含用戶控制值的 LDAP 聲明,從而允許攻擊者訪問未經授權的目錄條目。
Database access control 錯誤在以下情況下發生:
1. 數據從一個不可信賴的數據源進入程序。
2. 數據用于在 LDAP 查詢中指定一個數據值。
例 1:當前已驗證用戶的雇員 ID 會隨著各個請求一起,通過客戶端界面自動提交。下面的代碼會在使用雇員姓名建立 LDAP 查詢之前適當地使用白名單對該姓名進行驗證。該驗證避免了 LDAP injection 漏洞,但仍可能留下代碼漏洞。
...
string whitelist = @"^[a-zA-Z\-\.']$";
string employee = empName.Text.trim();
Regex pattern = new Regex(whitelist);
if(!pattern.IsMatch(employee)) {
DirectorySearcher src =
new DirectorySearcher("(empID=" + employee + ")");
src.SearchRoot = de;
src.SearchScope = SearchScope.Subtree;
foreach(SearchResult res in src.FindAll()) {
...
}
}
empName 值,會發生什么情況。盡管該界面會自動提交當前用戶的雇員 ID,但是攻擊者也可能在惡意請求中提交其他值替換當前的 ID。因為本例子中的代碼是在匿名綁定情況下執行查詢,不管當前已驗證用戶的身份如何,它都會將有效的雇員 ID 返回至目錄入口。
[1] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A2 Broken Access Control
[2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A4 Insecure Direct Object Reference
[3] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A4 Insecure Direct Object References
[4] Standards Mapping - FIPS200 - (FISMA) AC
[5] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I
[6] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I
[7] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 639
[8] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Insufficient Authorization
[9] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Porous Defenses - CWE ID 863
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.2
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.5.4
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.8