原理:恶意拼接查询
针对程序员编写疏于检查用户输入参数,拼接字符串造成,数据库服务器误认为是正常的sql语句运行;
如果用户输入正确的账号密码,则服务器拼接如下语句:
SELECT * FROM table where usr = 'cyh' and passwd = '123'
攻击者采用sql注入,输入用户账户为 cyh' and 1=1 # ;
密码随便输入,则服务器拼接语句如下:
SELECT * FROM table where usr = 'cyh' and 1 = 1 #and passwd = ''
其中#注释当前字符到行尾,服务器真正检查的语句就是
SELECT * FROM table where usr = 'cyh' and 1 = 1
这样攻击者就成功登录
同理修改密码可得到如下的sql语句,也可成功登录
SELECT * FROM table WHERE usr = 'cyh' and passwd = 'asdasd' or 1 = 1#
甚至于利用分号分割命令,执行非法操作
SELECT * FROM table where usr = 'cyh' and 1 = 1;DELETE FROM table#
甚至于
SELECT * FROM table where usr = '' or 1=1;DROP DATABASE (DB name)#
后果你懂的