【声明】:文中涉及到的相关漏洞均为官方已经公开并修复的漏洞,涉及到的安全技术也仅用于安全对抗技术研究。本文仅限业内技术研究与讨论,严禁用于非法用途,否则产生的一切后果自行承担。
环境准备
-
- 搭建openldap服务器
-
- 在ldap服务端导入java.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/java.ldif
操作步骤
1. 将java对象序列化到文件中
如下代码,会将一个Person的对象,序列化到E:\tmp\javaobj.data中。
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class ObjectUtils {
public static void main(String[] args) throws IOException {
serialize(new Person("tom", 20), "E:\\tmp\\javaobj.data");
}
public static void serialize(Object obj, String filePath) throws IOException {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filePath))) {
oos.writeObject(obj);
}
}
}
2. 在oepnldap上创建一个javaobject的条目
其中javaSerializedData为上一步生成的那个文件二进制内容。
3. 通过JNDI从ldap上加载这个对象
import javax.naming.Context;
import javax.naming.directory.*;
import java.util.Hashtable;
public class TestJavaObj {
public static void main(String[] args) {
DirContext context = null;
try {
context = new InitialDirContext();
Person obj = (Person) context.lookup("ldap://127.0.0.1:389/cn=javaldap,ou=bbb,dc=aaa,dc=com");
System.out.println(obj.getName() + "," + obj.getAge());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (context != null) {
try {
context.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
运行结果:
log4j2漏洞复现
- log4j2版本:2.12.0
复现步骤
1)在上述Person的代码的static块中增加调用系统命令
2)使用log4j2 API记录日志
3)执行效果
可以看到,简单的记录日志就能触发。这个漏洞还是比较严重的,建议大家尽快排查,按照官网指导修复这个漏洞。