

通过两个ctf题来做讲解,第一个很简单,第二个多了些限制 http://lab1.xseclab.com/sqli2_3265b4852c13383560327d1c31550b60/index.php http://ctf5.shiyanbar.com/web/wonderkun/web/index.html

万能密码原理 万能密码漏洞都是因为提交字符未加过滤或过滤不严而导致的。
$sql = "SELECT * FROM user WHERE username = '{$username}' AND password = '{$password}'";$res = $dbConnect->query($sql);
后台数据库中会执行
select * from user where username = ' ' and password = ''
两种情况: 1.已知账户名 既然知道了username,就可以将后面的注释使逻辑为真 常用方法:

2.未知账户名
需要通过构造sql语句使where为真 常用方法:



' '+' ' 相当于false(0)

' ' = ' ' 为Ture(1) ' '+' ' 和 ' '=' ' 和 0 = 0都是为了使 where username = ' ' and password = ' '成立 where 0 and 0 或 where 1 and 1

结合例子讲解
第一题:
源码中告诉我们有个用户名是admin


假如 我们并不 知道 admin这个用户

发现也可以成功绕过
第二题:
我们不知道任何用户名的情况下


我们发现貌似不行了,or被过滤了。看看都过滤了哪些字符


可以看到# and or都被过滤了,+和=没有被过滤




最终通过' ' = ' ' 获得了flag

对于select * from user where username = ' ' and password = ''来说 只要我们能够构造出合适的语句使where后面的为真就可以了 本质上就是使 w here 1 and 1 或 where 0 and 0
内 容 来 源 | 五 号 黯 区
QQ 交流群 | 662588477
官 网 地 址 | www.dark5.net
