【聲明】:文中涉及到的相關漏洞均爲官方已經公開並修復的漏洞,涉及到的安全技術也僅用於安全對抗技術研究。本文僅限業內技術研究與討論,嚴禁用於非法用途,否則產生的一切後果自行承擔。
環境準備
-
- 搭建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)執行效果
可以看到,簡單的記錄日誌就能觸發。這個漏洞還是比較嚴重的,建議大家儘快排查,按照官網指導修復這個漏洞。