From 314bb4c37c80e931f62e5e3bbf4195ef755b98a0 Mon Sep 17 00:00:00 2001
From: ca-syn <84011044+cas1n@users.noreply.github.com>
Date: Tue, 30 Jan 2024 17:15:39 +0100
Subject: [PATCH 1/3] Add parameterized payloads
* Add supplementary arguments for internal translet based payloads
* Add supplementary arguments for Transformer payloads
* Make CommonsBeanutils1 silent using NullComparator
---
pom.xml | 7 +-
src/main/java/ysoserial/GeneratePayload.java | 45 +++-
src/main/java/ysoserial/Strings.java | 17 ++
src/main/java/ysoserial/payloads/Click1.java | 7 +-
.../ysoserial/payloads/CommonsBeanutils1.java | 17 +-
.../payloads/CommonsCollections1.java | 19 +-
.../payloads/CommonsCollections2.java | 6 +-
.../payloads/CommonsCollections3.java | 14 +-
.../payloads/CommonsCollections4.java | 8 +-
.../payloads/CommonsCollections5.java | 18 +-
.../payloads/CommonsCollections6.java | 21 +-
.../payloads/CommonsCollections7.java | 23 +-
src/main/java/ysoserial/payloads/Groovy1.java | 2 +-
.../java/ysoserial/payloads/Hibernate1.java | 11 +-
.../payloads/JBossInterceptors1.java | 13 +-
src/main/java/ysoserial/payloads/JSON1.java | 7 +-
.../ysoserial/payloads/JavassistWeld1.java | 13 +-
src/main/java/ysoserial/payloads/Jdk7u21.java | 7 +-
.../ysoserial/payloads/MozillaRhino1.java | 8 +-
.../ysoserial/payloads/MozillaRhino2.java | 7 +-
.../payloads/ParameterizedObjectPayload.java | 38 +++
...arameterizedTransformersObjectPayload.java | 216 ++++++++++++++++++
.../ParameterizedTransletObjectPayload.java | 154 +++++++++++++
src/main/java/ysoserial/payloads/ROME.java | 8 +-
src/main/java/ysoserial/payloads/Spring1.java | 11 +-
src/main/java/ysoserial/payloads/Spring2.java | 8 +-
src/main/java/ysoserial/payloads/Vaadin1.java | 19 +-
.../java/ysoserial/payloads/util/Gadgets.java | 114 +++++++--
28 files changed, 666 insertions(+), 172 deletions(-)
create mode 100644 src/main/java/ysoserial/payloads/ParameterizedObjectPayload.java
create mode 100644 src/main/java/ysoserial/payloads/ParameterizedTransformersObjectPayload.java
create mode 100644 src/main/java/ysoserial/payloads/ParameterizedTransletObjectPayload.java
diff --git a/pom.xml b/pom.xml
index 69bb2a5f..7833b849 100644
--- a/pom.xml
+++ b/pom.xml
@@ -177,6 +177,11 @@
remoting-jmx
2.0.1.Final
+
+ commons-cli
+ commons-cli
+ 1.6.0
+
@@ -444,5 +449,5 @@
GitHub Packages
https://maven.pkg.github.com/frohoff/ysoserial
-
+
diff --git a/src/main/java/ysoserial/GeneratePayload.java b/src/main/java/ysoserial/GeneratePayload.java
index 88776f34..ca9f7403 100644
--- a/src/main/java/ysoserial/GeneratePayload.java
+++ b/src/main/java/ysoserial/GeneratePayload.java
@@ -3,8 +3,10 @@
import java.io.PrintStream;
import java.util.*;
+import org.apache.commons.cli.ParseException;
import ysoserial.payloads.ObjectPayload;
import ysoserial.payloads.ObjectPayload.Utils;
+import ysoserial.payloads.ParameterizedObjectPayload;
import ysoserial.payloads.annotation.Authors;
import ysoserial.payloads.annotation.Dependencies;
@@ -14,12 +16,12 @@ public class GeneratePayload {
private static final int USAGE_CODE = 64;
public static void main(final String[] args) {
- if (args.length != 2) {
+ if (args.length == 0) {
printUsage();
System.exit(USAGE_CODE);
}
final String payloadType = args[0];
- final String command = args[1];
+ final String[] payloadArgs = Arrays.copyOfRange(args, 1, args.length);
final Class extends ObjectPayload> payloadClass = Utils.getPayloadClass(payloadType);
if (payloadClass == null) {
@@ -31,7 +33,42 @@ public static void main(final String[] args) {
try {
final ObjectPayload payload = payloadClass.newInstance();
- final Object object = payload.getObject(command);
+ if(payloadArgs.length == 0) {
+ if (payload instanceof ParameterizedObjectPayload) {
+ System.err.println(((ParameterizedObjectPayload) payload).getHelp());
+ } else {
+ System.err.println("Usage: java -jar ysoserial-[version]-all.jar "+ payloadType +" '[command]'");
+ }
+ System.exit(USAGE_CODE);
+ return;
+ }
+ final Object object;
+ if (payload instanceof ParameterizedObjectPayload) {
+ ParameterizedObjectPayload parameterizedPayload = (ParameterizedObjectPayload)payload;
+ try {
+ object = parameterizedPayload.getObject(payloadArgs);
+ } catch (ParseException e) {
+ System.err.println("Error: " + e.getMessage());
+ System.err.println(parameterizedPayload.getHelp());
+ System.exit(USAGE_CODE);
+ return;
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() != null) {
+ System.err.println("Error: " + e.getMessage());
+ }
+ System.err.println(parameterizedPayload.getHelp());
+ System.exit(USAGE_CODE);
+ return;
+ }
+ } else {
+ if (payloadArgs.length > 1) {
+ System.err.println("Error: the payload '" + payloadType + "' does not support multiple arguments");
+ printUsage();
+ System.exit(USAGE_CODE);
+ return;
+ }
+ object = payload.getObject(payloadArgs[0]);
+ }
PrintStream out = System.out;
Serializer.serialize(object, out);
ObjectPayload.Utils.releasePayload(payload, object);
@@ -45,7 +82,7 @@ public static void main(final String[] args) {
private static void printUsage() {
System.err.println("Y SO SERIAL?");
- System.err.println("Usage: java -jar ysoserial-[version]-all.jar [payload] '[command]'");
+ System.err.println("Usage: java -jar ysoserial-[version]-all.jar [payload] [arguments ...]");
System.err.println(" Available payload types:");
final List> payloadClasses =
diff --git a/src/main/java/ysoserial/Strings.java b/src/main/java/ysoserial/Strings.java
index 84c21971..1289d5e6 100644
--- a/src/main/java/ysoserial/Strings.java
+++ b/src/main/java/ysoserial/Strings.java
@@ -21,6 +21,10 @@ public static String join(Iterable strings, String sep, String prefix, S
return sb.toString();
}
+ public static String join(Iterable strings, String sep) {
+ return Strings.join(strings, sep, null, null);
+ }
+
public static String repeat(String str, int num) {
final String[] strs = new String[num];
Arrays.fill(strs, str);
@@ -49,6 +53,19 @@ public static List formatTable(List rows) {
return lines;
}
+ public static String escapeJavaString(String str) {
+ return str.replace("\\", "\\\\")
+ .replace("\"", "\\\"");
+ }
+
+ public static String[] escapeJavaStrings(String[] strs) {
+ String[] res = new String[strs.length];
+ for(int i = 0; i < res.length; ++i) {
+ res[i] = escapeJavaString(strs[i]);
+ }
+ return res;
+ }
+
public static class ToStringComparator implements Comparator