Apache Kafka 反序列化漏洞分析
1.背景概述
Apache Kafka
是用于构建实时数据流水线和流媒体的应用服务。它具有水平可扩展性,容错性,目前有数千家公司使用其产品。
2017 年 7 月 19 日曝出,Apache kafka connect-api
,在执行 FileOffsetBackingStore
类可实现一个反序列化漏洞,这将导致远程代码执行。
其代码开源于 Apache 官方 Github:https://github.com/apache/kafka/
2.原理分析
2.1漏洞简析
在Apache Kafka 0.11.0.0
中,org.apache.kafka.connect.storage.FileOffsetBackingStore
这个 class 主要实现了将数据保存到本地文件功能。同时也提供了一个反序列化接口。
查看 FileOffsetBackingStore.java
源码:
通过 configure(WorkerConfig config)
函数读取文件
随后文件在 load()
函数利用 ObjectInputStream
类加载,随后调用 readObject()
方法进行反序列化。
发现 FileOffsetBackingStore
在反序列化过程中,直接调用了 java.io.ObjectInputStream
类的 readObject()
方法,没有对传入参数进行验证。这将允许攻击者构造反序列化对象并执行恶意代码。
2.2漏洞复现
对于此类反序列化漏洞的利用方式有很多,可以先使用较简单的方式复现,以便分析:
首先,查阅Java官方文档:
发现对于 readObject()
方法有以下描述:
Read an object from the ObjectInputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are read. Default deserializing for a class can be overriden using the writeObject and readObject methods. Objects referenced by this object are read transitively so that a complete equivalent graph of objects is reconstructed by readObject.
The root object is completely restored when all of its fields and the objects it references are completely restored. At this point the object validation callbacks are executed in order based on their registered priorities. The callbacks are registered by objects (in the readObject special methods) as they ar