@@ -121,6 +121,8 @@ public class Challenge2Screen extends SequentialLessonAdapter
121
121
private String pass = "goodbye" ;
122
122
123
123
private String user = "youaretheweakestlink" ;
124
+
125
+ private String instructions = "" ;
124
126
125
127
/**
126
128
* Description of the Method
@@ -145,6 +147,9 @@ protected Element createContent(WebSession s)
145
147
*/
146
148
protected Element doStage1 (WebSession s ) throws Exception
147
149
{
150
+
151
+ instructions = "Your mission is to get the username and password from the WebGoat source code in order to authenticate." ;
152
+
148
153
setStage (s , 1 );
149
154
150
155
String username = s .getParser ().getRawParameter (USERNAME , "" );
@@ -189,6 +194,9 @@ protected Element doStage1(WebSession s) throws Exception
189
194
*/
190
195
protected Element doStage2 (WebSession s ) throws Exception
191
196
{
197
+
198
+ instructions = "Your mission is to steal all the credit cards from the database. " ;
199
+
192
200
// <START_OMIT_SOURCE>
193
201
194
202
Cookie newCookie = new Cookie (USER_COOKIE , Encoding .base64Encode (user ));
@@ -290,6 +298,10 @@ protected Element doStage2(WebSession s) throws Exception
290
298
*/
291
299
protected Element doStage3 (WebSession s ) throws Exception
292
300
{
301
+ instructions = "Your mission is to deface this website. Your main website jsp, which is rendered below, is contained in "
302
+ + "'webgoat_challenge_" + s .getUserName () + JSP + "'. To overwrite 'webgoat_challenge_" + s .getUserName () + JSP
303
+ + "' you will need to use many of the techniques you have learned in the other lessons. " ;
304
+
293
305
// <START_OMIT_SOURCE>
294
306
295
307
ElementContainer ec = new ElementContainer ();
@@ -326,19 +338,20 @@ protected Element doStage3(WebSession s) throws Exception
326
338
// Setup the screen content
327
339
try
328
340
{
329
- ec .addElement (new H1 ("Current Network Status:" ));
341
+ ec .addElement (new H1 ("Current Network Status (limited to 10 rows) :" ));
330
342
ec .addElement (netstatResults );
331
343
332
344
Table t = new Table ().setCellSpacing (0 ).setCellPadding (2 ).setWidth ("90%" ).setAlign ("center" );
333
345
if (s .isColor ())
334
346
{
335
347
t .setBorder (1 );
336
348
}
337
- String [] list = { "tcp" , "tcpv6" , "ip" , "ipv6" , "udp" , "udpv6" };
338
-
349
+ String [] list = { "tcp" , "udp" };
350
+ //String[] list = { "inet", "inet6", "ax25", "netrom", "ipx", "ddp", "x25" };
351
+
339
352
TR tr = new TR ();
340
353
tr .addElement (new TD ().addElement (ECSFactory .makeButton ("View Network" )));
341
- tr .addElement (new TD ().setWidth ("35%" ).addElement (ECSFactory .makePulldown (PROTOCOL , list , "" , 5 )));
354
+ tr .addElement (new TD ().setWidth ("35%" ).addElement (ECSFactory .makePulldown (PROTOCOL , list , "" , 2 )));
342
355
t .addElement (tr );
343
356
344
357
ec .addElement (t );
@@ -404,7 +417,7 @@ private void resetWebPage(WebSession s)
404
417
{
405
418
try
406
419
{
407
- // get current text and compare to the new text
420
+ // get current text and overwrite the potential defaced file
408
421
String defacedpath = s .getContext ().getRealPath (WEBGOAT_CHALLENGE + "_" + s .getUserName () + JSP );
409
422
String masterFilePath = s .getContext ().getRealPath (WEBGOAT_CHALLENGE_JSP );
410
423
@@ -415,6 +428,7 @@ private void resetWebPage(WebSession s)
415
428
fw .close ();
416
429
// System.out.println("webgoat_guest replaced: " + getFileText( new
417
430
// BufferedReader( new FileReader( defacedpath ) ), false ) );
431
+
418
432
} catch (Exception e )
419
433
{
420
434
e .printStackTrace ();
@@ -554,10 +568,7 @@ protected Element makeLogin(WebSession s)
554
568
*/
555
569
public String getInstructions (WebSession s )
556
570
{
557
- String instructions = "Your mission is to break the authentication scheme, "
558
- + "steal all the credit cards from the database, and then deface the website. "
559
- + "You will have to use many of the techniques you have learned in the other lessons. "
560
- + "The main webpage to deface for this site is 'webgoat_challenge_" + s .getUserName () + ".jsp'" ;
571
+ // each stage will load it's instructions
561
572
562
573
return (instructions );
563
574
}
@@ -629,27 +640,49 @@ protected ElementContainer getNetstatResults(WebSession s)
629
640
t .setBorder (1 );
630
641
}
631
642
632
- String [] colWidths = new String [] { "55" , "110" , "260" , "70" , "50" };
643
+ String [] colWidths = new String [] { "55" , "110" , "260" , "70" };
633
644
TR tr = new TR ();
634
645
tr .addElement (new TH ().addElement ("Protocol" ).setWidth (colWidths [0 ]));
635
646
tr .addElement (new TH ().addElement ("Local Address" ).setWidth (colWidths [1 ]));
636
647
tr .addElement (new TH ().addElement ("Foreign Address" ).setWidth (colWidths [2 ]));
637
648
tr .addElement (new TH ().addElement ("State" ).setWidth (colWidths [3 ]));
638
- tr .addElement (new TH ().addElement ("Offload State" ).setWidth (colWidths [4 ]));
639
649
t .addElement (tr );
640
650
641
651
String protocol = s .getParser ().getRawParameter (PROTOCOL , "tcp" );
642
652
643
653
String osName = System .getProperty ("os.name" );
654
+ // System.out.println("os.name= " + osName);
655
+
656
+ if (protocol .indexOf ("rm" ) != -1 || protocol .indexOf ("webgoat_challenge.jsp" ) != -1 )
657
+ {
658
+ s .setMessage ("Play nice - please don't try to hack the environment" );
659
+ protocol = "tcp" ;
660
+ }
661
+
644
662
ExecResults er = null ;
645
663
if (osName .indexOf ("Windows" ) != -1 )
646
664
{
647
665
String cmd = "cmd.exe /c netstat -ant -p " + protocol ;
648
666
er = Exec .execSimple (cmd );
649
667
}
668
+ else if (osName .indexOf ("Mac OS X" ) != -1 )
669
+ {
670
+ String [] macCmd = { "/bin/sh" , "-c" , "netstat -an -p " + protocol };
671
+ er = Exec .execSimple (macCmd );
672
+ }
650
673
else
651
674
{
652
- String [] cmd = { "/bin/sh" , "-c" , "netstat -ant -p " + protocol };
675
+ // allows for command injection by defaulting to user input
676
+ if ( protocol .startsWith ("tcp" ))
677
+ {
678
+ protocol = protocol .replace ("tcp" , "-t" );
679
+ }
680
+ else if (protocol .startsWith ("udp" ))
681
+ {
682
+ protocol = protocol .replace ("udp" , "-u" );
683
+ }
684
+
685
+ String [] cmd = { "/bin/sh" , "-c" , "netstat -an " + protocol };
653
686
er = Exec .execSimple (cmd );
654
687
}
655
688
@@ -669,7 +702,16 @@ protected ElementContainer getNetstatResults(WebSession s)
669
702
line = lines .nextToken ();
670
703
}
671
704
}
672
- while (start > 0 && lines .hasMoreTokens ())
705
+
706
+ // This is what is being parsed
707
+ //
708
+ // Active Internet connections (servers and established)
709
+ // Proto Recv-Q Send-Q Local Address Foreign Address State
710
+ // tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
711
+ // tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
712
+
713
+ int read10 = 10 ;
714
+ while (start > 0 && lines .hasMoreTokens () && read10 -- > 0 )
673
715
{
674
716
// in order to avoid a ill-rendered screen when the user performs
675
717
// command injection, we will wrap the screen at 4 columns
@@ -681,6 +723,12 @@ protected ElementContainer getNetstatResults(WebSession s)
681
723
{
682
724
td = new TD ().setWidth (colWidths [columnCount ++]);
683
725
tr .addElement (td .addElement (tokens .nextToken ()));
726
+ // throw away token 1 and 2
727
+ if (columnCount == 1 )
728
+ {
729
+ if (tokens .hasMoreTokens () ) tokens .nextToken ();
730
+ if (tokens .hasMoreTokens () ) tokens .nextToken ();
731
+ }
684
732
}
685
733
t .addElement (tr );
686
734
}
0 commit comments