概述
RMI(Remote Method Invocation) :远程方法调用
它使客户机上运行的程序可以通过网络实现调用远程服务器上的对象,要实现RMI,客户端和服务端需要共享同一个接口。
基础
Client 和 Regisry 基于 Stub 和 Skeleton 进行通信,分别对应 RegistryImpl_Stub 和
RegistryImpl_Skel 两个类。

示例
- 一个可以远程调用的接口,实现了 Remote 接口
package pers.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
//定义一个能够远程调用的接口,并且需要扩展Remote接口
public interface RemoteInterface extends Remote {
public String CaseBegin() throws RemoteException;
public String CaseBegin(Object demo) throws RemoteException;
public String CaseOver() throws RemoteException;
}
- 实现了接口的类
package pers.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
//远程可以调用的类,需要继承UnicastRemoteObject类和实现RemoteInterface接口
//也可以指定需要远程调用的类,可以使用UnicastRemoteObject类中的静态方法exportObject指定调用类
public class RemoteObject extends UnicastRemoteObject implements RemoteInterface {
protected RemoteObject() throws RemoteException {
super();
}
@Override
public String CaseBegin() {
return "Hello world!";
}
@Override
public String CaseBegin(Object demo) {
return demo.getClass().getName();
}
@Override
public String CaseOver() {
return "Good bye!";
}
}
- 远程服务端,其中附带了注册中心
package pers.rmi;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RemoteServer {
public static void main(String[] args) throws RemoteException, MalformedURLException, AlreadyBoundException {
LocateRegistry.createRegistry(1099);
//将需要调用的类进行绑定
//创建远程类
RemoteObject remoteObject = new RemoteObject();
//获取注册中心
Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1099);
//绑定类
registry.bind("test", remoteObject);
}
}
- 尝试构建一个客户端使用RMI协议
package pers.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class RMIClient {
public static void main(String[] args) throws MalformedURLException, NotBoundException, RemoteException {
RemoteInterface remoteInterface = (RemoteInterface) Naming.lookup("rmi://127.0.0.1:1099/test");
String s = remoteInterface.CaseBegin();
System.out.println(s);
}
}

能够使用。
Attacks
Registry Attacked By Server
Server 端在执行 bind 或者 rebind 方法的

本文详细介绍了RMI(远程方法调用)攻击中的Registry攻击,包括服务器端通过bind或rebind方法触发的反序列化漏洞,以及客户端通过lookup方法的潜在利用。文中分析了攻击流程,并提供了相关调用栈和实现步骤,为理解此类攻击提供了深入的解析。
最低0.47元/天 解锁文章
1750

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



