[网鼎杯 2020 玄武组]SSRFMe

[网鼎杯 2020 玄武组]SSRFMe

源码

<?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.
?>
  • 题目给了提示,请在本地访问hint.php。
  • 代码不算难懂:就是只能使用这些协议:http|https|gopher|dict,而且还进行了过滤不严的127.0.0.1,直接使用0.0.0.0绕过
    [[ssrf绕过#绕过127.0.0.1]]
    访问得到
<?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']);
}
  • 尝试绕过死亡exit(),但是/var目录没有写了权限,/tmp目录有写入权限
  • 而且这里给了提示:redis pass is root 告诉我们密码是root

主从复制

[[redis-主从复制]]

原理

  • 字面意思,redis为了数据更改方便,有这一模式,主机的内容更改会导致从机的内容跟着更改。
  • 这时我们将自己的服务主机设置为主机,目标的设置为从机,则从机会有主机的执行脚本,从而rce
  • 详细的参考博客
    redis主从复制

使用

准备工作

需要使用
https://github.com/xmsec/redis-ssrf 和 https://github.com/n0b0dyCN/redis-rogue-server 下的exp.so文件

使用过程
  • 在自己的服务主机里把这两个py文件和exp.so传至同一目录下,也可以开个小号使用buu内网
更改ssrf-redis.py内容
  • 这里只需要更改4处内容就行
    lhost改为自己或者buu内网的IP,command改为执行的命令
    image.png
    更改ip绕过本题的waf
    image.png
    根据提示填入passwd为root
    image.png
生成payload启动服务

image.png
只是在kali下演示一下,自己主机得到的回显
image.png
使用payload得到flag,要进行二次编码
image.png

反弹shell

参考下一篇文章
[网鼎杯 2020 玄武组]SSRFMe-反弹shell

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值