1010package de .rub .nds .tlsattacker .attacks ;
1111
1212import com .beust .jcommander .JCommander ;
13+ import com .beust .jcommander .JCommander .Builder ;
14+ import com .beust .jcommander .ParameterException ;
1315import de .rub .nds .tlsattacker .attacks .config .*;
1416import de .rub .nds .tlsattacker .attacks .config .delegate .GeneralAttackDelegate ;
1517import de .rub .nds .tlsattacker .attacks .impl .*;
@@ -35,53 +37,81 @@ public class Main {
3537 */
3638 public static void main (String [] args ) {
3739 GeneralDelegate generalDelegate = new GeneralAttackDelegate ();
38- JCommander jc = new JCommander (generalDelegate );
40+ Builder builder = JCommander .newBuilder ().addObject (generalDelegate );
41+
3942 BleichenbacherCommandConfig bleichenbacherTest = new BleichenbacherCommandConfig (generalDelegate );
40- jc .addCommand (BleichenbacherCommandConfig .ATTACK_COMMAND , bleichenbacherTest );
43+ builder .addCommand (BleichenbacherCommandConfig .ATTACK_COMMAND , bleichenbacherTest );
4144
4245 PskBruteForcerAttackServerCommandConfig pskBruteForcerAttackServerTest = new PskBruteForcerAttackServerCommandConfig (
4346 generalDelegate );
44- jc .addCommand (PskBruteForcerAttackServerCommandConfig .ATTACK_COMMAND , pskBruteForcerAttackServerTest );
47+ builder .addCommand (PskBruteForcerAttackServerCommandConfig .ATTACK_COMMAND , pskBruteForcerAttackServerTest );
4548
4649 PskBruteForcerAttackClientCommandConfig pskBruteForcerAttackClientTest = new PskBruteForcerAttackClientCommandConfig (
4750 generalDelegate );
48- jc .addCommand (PskBruteForcerAttackClientCommandConfig .ATTACK_COMMAND , pskBruteForcerAttackClientTest );
51+ builder .addCommand (PskBruteForcerAttackClientCommandConfig .ATTACK_COMMAND , pskBruteForcerAttackClientTest );
52+
4953 InvalidCurveAttackConfig ellipticTest = new InvalidCurveAttackConfig (generalDelegate );
50- jc .addCommand (InvalidCurveAttackConfig .ATTACK_COMMAND , ellipticTest );
54+ builder .addCommand (InvalidCurveAttackConfig .ATTACK_COMMAND , ellipticTest );
55+
5156 HeartbleedCommandConfig heartbleed = new HeartbleedCommandConfig (generalDelegate );
52- jc .addCommand (HeartbleedCommandConfig .ATTACK_COMMAND , heartbleed );
57+ builder .addCommand (HeartbleedCommandConfig .ATTACK_COMMAND , heartbleed );
5358
5459 Lucky13CommandConfig lucky13 = new Lucky13CommandConfig (generalDelegate );
55- jc .addCommand (Lucky13CommandConfig .ATTACK_COMMAND , lucky13 );
60+ builder .addCommand (Lucky13CommandConfig .ATTACK_COMMAND , lucky13 );
5661
5762 PaddingOracleCommandConfig paddingOracle = new PaddingOracleCommandConfig (generalDelegate );
58- jc .addCommand (PaddingOracleCommandConfig .ATTACK_COMMAND , paddingOracle );
63+ builder .addCommand (PaddingOracleCommandConfig .ATTACK_COMMAND , paddingOracle );
64+
5965 TLSPoodleCommandConfig tlsPoodle = new TLSPoodleCommandConfig (generalDelegate );
60- jc .addCommand (TLSPoodleCommandConfig .ATTACK_COMMAND , tlsPoodle );
66+ builder .addCommand (TLSPoodleCommandConfig .ATTACK_COMMAND , tlsPoodle );
67+
6168 Cve20162107CommandConfig cve20162107 = new Cve20162107CommandConfig (generalDelegate );
62- jc .addCommand (Cve20162107CommandConfig .ATTACK_COMMAND , cve20162107 );
69+ builder .addCommand (Cve20162107CommandConfig .ATTACK_COMMAND , cve20162107 );
70+
6371 EarlyCCSCommandConfig earlyCCS = new EarlyCCSCommandConfig (generalDelegate );
64- jc .addCommand (EarlyCCSCommandConfig .ATTACK_COMMAND , earlyCCS );
72+ builder .addCommand (EarlyCCSCommandConfig .ATTACK_COMMAND , earlyCCS );
73+
6574 EarlyFinishedCommandConfig earlyFin = new EarlyFinishedCommandConfig (generalDelegate );
66- jc .addCommand (EarlyFinishedCommandConfig .ATTACK_COMMAND , earlyFin );
75+ builder .addCommand (EarlyFinishedCommandConfig .ATTACK_COMMAND , earlyFin );
76+
6777 PoodleCommandConfig poodle = new PoodleCommandConfig (generalDelegate );
68- jc .addCommand (PoodleCommandConfig .ATTACK_COMMAND , poodle );
78+ builder .addCommand (PoodleCommandConfig .ATTACK_COMMAND , poodle );
79+
6980 SimpleMitmProxyCommandConfig simpleMitmProxy = new SimpleMitmProxyCommandConfig (generalDelegate );
70- jc .addCommand (SimpleMitmProxyCommandConfig .ATTACK_COMMAND , simpleMitmProxy );
81+ builder .addCommand (SimpleMitmProxyCommandConfig .ATTACK_COMMAND , simpleMitmProxy );
82+
7183 GeneralDrownCommandConfig generalDrownConfig = new GeneralDrownCommandConfig (generalDelegate );
72- jc .addCommand (GeneralDrownCommandConfig .COMMAND , generalDrownConfig );
84+ builder .addCommand (GeneralDrownCommandConfig .COMMAND , generalDrownConfig );
85+
7386 SpecialDrownCommandConfig specialDrownConfig = new SpecialDrownCommandConfig (generalDelegate );
74- jc .addCommand (SpecialDrownCommandConfig .COMMAND , specialDrownConfig );
75- jc .parse (args );
76- if (generalDelegate .isHelp () || jc .getParsedCommand () == null ) {
77- if (jc .getParsedCommand () == null ) {
78- jc .usage ();
87+ builder .addCommand (SpecialDrownCommandConfig .COMMAND , specialDrownConfig );
88+
89+ JCommander jc = builder .build ();
90+
91+ try {
92+ jc .parse (args );
93+ } catch (ParameterException ex ) {
94+ String parsedCommand = ex .getJCommander ().getParsedCommand ();
95+ if (parsedCommand != null ) {
96+ ex .getJCommander ().getUsageFormatter ().usage (parsedCommand );
7997 } else {
80- jc .usage (jc . getParsedCommand () );
98+ ex .usage ();
8199 }
82100 return ;
83101 }
102+
103+ if (jc .getParsedCommand () == null ) {
104+ jc .usage ();
105+ return ;
106+ }
107+
108+ if (generalDelegate .isHelp ()) {
109+ jc .getUsageFormatter ().usage (jc .getParsedCommand ());
110+ return ;
111+ }
112+
84113 Attacker <? extends TLSDelegateConfig > attacker = null ;
114+
85115 switch (jc .getParsedCommand ()) {
86116 case BleichenbacherCommandConfig .ATTACK_COMMAND :
87117 attacker = new BleichenbacherAttacker (bleichenbacherTest , bleichenbacherTest .createConfig ());
@@ -131,41 +161,28 @@ public static void main(String[] args) {
131161 attacker = new SpecialDrownAttacker (specialDrownConfig , specialDrownConfig .createConfig ());
132162 break ;
133163 default :
134- throw new ConfigurationException ( "Command not found" ) ;
164+ break ;
135165 }
166+
136167 if (attacker == null ) {
137- throw new ConfigurationException ("Attacker not found" );
168+ throw new ConfigurationException ("Command not found" );
138169 }
139- if (isPrintHelpForCommand (jc , attacker .getConfig ())) {
140- jc .usage (jc .getParsedCommand ());
141- } else {
142170
143- if (attacker .getConfig ().isExecuteAttack ()) {
144- attacker .attack ();
145- } else {
146- try {
147- Boolean result = attacker .checkVulnerability ();
148- if (Objects .equals (result , Boolean .TRUE )) {
149- CONSOLE .error ("Vulnerable:" + result .toString ());
150- } else if (Objects .equals (result , Boolean .FALSE )) {
151- CONSOLE .info ("Vulnerable:" + result .toString ());
152- } else {
153- CONSOLE .warn ("Vulnerable: Uncertain" );
154- }
155- } catch (UnsupportedOperationException E ) {
156- LOGGER .info ("The selected attacker is currently not implemented" );
171+ if (attacker .getConfig ().isExecuteAttack ()) {
172+ attacker .attack ();
173+ } else {
174+ try {
175+ Boolean result = attacker .checkVulnerability ();
176+ if (Objects .equals (result , Boolean .TRUE )) {
177+ CONSOLE .error ("Vulnerable:" + result .toString ());
178+ } else if (Objects .equals (result , Boolean .FALSE )) {
179+ CONSOLE .info ("Vulnerable:" + result .toString ());
180+ } else {
181+ CONSOLE .warn ("Vulnerable: Uncertain" );
157182 }
183+ } catch (UnsupportedOperationException E ) {
184+ LOGGER .info ("The selected attacker is currently not implemented" );
158185 }
159186 }
160187 }
161-
162- /**
163- *
164- * @param jc
165- * @param config
166- * @return
167- */
168- public static boolean isPrintHelpForCommand (JCommander jc , TLSDelegateConfig config ) {
169- return config .getGeneralDelegate ().isHelp ();
170- }
171188}
0 commit comments