2021年11月24日,阿里云安全团队向Apache官方报告了Apache Log4j2远程代码执行漏洞。2021年12月10日,阿里云安全团队发现 Apache Log4j 2.15.0-rc1 版本存在漏洞绕过,请及时更新至 Apache Log4j 2.15.0 正式版本。
经过一周时间的Log4j2 RCE事件的发酵,事情也变也越来越复杂和有趣,就连 Log4j 官方紧急发布了 2.15.0 版本之后没有过多久,又发声明说 2.15.0 版本也没有完全解决问题,然后进而继续发布了 2.16.0 版本。大家都以为2.16.0是最终终结版本了,没想到才过多久又爆雷,Log4j 2.17.0横空出世。
续上篇文内容,接着来学习JNDI注入相关知识。JNDI注入是Fastjson反序列化漏洞中的攻击手法之一。
Apache Log4j2是一个基于Java的日志记录工具。该工具重写了Log4j框架,并且引入了大量丰富的特性。该日志框架被大量用于业务系统开发,用来记录日志信息。大多数情况下,开发者可能会将用户输入导致的错误信息写入日志中,比如在用户登录的时候打印一些异常信息,如xxx密码输入错误超过5次,账号被锁定;xxx账号已被锁定;xxx账号频繁异地登录。
我们在上一章《攻击rmi的方式》中提到了rmi的一大特性——动态类加载。而jndi注入就是利用的动态类加载完成攻击的。在谈jndi注入之前,我们先来看看关于jndi的基础知识
JNDI (Java Naming and Directory Interface) 是一个java中的技术,用于提供一个访问各种资源的接口。比如通过JNDI可以在局域网上定位一台打印机,或者定位数据库服务,远程JAVA对象等。 JNDI底层支持RMI远程对象,RMI注册的服务可以直接被JNDI接口访问调用。
Naming就是名称服务,通过名称查找实际对象的服务。值得一提的名称服务为 LDAP,全称为 Lightweight Directory Access Protocol,即轻量级目录访问协议,其名称也是从右到左进行逐级定义,各级以逗号分隔,每级为一个 name/value 对,以等号分隔。比如一个 LDAP 名称如下:
漏洞成因: log4j支持jndi,可以远程调用rmi和ldap,由于rmi和idap本身存在漏洞,因此log4j就会简介触发rmi和idap
最近两天,我相信Java圈子讨论最多的就是这个Log4J2的漏洞了,毕竟影响还是很大的
之前看了SHIRO-721这个漏洞,然后这个漏洞和SHIRO-550有些关联,在SHIRO-550的利用方式中又看到了利用ysoserial中的JRMP exploit,然后又想起了RMI、JNDI、LDAP、JMX、JMS这些词。这些东西也看到了几次,也看过对应的文章,但把他们联想在一起时这些概念又好像交叉了一样容易混淆。网上的一些资料也比较零散与混乱,所以即使以前看过,没有放在一起看的话很容易混淆。下面是对RMI、JNDI、LDAP、JRMP、JMX、JMS一些资料的整理。
log4j支持jndi,可以远程调用rmi和ldap,由于rmi和idap本身存在漏洞,因此log4j就会简介触发rmi和idap
主要关注到/ApiTest/post控制器,接收了传入的数据参数,并且使用JSON.parseObject函数解析数据,从而触发fastjson反序列化,
pom.xml,maven中添加此组件会自动加载mchange-commons-java这个包
当输入期间意外终止文件或流时,将抛出“EOFException”。 以下是抛出EOFException异常的一个示例,来自JavaBeat应用程序:
最近据说爆出来一个在hw期间使用的fastjson 漏洞,该漏洞无需开启autoType即可利用成功,建议使用fastjson的用户尽快升级到> 1.2.47版本(保险起见,建议升级到最新版)
Tomcat为每个在其上运行的web应用提供了一个JNDI的** InitialContext**实现实例,它与Java EE应用服务器提供的对应类完全兼容。 Java EE标准在/WEB-INF/web.xml文件中提供了一系列标准元素,用来引用或者定义资源。
C3P0是一个开源的JDBC连接池,它实现了数据源和 JNDI 绑定,具有连接数控制、连接可靠性测试、连接泄露控制、缓存语句等功能,支持 JDBC3 规范和 JDBC2 的标准扩展。 使用它的开源项目有Hibernate、Spring等。例如在执行JDBC的增删改查的操作时,如果每一次操作都来一次打开连接,操作,关闭连接,那么创建和销毁JDBC连接的开销就太大了。为了避免频繁地创建和销毁JDBC连接,我们可以通过连接池(Connection Pool)复用已经创建好的连接。
fastjson用于将Java Bean序列化为JSON字符串,也可以从JSON字符串反序列化到JavaBean。fastjson.jar是阿里开发的一款专门用于Java开发的包,可以方便的实现json对象与JavaBean对象的转换,实现JavaBean对象与json字符串的转换,实现json对象与json字符串的转换。除了这个fastjson以外,还有Google开发的Gson包,其他形式的如net.sf.json包,都可以实现json的转换。方法名称不同而已,最后的实现结果都是一样的。
最近互联网技术圈最火的一件事莫过于Log4j2的漏洞了。同时也涌现出了各类分析文章,关于漏洞的版本、漏洞的原因、漏洞的修复、程序员因此加班等等。
前两天的 log4j 漏洞引起了安全圈的震动,虽然是二进制选手,但为了融入大家的过年氛围,还是决定打破舒适圈来研究一下 JNDI 注入漏洞。
JNDI 全名 Java Naming and Directory Interface,实际上简单来说就是一个接口,应用通过该接口来访问对应的目录服务。好吧,先了解一下目录服务是啥。
2021年11月中国软件工程师陈兆军发现了一个在Java服务中常用日志组件Log4j2的一个高危漏洞,并提交给官方。
在写完《Java中RMI、JNDI、LADP、JRMP、JMX、JMS那些事儿(上)》的时候,又看到一个包含RMI-IIOP的议题,在16年Blackhat JNDI注入议题中也提到了这个协议的利用,当时想着没太看到或听说有多少关于IIOP的漏洞(可能事实真的如此吧,在下面Weblogic RMI-IIOP部分或许能感受到),所以那篇文章写作过程中也没去看之前那个16年议题IIOP相关部分。网上没怎么看到有关于IIOP或RMI-IIOP的分析文章,这篇文章来感受下。
public interface HelloWord { public String sayHello(String name); }
但是,高端的玩家往往不会仅限于此,熟悉接口开发的同学一定知道,能将数据对象很轻松的实现多平台之间的通信、对象持久化存储,序列化和反序列化是一种非常有效的手段,例如如下应用场景,对象必须 100% 实现序列化。
在现代企业应用架构中,Java Naming and Directory Interface (JNDI) 是一个核心组件,它允许应用程序查找并使用分布式系统中的各种资源。然而,这一强大的功能若被恶意利用,则可能成为安全攻击的入口点,特别是当涉及到远程代码执行(RCE)时。本文将深入探讨JNDI注入攻击,特别是如何对JNDI流量数据进行解密,并通过真实案例和代码示例展示其潜在风险及防御策略。
2021 年 11 月 24 日,阿里云安全团队向 Apache 官方报告了 Apache Log4j2 远程代码执行漏洞,在 12 月 9 日被国外有人公开 POC,从而导致了一波安全从业人员的疯狂运动,甲方安全从业者加班加点修复漏洞;白帽子们疯狂扫描漏洞并提交 SRC,一度导致一些 SRC 发布公告暂停接收相关漏洞;而黑灰产们已经在自己的挖矿勒索武器库上增加了该漏洞的利用模块。为什么会这么疯狂?
相信大家最近一定被 log4j2 的远程代码执行漏洞所刷屏了,各个互联网厂商,开源组织,还有相关企业都瑟瑟发抖,相关研发人员也都是加班加点紧急修复和改正。笔者也看了一些相关文章,感觉不少都是刷屏,刷阅读量,甚至是做相关广告的,详细介绍的少之又少。这里写一篇文章,详细介绍 log4j2 RCE 漏洞复现步骤以及根因,纯粹是以学习为目的。log4j2 RCE 漏洞总体来说是通过 JNDI 注入来完成的,具体的有 RMI 协议的方式和 LDAP 协议等不同方式,这里以 RMI 方式为例子做详细复现步骤和根因分析(不了解 JNDI/RMI/LDAP 等相关概念的同学请自 Google)。
写在前面 Hibernate是一个开源免费的、基于 ORM 技术的 Java 持久化框架。通俗地说,Hibernate 是一个用来连接和操作数据库的 Java 框架,它最大的优点是使用了 ORM 技术。 Hibernate 支持几乎所有主流的关系型数据库,只要在配置文件中设置好当前正在使用的数据库,程序员就不需要操心不同数据库之间的差异。 分析 对于Hibernate框架的反序列化链主要是通过调用了任意的getter方法,结合TemplatesImpl这条链子进行利用链的构造。 BasicPro
经过一周时间的 log4j2 RCE 事件的发酵,事情也变也越来越复杂和有趣,就连 log4j 官方紧急发布了 2.15.0 版本之后没有过多久,又发声明说 2.15.0 版本也没有完全解决问题,然后进而继续发布了 2.16.0 版本。刚刚熬夜费劲升级了 2.15.0 版本的小伙伴们是不是心中一万个小羊驼奔过。然而在网络上也有各种文章和博客进行激烈的讨论,例如高版本的 JDK 也可以避免,开启 formatMsgNolookups 的方案,还有log4j1 可以幸免于难等等各种说法。在这里笔者针对这些讨论详细介绍一下,JDK 高版本是否可以避免,开启 formatMsgNolookups 的方案是否可行,log4j1 是否真的可以幸免于难。
2021 年 12 月 9 日,2021 年 11 月 24 日,阿里云安全团队向 Apache 官方报告了 Apache Log4j2 远程代码执行漏洞。详情见 【漏洞预警】Apache Log4j 远程代码执行漏洞
几个月以前,趋势科技发现了APT组织Pawn Storm利用之前未经披露的Java漏洞(CVE-2015-2590)进行攻击。在那之后,我们注意到一个被用于染过Java点击播放(click-to-play)保护的独立漏洞。 第二个漏洞(CVE-2015-4902)现在已经在Oracle定期的季度更新中被修复,并将此归功于趋势科技的发现。 FreeBuf百科:Click-to-play Click-to-play要求用户在Java应用程序执行之前,在空白处单击一下。实际上,它要求用户只有在十分确定需要运行Ja
Java Naming and Directory Interface,Java命名和目录接口
模型 ----- Model 视图 ----- View 控制器 ----- Controller
介绍什么的就不说了,简介以及1.2.24的复现和详细分析可以看 Java反序列化(十) | Fastjson – CVE-2017-18349
H2 是一种非常流行的开源 Java SQL 数据库,它提供了一种不需要将数据存储在磁盘上的轻量级内存解决方案。这使得从网络平台的各种项目流行的数据存储解决方案,如ThingWorks。该com.h2database:H2包是前50名最受欢迎的Maven包的一部分,几乎7000工件依赖关系。
在程序中获取数据源,通过jndi,这个jndi必须在Servlet中才能获取,并且需要配置web.xml使servlet一启动就拿到数据源
web项目中有时候客户要求我们使用ad域进行身份确认,不再另外做一套用户管理系统。其实客户就是只要一套账号可以访问所有的OA,CRM等办公系统。 这就是第三方验证。一般有AD域,Ldap,Radius,邮件服务器等。最常用的要数AD域了。因为window系统在国内占据了大量的江山。做起来也很方便。 我这篇文章就是写,如何用java去实现AD域的身份验证。好了,直接看代码吧:
上述下载的GlassFish为开源版本,文档见GlassFish Server Documentation。
Apache log4j是Apache的一个开源项目,Java的日志记录工具(同logback)。
WebLogic是美国Oracle公司出品的一个application server确切的说是一个基于JAVAEE架构的中间件,BEA WebLogic是用于开发、集成、部署和管理大型分布式Web应用、网络应用和数据库应用的Java应用服务器。
前段时间发生的 Log4j2 漏洞事件着实让人有点蛋疼,可以说是值得广大中国企业技术人员纪念的日子。在修复漏洞的过程中,让人看到的是:在风险面前,我们的系统就像一个裸奔的男人站在海边,被海风肆意地虐打着,毫无反抗力……
Spring Boot Actuator端点通过 JMX 和HTTP 公开暴露给外界访问,大多数时候我们使用基于HTTP的Actuator端点,因为它们很容易通过浏览器、CURL命令、shell脚本等方式访问。
Java 序列化及反序列化处理在基于Java 架构的Web应用中具有尤为重要的作用。例如位于网络两端、彼此不共享内存信息的两个Web应用在进行远程通信时,无论相互间发送何种类型的数据,在网络中实际上都是以二进制序列的形式传输的。为此,发送方必须将要发送的Java 对象序列化为字节流,接收方则需要将字节流再反序列化还原得到Java 对象,才能实现正常通信。当攻击者输入精心构造的字节流被反序列化为恶意对象时,就会造成一系列的安全问题。
JNDI的全称是java命名与目录接口(Java Naming and Directory Interface),是一个应用程序设计的API,为开发人员提供了查找和访问各种命名和目录服务的通用、统一的接口。我们可以把JNDI简单地理解为是一种将对象和名字绑定的技术,即指定一个资源名称,将该名称与某一资源或服务相关联,当需要访问其他组件和资源时,就需要使用JNDI服务进行定位,应用程序可以通过名字获取对应的对象或服务。 JNDI方式 - 配置Tomcat6.0 连接池 数据库连接池的基本思想就是为数据库连
大家好,又见面了,我是你们的朋友全栈君。 最近因为项目需要,对ilog进行了学习,包括ilog在was的安装以及客户端连接ilog等内容。 个人感觉很多是通过ejb来进行查找及调用的,所以,特意自己做了一个ejb在was上部署以及客户端连接的例子: [b][color=red]1、ejb方面[/color][/b] ejb采用ejb 2,分三个类:Hello、HelloHome、HelloWord; [color=cyan]Hello:[/color] public class Hello implements SessionBean { /** The session context */ private SessionContext context; public Hello() { super(); // TODO Auto-generated constructor stub } /** * Set the associated session context. The container calls this method * after the instance creation. * * The enterprise bean instance should store the reference to the context * object in an instance variable. * * This method is called with no transaction context. * * @throws EJBException Thrown if method fails due to system-level error. */ public void setSessionContext(SessionContext newContext) throws EJBException { context = newContext; } public void ejbCreate() throws EJBException, RemoteException { // TODO Auto-generated method stub System.out.println(“ejb create”); } public void ejbRemove() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbActivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbPassivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } /** * An example business method * * @ejb.interface-method view-type = “remote” * * @throws EJBException Thrown if method fails due to system-level error. */ public String sayIt() throws EJBException { System.out.println(“hello didi”); return “hello didi.”; } } [color=cyan][b]HelloHome[/b][/color] public interface HelloHome extends javax.ejb.EJBHome { public com.rox.HelloWorld create() throws javax.ejb.CreateException,java.rmi.RemoteException; } [color=cyan]HelloWorld[/color] public interface HelloWorld extends EJBObject{ public String sayIt() throws RemoteException; } [color=red][b]2、发布ejb到was中[/b][/color] 注意:在ejb的jndi项,填写e
序列化与反序列化是让Java对象脱离Java运行环境的一种手段,可以有效的实现多平台之间的通信、对象持久化存储。主要应用在以下场景:
如果在android平台连接activemq服务,应该怎么实现呢?大部分网上的文章都是eclipse 提供的paho MQTT client实现。如果你只是用消息发布/订阅功能,那么用paho MQTT client就足够了。 但是MQTT协议只支持消息发布/订阅,所以如果你需要使用生产者/消费者模型,就不能用MQTT协议了。 我就遇到这样的需求,需要在android平台以消费者身份接收消息队列的数据。于是我尝试使用activemq提供的activemq-client库来连接activemq服务.
领取专属 10元无门槛券
手把手带您无忧上云