SQL Injection Method

非 Y 不嫁゛ 提交于 2019-12-20 07:34:57

问题


The Injection Procedures are :

SELECT UserId, Name, Password FROM Users WHERE UserId = 105 or 1=1;

But, My Question Is how the injection query is working in the sql?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/44878026/sql-injection-method

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