输入验证与表示问题是由元字符、交替编码和数字表示引起的。安全问题源于信任输入。这些问题包括:“Buffer Overflows”、“Cross-Site Scripting”攻击、“SQL Injection”等其他问题。
...
v_account = request->get_form_field( 'account' ).
v_reference = request->get_form_field( 'ref_key' ).
CONCATENATE `user = '` sy-uname `'` INTO cl_where.
IF v_account IS NOT INITIAL.
CONCATENATE cl_where ` AND account = ` v_account INTO cl_where SEPARATED BY SPACE.
ENDIF.
IF v_reference IS NOT INITIAL.
CONCATENATE cl_where "AND ref_key = `" v_reference "`" INTO cl_where.
ENDIF.
SELECT *
FROM invoice_items
INTO CORRESPONDING FIELDS OF TABLE itab_items
WHERE (cl_where).
...
SELECT *
FROM invoice_items
INTO CORRESPONDING FIELDS OF TABLE itab_items
WHERE user = sy-uname
AND account = <account>
AND ref_key = <reference>.
"abc` OR MANDT NE `+"
,为 v_account 输入字符串“1000”,则该查询会变成:
SELECT *
FROM invoice_items
INTO CORRESPONDING FIELDS OF TABLE itab_items
WHERE user = sy-uname
AND account = 1000
AND ref_key = `abc` OR MANDT NE `+`.
OR MANDT NE `+`
条件会导致 WHERE
子句的估值永远为 true,因为,客户端字段永远不会等于 literal +,因此该查询在逻辑上等同于一个更为简化的查询:
SELECT * FROM invoice_items
INTO CORRESPONDING FIELDS OF TABLE itab_items.
invoice_items
表中的所有条目,而不论指定用户是谁。
PARAMETERS: p_street TYPE string,
p_city TYPE string.
Data: v_sql TYPE string,
stmt TYPE REF TO CL_SQL_STATEMENT.
v_sql = "UPDATE EMP_TABLE SET ".
"Update employee address. Build the update statement with changed details
IF street NE p_street.
CONCATENATE v_sql "STREET = `" p_street "`".
ENDIF.
IF city NE p_city.
CONCATENATE v_sql "CITY = `" p_city "`".
ENDIF.
l_upd = stmt->execute_update( v_sql ).
"ABC` SALARY = `1000000"
的字符串,则应用程序会使用修订后的薪资更新数据库!
...
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var username:String = String(params["username"]);
var itemName:String = String(params["itemName"]);
var query:String = "SELECT * FROM items WHERE owner = " + username + " AND itemname = " + itemName;
stmt.sqlConnection = conn;
stmt.text = query;
stmt.execute();
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
owner
与被授予权限的当前用户一致的条目。
...
string userName = ctx.getAuthenticatedUserName();
string query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ ItemName.Text + "'";
sda = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
例 2:此外,SQLite 使用以下代码可以获得类似的结果:
...
ctx.getAuthUserName(&userName); {
CString query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ request.Lookup("item") + "'";
dbms.ExecuteSQL(query);
...
...
sprintf (sql, "SELECT * FROM items WHERE owner='%s' AND itemname='%s'", username, request.Lookup("item"));
printf("SQL to execute is: \n\t\t %s\n", sql);
rc = sqlite3_exec(db,sql, NULL,0, &err);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
ACCEPT USER.
ACCEPT ITM.
MOVE "SELECT * FROM items WHERE owner = '" TO QUERY1.
MOVE "' AND itemname = '" TO QUERY2.
MOVE "'" TO QUERY3.
STRING
QUERY1, USER, QUERY2, ITM, QUERY3 DELIMITED BY SIZE
INTO QUERY
END-STRING.
EXEC SQL
EXECUTE IMMEDIATE :QUERY
END-EXEC.
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itm
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
条件会导致 where 子句的估值永远为 true,因此该查询在逻辑上等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
<cfquery name="matchingItems" datasource="cfsnippets">
SELECT * FROM items
WHERE owner='#Form.userName#'
AND itemId=#Form.ID#
</cfquery>
...
SELECT * FROM items
WHERE owner = <userName>
AND itemId = <ID>;
Form.ID
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 Form.ID
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemId = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 hacker
的攻击者为 Form.ID
输入字符串“hacker'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'hacker'
AND itemId = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'hacker'
AND itemId = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
final server = await HttpServer.bind('localhost', 18081);
server.listen((request) async {
final headers = request.headers;
final userName = headers.value('userName');
final itemName = headers.value('itemName');
final query = "SELECT * FROM items WHERE owner = '"
+ userName! + "' AND itemname = '"
+ itemName! + "'";
db.query(query);
}
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
rawQuery := request.URL.Query()
username := rawQuery.Get("userName")
itemName := rawQuery.Get("itemName")
query := "SELECT * FROM items WHERE owner = " + username + " AND itemname = " + itemName + ";"
db.Exec(query)
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
中所用的技巧进行攻击。如果攻击者输入字符串 "name'; DELETE FROM items; SELECT * FROM items WHERE 'a'='a
",将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
String userName = ctx.getAuthenticatedUserName();
String itemName = request.getParameter("itemName");
String query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
ResultSet rs = stmt.execute(query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
Example 1
以适应 Android 平台。
...
PasswordAuthentication pa = authenticator.getPasswordAuthentication();
String userName = pa.getUserName();
String itemName = this.getIntent().getExtras().getString("itemName");
String query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
SQLiteDatabase db = this.openOrCreateDatabase("DB", MODE_PRIVATE, null);
Cursor c = db.rawQuery(query, null);
...
...
var username = document.form.username.value;
var itemName = document.form.itemName.value;
var query = "SELECT * FROM items WHERE owner = " + username + " AND itemname = " + itemName + ";";
db.transaction(function (tx) {
tx.executeSql(query);
}
)
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
$userName = $_SESSION['userName'];
$itemName = $_POST['itemName'];
$query = "SELECT * FROM items WHERE owner = '$userName' AND itemname = '$itemName';";
$result = mysql_query($query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
procedure get_item (
itm_cv IN OUT ItmCurTyp,
usr in varchar2,
itm in varchar2)
is
open itm_cv for ' SELECT * FROM items WHERE ' ||
'owner = '''|| usr || '''' ||
' AND itemname = ''' || itm || '''';
end get_item;
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itm
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
条件会导致 where 子句的估值永远为 true,因此该查询在逻辑上等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
userName = req.field('userName')
itemName = req.field('itemName')
query = "SELECT * FROM items WHERE owner = ' " + userName +" ' AND itemname = ' " + itemName +"';"
cursor.execute(query)
result = cursor.fetchall()
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
userName = getAuthenticatedUserName()
itemName = params[:itemName]
sqlQuery = "SELECT * FROM items WHERE owner = '#{userName}' AND itemname = '#{itemName}'"
rs = conn.query(sqlQuery)
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。
...
id = params[:id]
itemName = Mysql.escape_string(params[:itemName])
sqlQuery = "SELECT * FROM items WHERE id = #{userName} AND itemname = '#{itemName}'"
rs = conn.query(sqlQuery)
...
SELECT * FROM items WHERE id=<id> AND itemname = <itemName>;
itemName
中指定单引号,并且似乎已经避免了 SQL injection 漏洞。然而,由于 Ruby 不是静态类型语言,即使我们期望 id
是某种整数,因为这是通过用户输入来指定的,它也不一定是一个数字。如果攻击者可以将 id
的值更改为 1 OR id!=1--
,因为没有检查 id
实际上是数字,SQL 查询现在变为:
SELECT * FROM items WHERE id=1 OR id!=1-- AND itemname = 'anyValue';
SELECT * FROM items WHERE id=1 OR id!=1;
id
的值是否等于 1,这当然相当于表中的一切内容。
def doSQLQuery(value:String) = Action.async { implicit request =>
val result: Future[Seq[User]] = db.run {
sql"select * from users where name = '#$value'".as[User]
}
...
}
SELECT * FROM users
WHERE name = <userName>
userName
不包含单引号字符时,该查询才能正常运行。 如果一个用户名为 wiley
的攻击者为 userName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM users
WHERE name = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM users;
users
表中存储的所有条目,而不论其指定用户是谁。owner
与当前经过身份验证的用户的名称一致的条目。
...
let queryStatementString = "SELECT * FROM items WHERE owner='\(username)' AND itemname='\(item)'"
var queryStatement: OpaquePointer? = nil
if sqlite3_prepare_v2(db, queryStatementString, -1, &queryStatement, nil) == SQLITE_OK {
if sqlite3_step(queryStatement) == SQLITE_ROW {
...
}
}
...
SELECT * FROM items
WHERE owner = '<userName>'
AND itemname = '<itemName>'
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
username = Session("username")
itemName = Request.Form("itemName")
strSQL = "SELECT * FROM items WHERE owner = '"& userName &"' AND itemname = '" & itemName &"'"
objRecordSet.Open strSQL, strConnect, adOpenDynamic, adLockOptimistic, adCmdText
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
owner
与被授予权限的当前用户一致的条目。
...
string userName = ctx.getAuthenticatedUserName();
string queryString = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ ItemName.Text + "'";
SimpleQuery<Item> queryObject = new SimpleQuery(queryString);
Item[] items = (Item[])queryObject.Execute(query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。
...
String userName = ctx.getAuthenticatedUserName();
String itemName = request.getParameter("itemName");
String query = "FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
List items = sess.createQuery(query).list();
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
#
字符来定义,如下所示:
<select id="getItems" parameterClass="MyClass" resultClass="items">
SELECT * FROM items WHERE owner = #userName#
</select>
#
字符表示 iBatis 将创建含 userName
变量的参数化查询。但是,iBatis 也允许使用 $
字符将变量直接连接到 SQL 语句,因而为发动 SQL Injection 攻击敞开了大门。
<select id="getItems" parameterClass="MyClass" resultClass="items">
SELECT * FROM items WHERE owner = #userName# AND itemname = '$itemName$'
</select>
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
...
String userName = ctx.getAuthenticatedUserName();
String itemName = request.getParameter("itemName");
String sql = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
Query query = pm.newQuery(Query.SQL, sql);
query.setClass(Person.class);
List people = (List)query.execute();
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
owner
与被授予权限的当前用户一致的条目。
...
string userName = ctx.getAuthenticatedUserName();
string query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ ItemName.Text + "'";
var items = dataContext.ExecuteCommand<Item>(query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
#
字符来定义,如下所示:
<select id="getItems" parameterType="domain.company.MyParamClass" resultType="MyResultMap">
SELECT *
FROM items
WHERE owner = #{userName}
</select>
#
字符并在变量名称两侧添加大括号表示 MyBatis 将创建含 userName
变量的参数化查询。但是,MyBatis 也允许使用 $
字符将变量直接连接到 SQL 语句,因而为发动 SQL Injection 攻击敞开了大门。
<select id="getItems" parameterType="domain.company.MyParamClass" resultType="MyResultMap">
SELECT *
FROM items
WHERE owner = #{userName}
AND itemname = ${itemName}
</select>
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,WHERE
子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
owner
与被授予权限的当前用户一致的条目。
...
string userName = ctx.GetAuthenticatedUserName();
string query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ ItemName.Text + "'";
List items = sess.CreateSQLQuery(query).List();
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
ItemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 ItemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 ItemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'; DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
owner
与当前经过身份验证的用户的名称一致的条目。
...
string userName = identity.User;
string itemName = apiGatewayProxyRequest.QueryStringParameters['item'];
string statement = $"SELECT * FROM items WHERE owner = '{userName}' AND itemname = '{itemName}'";
var executeStatementRequest = new ExecuteStatementRequest();
executeStatementRequest.Statement = statement;
var executeStatementResponse = await dynamoDBClient.ExecuteStatementAsync(executeStatementRequest);
return displayResults(executeStatementResponse.Items);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:owner
与当前经过身份验证的用户的名称一致的条目。
...
String userName = identity.getUser();
String itemName = apiGatewayProxyRequest.getQueryStringParameters('item');
String statement = String.format("SELECT * FROM items WHERE owner = '%s' AND itemname = '%s'", userName, itemName);
ExecuteStatementRequest executeStatementRequest = new ExecuteStatementRequest();
executeStatementRequest.setStatement(statement);
ExecuteStatementResponse executeStatementResponse = dynamoDBClient.executeStatement(executeStatementRequest);
return displayResults(executeStatementResponse.items());
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,该查询才能正常运行。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,则该查询会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
,where 子句的值将始终为 true,这样该查询在逻辑上就等同于一个更为简单的查询:
...
String userName = ctx.getAuthenticatedUserName();
String itemName = request.getParameter("itemName");
String query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
ResultSet rs = stmt.execute(query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'; DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';
Example 1
以适应 Android 平台。
...
PasswordAuthentication pa = authenticator.getPasswordAuthentication();
String userName = pa.getUserName();
String itemName = this.getIntent().getExtras().getString("itemName");
String query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ itemName + "'";
SQLiteDatabase db = this.openOrCreateDatabase("DB", MODE_PRIVATE, null);
Cursor c = db.rawQuery(query, null);
...
mysql_real_escape_string()
等编码函数可避免一部分 SQL Injection 漏洞,但不能完全避免。依靠此类编码函数等同于用一个安全性较差的拒绝列表来防止 SQL Injection 攻击,并且可能允许攻击者修改语句的含义或者执行任意 SQL 命令。由于在动态解释代码的给定部分中不可能总是静态确定输入显示的位置,因此 Fortify 安全编码规则包可能会将经过验证的动态 SQL 数据显示为“SQL Injection: Poor Validation”问题,即使验证可能足以防止在该上下文中出现 SQL Injection 攻击时也是如此。mysqli_real_escape_string()
的行为。 将 SQL 模式设置为“NO_BACKSLASH_ESCAPES” 时,反斜杠字符会被视为正常字符,而不是转移字符[5]。 由于 mysqli_real_escape_string()
将此情况考虑在内,因此鉴于数据库配置,当 "
不再转义为 \"
时,以下查询易受到 SQL Injection 的攻击。
mysqli_query($mysqli, 'SET SQL_MODE="NO_BACKSLASH_ESCAPES"');
...
$userName = mysqli_real_escape_string($mysqli, $_POST['userName']);
$pass = mysqli_real_escape_string($mysqli, $_POST['pass']);
$query = 'SELECT * FROM users WHERE userName="' . $userName . '"AND pass="' . $pass. '";';
$result = mysqli_query($mysqli, $query);
...
password
字段留空并为 userName
输入 " OR 1=1;--
,则不对引号进行转义,最后的查询如下所示:
SELECT * FROM users
WHERE userName = ""
OR 1=1;
-- "AND pass="";
OR 1=1
会导致 where 子句的值始终为 true 且双连字符会导致剩余语句被视为注释,因此该查询在逻辑上就等同于一个更为简单的查询:
SELECT * FROM users;
owner
与被授予权限的当前用户一致的条目。
...
string userName = ctx.getAuthenticatedUserName();
string query = "SELECT * FROM items WHERE owner = '"
+ userName + "' AND itemname = '"
+ ItemName.Text + "'";
IDataReader responseReader = new InlineQuery().ExecuteReader(query);
...
SELECT * FROM items
WHERE owner = <userName>
AND itemname = <itemName>;
itemName
不包含单引号字符时,才会正确执行这一查询。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name' OR 'a'='a
”,那么查询就会变成:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name' OR 'a'='a';
OR 'a'='a'
会使 where 从句永远评估为 true,因此该查询在逻辑上将等同于一个更为简化的查询:
SELECT * FROM items;
items
表中的所有条目,而不论其指定所有者是谁。Example 1
.中构造和执行的查询所带来的影响。如果一个用户名为 wiley
的攻击者为 itemName
输入字符串“name'); DELETE FROM items; --
”,则该查询就会变为以下两个查询:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
--'
Example 1
.中所用的技巧进行攻击。如果攻击者输入字符串“name'); DELETE FROM items; SELECT * FROM items WHERE 'a'='a
”,将创建以下三个有效语句:
SELECT * FROM items
WHERE owner = 'wiley'
AND itemname = 'name';
DELETE FROM items;
SELECT * FROM items WHERE 'a'='a';