From 967ee9e54b4c2c87563fb0fd92099f3dbe6a81d2 Mon Sep 17 00:00:00 2001 From: Tobias Neitzel Date: Sun, 21 Jan 2024 18:07:21 +0100 Subject: [PATCH] Add SubparserGroups for plugins When plugins add actions to rmg, these are now separately grouped to make them distinguishable from the native actions. --- pom.xml | 2 +- .../rmg/internal/ArgumentHandler.java | 1 + src/eu/tneitzel/rmg/operations/Operation.java | 13 +++++++++ .../rmg/operations/OperationGroup.java | 29 +++++++++++++++++++ src/eu/tneitzel/rmg/plugin/PluginSystem.java | 11 ++++++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/eu/tneitzel/rmg/operations/OperationGroup.java diff --git a/pom.xml b/pom.xml index ce1395c..9142ac8 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ eu.tneitzel argparse4j - 1.1.0 + 1.2.0 diff --git a/src/eu/tneitzel/rmg/internal/ArgumentHandler.java b/src/eu/tneitzel/rmg/internal/ArgumentHandler.java index 4ee4681..6f5add6 100644 --- a/src/eu/tneitzel/rmg/internal/ArgumentHandler.java +++ b/src/eu/tneitzel/rmg/internal/ArgumentHandler.java @@ -55,6 +55,7 @@ public ArgumentHandler(String[] argv) { parser = ArgumentParsers.newFor("remote-method-guesser").build(); parser.description("rmg v" + ArgumentHandler.class.getPackage().getImplementationVersion() + " - a Java RMI Vulnerability Scanner"); + parser.addArgument("--plugin").help("file system path of a rmg plugin"); ActionContext ctx = Operation.getActionContext(); Subparsers subParsers = ctx.addSubparsers(parser); diff --git a/src/eu/tneitzel/rmg/operations/Operation.java b/src/eu/tneitzel/rmg/operations/Operation.java index 90bf0e2..cbfc83a 100644 --- a/src/eu/tneitzel/rmg/operations/Operation.java +++ b/src/eu/tneitzel/rmg/operations/Operation.java @@ -4,9 +4,11 @@ import eu.tneitzel.argparse4j.global.ActionContext; import eu.tneitzel.argparse4j.global.IAction; +import eu.tneitzel.argparse4j.global.IActionGroup; import eu.tneitzel.argparse4j.global.IOption; import eu.tneitzel.rmg.internal.ExceptionHandler; import eu.tneitzel.rmg.internal.RMGOption; +import eu.tneitzel.rmg.plugin.PluginSystem; /** * The Operation enum class contains one item for each possible rmg action. An enum item consists out of @@ -435,6 +437,17 @@ public static ActionContext getActionContext() return new ActionContext("action", " ", " ", Operation.values()); } + @Override + public IActionGroup getGroup() + { + if (PluginSystem.getPluginActions().length != 0) + { + return OperationGroup.NATIVE; + } + + return null; + } + @Override public String getName() { diff --git a/src/eu/tneitzel/rmg/operations/OperationGroup.java b/src/eu/tneitzel/rmg/operations/OperationGroup.java new file mode 100644 index 0000000..a836341 --- /dev/null +++ b/src/eu/tneitzel/rmg/operations/OperationGroup.java @@ -0,0 +1,29 @@ +package eu.tneitzel.rmg.operations; + +import eu.tneitzel.argparse4j.global.IActionGroup; + +/** + * When plugins implement IActionProvider, they can add additional arguments + * to rmg. In this case, we use the IActionGroup to distinguish from plugin and + * native actions. + * + * @author Tobias Neitzel (@qtc_de) + */ +public enum OperationGroup implements IActionGroup +{ + NATIVE("actions:"), + PLUGIN("plugin actions:"); + + private final String name; + + OperationGroup(String name) + { + this.name = name; + } + + @Override + public String getName() + { + return name; + } +} diff --git a/src/eu/tneitzel/rmg/plugin/PluginSystem.java b/src/eu/tneitzel/rmg/plugin/PluginSystem.java index 5eafac0..d36f105 100644 --- a/src/eu/tneitzel/rmg/plugin/PluginSystem.java +++ b/src/eu/tneitzel/rmg/plugin/PluginSystem.java @@ -10,12 +10,14 @@ import java.util.jar.Manifest; import eu.tneitzel.argparse4j.global.IAction; +import eu.tneitzel.argparse4j.inf.SubparserContainer; import eu.tneitzel.argparse4j.inf.Subparsers; import eu.tneitzel.rmg.exceptions.MalformedPluginException; import eu.tneitzel.rmg.internal.ExceptionHandler; import eu.tneitzel.rmg.internal.RMGOption; import eu.tneitzel.rmg.io.Logger; import eu.tneitzel.rmg.operations.Operation; +import eu.tneitzel.rmg.operations.OperationGroup; import eu.tneitzel.rmg.utils.RMGUtils; /** @@ -323,7 +325,14 @@ public static void addPluginActions(Subparsers parser) { for (IAction action : getPluginActions()) { - action.addSuparser(parser); + SubparserContainer container = parser; + + if (action.getGroup() == null) + { + container = parser.getOrCreateSubparserGroup(OperationGroup.PLUGIN.getName()); + } + + action.addSuparser(container); } } }