From aa9637a6b2ed575967cccfafc0feeab4c767c4f5 Mon Sep 17 00:00:00 2001 From: Tobias Neitzel Date: Tue, 3 Oct 2023 08:22:07 +0200 Subject: [PATCH] Small formatting changes --- src/de/qtc/rmg/Starter.java | 8 +- src/de/qtc/rmg/endpoints/KnownEndpoint.java | 8 +- .../rmg/endpoints/KnownEndpointHolder.java | 24 ++-- src/de/qtc/rmg/endpoints/Vulnerability.java | 4 +- .../exceptions/MalformedPluginException.java | 7 +- src/de/qtc/rmg/exceptions/SSRFException.java | 6 +- .../UnexpectedCharacterException.java | 8 +- src/de/qtc/rmg/internal/ArgumentHandler.java | 122 ++++++++++++------ 8 files changed, 121 insertions(+), 66 deletions(-) diff --git a/src/de/qtc/rmg/Starter.java b/src/de/qtc/rmg/Starter.java index 47e40a5d..e030896e 100644 --- a/src/de/qtc/rmg/Starter.java +++ b/src/de/qtc/rmg/Starter.java @@ -11,10 +11,10 @@ * * @author Tobias Neitzel (@qtc_de) */ -public class Starter { - - public static void main(String[] argv) { - +public class Starter +{ + public static void main(String[] argv) + { ArgumentHandler handler = new ArgumentHandler(argv); Operation operation = handler.getAction(); diff --git a/src/de/qtc/rmg/endpoints/KnownEndpoint.java b/src/de/qtc/rmg/endpoints/KnownEndpoint.java index 6972bc7c..ea902641 100644 --- a/src/de/qtc/rmg/endpoints/KnownEndpoint.java +++ b/src/de/qtc/rmg/endpoints/KnownEndpoint.java @@ -16,8 +16,8 @@ * * @author Tobias Neitzel (@qtc_de) */ -public class KnownEndpoint { - +public class KnownEndpoint +{ private String name; private String description; @@ -96,9 +96,13 @@ public void printEnum() String format = String.format("(known class: %s)", name); if( vulnerabilities.size() == 0 ) + { Logger.printlnPlainGreen(format); + } else + { Logger.printlnPlainYellow(format); + } } } diff --git a/src/de/qtc/rmg/endpoints/KnownEndpointHolder.java b/src/de/qtc/rmg/endpoints/KnownEndpointHolder.java index 6d6aca97..5f7c8b94 100644 --- a/src/de/qtc/rmg/endpoints/KnownEndpointHolder.java +++ b/src/de/qtc/rmg/endpoints/KnownEndpointHolder.java @@ -15,8 +15,8 @@ * * @author Tobias Neitzel (@qtc_de) */ -public class KnownEndpointHolder { - +public class KnownEndpointHolder +{ private List knownEndpoints = null; private static KnownEndpointHolder instance = null; @@ -53,13 +53,18 @@ public void setKnownEndpoints(List knownEndpoints) */ public KnownEndpoint lookup(String className) { - if( knownEndpoints == null ) + if (knownEndpoints == null) + { return null; + } - for( KnownEndpoint endpoint : knownEndpoints ) - - if( endpoint.getClassName().contains(className) ) + for (KnownEndpoint endpoint : knownEndpoints) + { + if (endpoint.getClassName().contains(className)) + { return endpoint; + } + } return null; } @@ -73,8 +78,10 @@ public KnownEndpoint lookup(String className) */ public boolean isKnown(String className) { - if( lookup(className) == null ) + if (lookup(className) == null) + { return false; + } return true; } @@ -92,7 +99,8 @@ public boolean isKnown(String className) */ public static KnownEndpointHolder getHolder() { - if( instance == null ) { + if (instance == null) + { Yaml yaml = new Yaml(new Constructor(KnownEndpointHolder.class)); InputStream stream = KnownEndpoint.class.getResourceAsStream(resource); diff --git a/src/de/qtc/rmg/endpoints/Vulnerability.java b/src/de/qtc/rmg/endpoints/Vulnerability.java index 0b34a23f..8a205fcc 100644 --- a/src/de/qtc/rmg/endpoints/Vulnerability.java +++ b/src/de/qtc/rmg/endpoints/Vulnerability.java @@ -10,8 +10,8 @@ * * @author Tobias Neitzel (@qtc_de) */ -public class Vulnerability { - +public class Vulnerability +{ private String name; private String description; diff --git a/src/de/qtc/rmg/exceptions/MalformedPluginException.java b/src/de/qtc/rmg/exceptions/MalformedPluginException.java index 8e978e69..f9b12bad 100644 --- a/src/de/qtc/rmg/exceptions/MalformedPluginException.java +++ b/src/de/qtc/rmg/exceptions/MalformedPluginException.java @@ -8,13 +8,14 @@ * * @author Tobias Neitzel (@qtc_de) */ -public class MalformedPluginException extends Exception { - +public class MalformedPluginException extends Exception +{ private static final long serialVersionUID = 1L; public MalformedPluginException() {} - public MalformedPluginException(String message) { + public MalformedPluginException(String message) + { super(message); } } diff --git a/src/de/qtc/rmg/exceptions/SSRFException.java b/src/de/qtc/rmg/exceptions/SSRFException.java index 3ed7b264..97f6c2b5 100644 --- a/src/de/qtc/rmg/exceptions/SSRFException.java +++ b/src/de/qtc/rmg/exceptions/SSRFException.java @@ -2,7 +2,7 @@ import java.io.Serializable; -public class SSRFException extends Exception implements Serializable { - +public class SSRFException extends Exception implements Serializable +{ private static final long serialVersionUID = 1L; -} +} \ No newline at end of file diff --git a/src/de/qtc/rmg/exceptions/UnexpectedCharacterException.java b/src/de/qtc/rmg/exceptions/UnexpectedCharacterException.java index c573ac8f..4461234d 100644 --- a/src/de/qtc/rmg/exceptions/UnexpectedCharacterException.java +++ b/src/de/qtc/rmg/exceptions/UnexpectedCharacterException.java @@ -14,10 +14,12 @@ * @author Tobias Neitzel (@qtc_de) */ @SuppressWarnings("serial") -public class UnexpectedCharacterException extends Exception { +public class UnexpectedCharacterException extends Exception +{ public UnexpectedCharacterException() {} - public UnexpectedCharacterException(String message) { + public UnexpectedCharacterException(String message) + { super(message); } -} +} \ No newline at end of file diff --git a/src/de/qtc/rmg/internal/ArgumentHandler.java b/src/de/qtc/rmg/internal/ArgumentHandler.java index 75922788..15cf98d7 100644 --- a/src/de/qtc/rmg/internal/ArgumentHandler.java +++ b/src/de/qtc/rmg/internal/ArgumentHandler.java @@ -56,10 +56,13 @@ public ArgumentHandler(String[] argv) Subparsers subparsers = parser.addSubparsers().help(" ").metavar("action").dest("action"); Operation.addSubparsers(subparsers); - try { + try + { args = parser.parseArgs(argv); + } - } catch (ArgumentParserException e) { + catch (ArgumentParserException e) + { parser.handleError(e); System.exit(1); } @@ -78,27 +81,30 @@ private Properties loadConfig(String filename) { Properties config = new Properties(); - try { + try + { InputStream configStream = null; configStream = ArgumentParser.class.getResourceAsStream(defaultConfiguration); config.load(configStream); configStream.close(); - if( filename != null ) { + if (filename != null) + { configStream = new FileInputStream(filename); config.load(configStream); configStream.close(); } + } - } catch( IOException e ) { + catch (IOException e) + { ExceptionHandler.unexpectedException(e, "loading", ".properties file", true); } return config; } - /** * Initializes the RMGOption enum and sets some static variables depending on the specified options. */ @@ -107,14 +113,17 @@ private void initialize() config = loadConfig(args.get(RMGOption.GLOBAL_CONFIG.name)); RMGOption.prepareOptions(args, config); - if( RMGOption.GLOBAL_NO_COLOR.getBool() ) + if (RMGOption.GLOBAL_NO_COLOR.getBool()) + { Logger.disableColor(); + } - if( RMGOption.SSRF_RAW.getBool() ) + if (RMGOption.SSRF_RAW.getBool()) + { Logger.disableStdout(); + } checkPortRange(); - PluginSystem.init(RMGOption.GLOBAL_PLUGIN.getValue()); } @@ -124,12 +133,15 @@ private void initialize() */ private void checkPortRange() { - if( RMGOption.TARGET_PORT.isNull() ) + if (RMGOption.TARGET_PORT.isNull()) + { return; + } int port = RMGOption.TARGET_PORT.getValue(); - if( port < 1 || port > 65535 ) { + if (port < 1 || port > 65535) + { Logger.eprintlnMixedYellow("The specified port number", String.valueOf(port), "is out of range."); RMGUtils.exit(); } @@ -144,8 +156,10 @@ public Operation getAction() { this.action = Operation.getByName(args.getString("action")); - if( action == null ) + if (action == null) + { ExceptionHandler.internalError("ArgumentHandler.getAction", "Invalid action was specified"); + } return action; } @@ -161,20 +175,24 @@ public Operation getAction() */ public String getRegMethod() { - if( regMethod != null ) + if (regMethod != null) + { return regMethod; + } String signature = RMGOption.REG_METHOD.getValue(); String[] supported = new String[]{"lookup", "unbind", "rebind", "bind"}; - if( signature == null ) { + if (signature == null) + { regMethod = "lookup"; return regMethod; } - for(String methodName : supported ) { - - if( signature.contains(methodName) ) { + for (String methodName : supported) + { + if (signature.contains(methodName)) + { regMethod = methodName; return methodName; } @@ -198,19 +216,23 @@ public String getRegMethod() */ public String getDgcMethod() { - if( dgcMethod != null ) + if (dgcMethod != null) + { return dgcMethod; + } String signature = RMGOption.DGC_METHOD.getValue(); - if( signature == null ) { + if (signature == null) + { dgcMethod = "clean"; return dgcMethod; } - for(String methodName : new String[]{"clean", "dirty"} ) { - - if( signature.contains(methodName) ) { + for (String methodName : new String[]{"clean", "dirty"}) + { + if (signature.contains(methodName)) + { dgcMethod = methodName; return methodName; } @@ -232,16 +254,20 @@ public String getDgcMethod() */ public RMIComponent getComponent() { - if( component != null ) + if (component != null) + { return component; + } RMIComponent targetComponent = RMIComponent.getByShortName(RMGOption.TARGET_COMPONENT.getValue()); - if( targetComponent == null ) + if (targetComponent == null) + { return null; + } - switch( targetComponent ) { - + switch (targetComponent) + { case REGISTRY: case DGC: case ACTIVATOR: @@ -255,7 +281,6 @@ public RMIComponent getComponent() } component = targetComponent; - return targetComponent; } @@ -270,15 +295,17 @@ public Object getGadget() String gadget = null; String command = null; - if( this.getAction() == Operation.BIND || this.getAction() == Operation.REBIND ) { - + if (this.getAction() == Operation.BIND || this.getAction() == Operation.REBIND) + { boolean customGadget = RMGOption.BIND_GADGET_NAME.notNull(); boolean customCommand = RMGOption.BIND_GADGET_CMD.notNull(); gadget = customGadget ? RMGOption.BIND_GADGET_NAME.getValue() : "jmx"; command = customCommand ? RMGOption.BIND_GADGET_CMD.getValue() : RMGOption.require(RMGOption.BIND_ADDRESS); + } - } else { + else + { gadget = (String) RMGOption.require(RMGOption.GADGET_NAME); command = RMGOption.require(RMGOption.GADGET_CMD); } @@ -310,8 +337,10 @@ public EnumSet getScanActions() { List scanActions = (List) RMGOption.ENUM_ACTION.value; - if( scanActions == null ) + if (scanActions == null) + { return EnumSet.allOf(ScanAction.class); + } return ScanAction.parseScanActions(scanActions); } @@ -333,18 +362,23 @@ public int[] getRmiPorts() String defaultPorts = config.getProperty("rmi_ports"); List portStrings = (List)RMGOption.SCAN_PORTS.value; - if( portStrings == null ) { + if (portStrings == null) + { portStrings = new ArrayList(); portStrings.add("-"); } - for(String portString : portStrings) { - - if( portString.equals("-") ) + for (String portString : portStrings) + { + if (portString.equals("-")) + { addPorts(defaultPorts, rmiPorts); + } else + { addPorts(portString, rmiPorts); + } } return rmiPorts.stream().mapToInt(i->i).toArray(); @@ -360,7 +394,8 @@ public void addPorts(String portString, Set portList) { String[] ports = portString.split(","); - for(String port: ports) { + for (String port: ports) + { addRange(port, portList); } } @@ -373,9 +408,10 @@ public void addPorts(String portString, Set portList) */ public void addRange(String portRange, Set portList) { - try { - - if(!portRange.contains("-")) { + try + { + if (!portRange.contains("-")) + { portList.add(Integer.valueOf(portRange)); return; } @@ -384,10 +420,14 @@ public void addRange(String portRange, Set portList) int start = Integer.valueOf(split[0]); int end = Integer.valueOf(split[1]); - for(int ctr = start; ctr <= end; ctr++) + for (int ctr = start; ctr <= end; ctr++) + { portList.add(ctr); + } + } - } catch( java.lang.NumberFormatException | java.lang.ArrayIndexOutOfBoundsException e ) { + catch (java.lang.NumberFormatException | java.lang.ArrayIndexOutOfBoundsException e) + { Logger.eprintlnMixedYellow("Caught unexpected", e.getClass().getSimpleName(), "while parsing RMI ports."); Logger.eprintlnMixedBlue("The specified value", portRange, "is invalid."); RMGUtils.exit();