SQL Injection Method

一曲冷凌霜 提交于 2019-12-02 11:05:11

its when you have your query as string in your code, something like this

Query = "SELECT UserId, Name, Password FROM Users WHERE UserId = '" + sUserID + "'"

So you pass sUserID = "ABC' OR 1=1;"

this will be translated like

SELECT UserId, Name, Password FROM Users WHERE UserId = 'ABC' OR 1=1

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!