package jbossexploit;

import org.apache.commons.cli.*;

public class Cli {

    public static org.apache.commons.cli.CommandLine parseArguments(String[] args) {
        // Set up CLI options

        Option help = new Option("help",  "print this message");
        Option rhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("Target Hostname or IP Address")
                .create("rhost");

        Option rport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Remote JBoss Port")
                .create("rport");

        Option lhost = OptionBuilder.withArgName("host")
                .hasArg()
                .withDescription("IP Address of Attacking Machine")
                .create("lhost");

        Option lport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port on which local handler is listening for a reverse TCP shell")
                .create("lport");

        Option srvport = OptionBuilder.withArgName("port")
                .hasArg()
                .withDescription("Port for local HTTP server")
                .create("srvport");

        Options options = new Options();

        options.addOption(help);
        options.addOption(rhost);
        options.addOption(rport);
        options.addOption(lhost);
        options.addOption(lport);
        options.addOption(srvport);

        CommandLineParser parser = new DefaultParser();
        org.apache.commons.cli.CommandLine cmd = null;
        try {
            cmd = parser.parse(options, args);
        } catch (Exception e) {
            System.out.println("Error parsing arguments.");
            System.exit(1);
        }

        // TODO: Print usage if no arguments are called from CLI
        if (cmd.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar JBossExploit.jar -lhost <host> -lport <port> -rhost <host> -rport <port> -srvport <port>",
                    options);
            System.exit(0);
        }

        return cmd;
    }
}

@@ -229,17 +229,17 @@
 elp%22,  %22
-p
+P
 rint thi
@@ -1752,73 +1752,8 @@
  %7D%0A%0A
-        // TODO: Print usage if no arguments are called from CLI%0A
     
@@ -1781,16 +1781,36 @@
 (%22help%22)
+ %7C%7C args.length == 0
 ) %7B%0A    

Print help menu when no args are passed from the CLI