问题描述
注入程序是:
SELECT UserId, Name, Password FROM Users WHERE UserId = 105 or 1=1;
但是,我的问题是注入查询在 sql 中是如何工作的?
But, My Question Is how the injection query is working in the sql?
推荐答案
由于条件 1=1
始终为 true
,将其添加到 末尾>WHERE
语句使它变得无关紧要,并且总是 true
,就好像 WHERE
语句根本不存在一样.因此,无论在 WHERE
语句中添加任何其他条件,始终都会执行查询.
Since the condition 1=1
is always true
, adding it at the end of a WHERE
statement renders it irrelevant, and always true
, as if the WHERE
statement does not exist at all. Thus, the query is always executed, regardless of any other conditions added to the WHERE
statement.
在您提供的示例中,如果您允许您的用户写下他们自己的 userID
,他们可以在输入字段或网站的 URL 地址,并且由于 or 1=1
使 UserId=105
无用,并且查询将始终选择数据,因此 SQL 注入.
In the example you provided, If you allow your users to write down their own userID
, they can write 105 or 1=1
in the input fields or in a website's URL address, and since or 1=1
makes UserId=105
useless, and the query will always select the data, hence the SQL injection.
这篇关于SQL注入方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!