Skip to content

Commit

Permalink
Add SubparserGroups for plugins
Browse files Browse the repository at this point in the history
When plugins add actions to rmg, these are now separately grouped to
make them distinguishable from the native actions.
  • Loading branch information
qtc-de committed Jan 21, 2024
1 parent 8b39300 commit 967ee9e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>eu.tneitzel</groupId>
<artifactId>argparse4j</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>

<dependency>
Expand Down
1 change: 1 addition & 0 deletions src/eu/tneitzel/rmg/internal/ArgumentHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/eu/tneitzel/rmg/operations/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
29 changes: 29 additions & 0 deletions src/eu/tneitzel/rmg/operations/OperationGroup.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 10 additions & 1 deletion src/eu/tneitzel/rmg/plugin/PluginSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 967ee9e

Please sign in to comment.