SQL Injection Method

前端 未结 2 1999
既然无缘
既然无缘 2021-01-27 20:36

The Injection Procedures are :

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

But, My Question Is how the injection query

相关标签:
2条回答
  • 2021-01-27 21:17

    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
    
    0 讨论(0)
  • 2021-01-27 21:24

    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.

    0 讨论(0)
提交回复
热议问题