構建包含用戶輸入的 SimpleDB 選擇指令會允許攻擊者查看未經授權的記錄。
Query string injection 漏洞會在以下情況下發生:
1. 數據從一個不可信賴的數據源進入程序。
2. 數據被用于動態地構造 SimpleDB 查詢字符串。
例 1:以下代碼動態地構造并執行了一個 SimpleDB select() 查詢,該查詢可搜索與用戶指定產品類別相匹配的清單。用戶還可以指定對結果進行排序的列。假定在執行此代碼片段之前已正確驗證了應用程序并設置了 customerID 的值。
...
String customerID = getAuthenticatedCustomerID(customerName, customerCredentials);
...
AmazonSimpleDBClient sdbc = new AmazonSimpleDBClient(appAWSCredentials);
String query = "select * from invoices where productCategory = '"
+ productCategory + "' and customerID = '"
+ customerID + "' order by '"
+ sortColumn + "' asc";
SelectResult sdbResult = sdbc.select(new SelectRequest(query));
...
select * from invoices
where productCategory = 'Fax Machines'
and customerID = '12345678'
order by 'price' asc
productCategory 和 price 不包含單引號字符時,才會正確執行這一查詢。但是,如果攻擊者為 productCategory 提供了字符串 "Fax Machines' or productCategory = \"",并為 sortColumn 提供了字符串 "\" order by 'price",則查詢將變為如下所示:
select * from invoices
where productCategory = 'Fax Machines' or productCategory = "'
and customerID = '12345678'
order by '" order by 'price' asc
select * from invoices
where productCategory = 'Fax Machines'
or productCategory = "' and customerID = '12345678' order by '"
order by 'price' asc
customerID 所要求的 Authentication,并查看與 'Fax Machines' 相匹配的所有客戶清單記錄。
[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, APP3540.1 CAT I, APP3540.3 CAT II
[5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I, APP3540.1 CAT I, APP3540.3 CAT II
[6] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 89
[7] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Insecure Interaction - CWE ID 089
[8] Standards Mapping - SANS Top 25 2010 - (SANS 2010) Insecure Interaction - CWE ID 089
[9] Standards Mapping - SANS Top 25 2011 - (SANS Top 25 2011) Insecure Interaction - CWE ID 089
[10] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1, Requirement 6.5.2
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.1
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.6
[13] Secure Use of Cloud Storage
[14] Standards Mapping - FIPS200 - (FISMA) SI
[15] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) SQL Injection