前言
前段时间FastJson的利用,最后使用了JNDI注入的方式 使得利用条件变得简单。
从一开始的RMI到LDAP, 都是把一个Reference对象绑定到N/D服务上, 最终实例化CodeBase远程代码库的类实现RCE。
但是这种方法在高版本jdk中已经不再能够使用, 由于TrustURLCodeBase的限制, 不再能够加载远程的代码库。
最近看几年前的BlackHat JNDI PPT时, 发现提到了除了Reference的另外几种方法。 不过没搜到EXP, 就自己看了下。
Reference的利用
N/D为LDAP
N/D服务返回Reference对象后, 服务端这边decodeReference后
尝试加载类。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
static ObjectFactory getObjectFactoryFromReference(
Reference ref, String factoryName)
throws IllegalAccessException,
InstantiationException,
MalformedURLException {
Class<?> clas =
null;
// 尝试在本地加载类。
try {
clas = helper.loadClass(factoryName);
}
catch (ClassNotFoundException e) {
// ignore and continue
// e.printStackTrace();
}
// 如果从本地加载类失败, 从远程代码库中获取。
String codebase;
if (clas ==
null &&
(codebase = ref.getFactoryClassLocation()) !=
null) {
try {
clas = helper.loadClass(factoryName, codebase);
}
catch (ClassNotFoundException e) {
}
}
return (clas !=
null) ? (ObjectFactory) clas.newInstance() :
null;
}
|
jdk1.7.0_80的 loadClass(String className, String codebase)
|
1
2
3
4
5
6
7
8
9
|
public Class loadClass(String className, String codebase)
throws ClassNotFoundException, MalformedURLException {
ClassLoader parent = getContextClassLoader();
ClassLoader cl =
URLClassLoader.newInstance(getUrlArray(codebase), parent);
return loadClass(className, cl);
}
|
直接使用URLClassLoader从远程动态加载字节码, 然后返回。
|
1
|
return (clas !=
null) ? (ObjectFactory) clas.newInstance() :
null;
|
然后实例化从远程获取到的类, 触发类的构造方法, 实现RCE。

jdk 1.8.0_191 的loadClass(String className, String codebase)
|
1
2
3
4
5
6
7
8
9
10
11
12
|
public Class<?> loadClass(String className, String cod
|

本文探讨了JNDI注入攻击的一种新方法,通过LDAP反序列化实现远程代码执行。在高版本的JDK中,由于TrustURLCodebase的限制,传统方法已不再有效。然而,作者发现当trustURLCodebase设置为false时,仍可通过反序列化绕过此限制。文中详细介绍了利用过程,并给出了可能的利用场景,如FastJson在高版本JDK下的JNDI反序列化选项,以及其他非反序列化JNDI注入情况。

最低0.47元/天 解锁文章
2631

被折叠的 条评论
为什么被折叠?



