From 2bda4a81f39e5be108c3e545999aec9c043d59d7 Mon Sep 17 00:00:00 2001 From: "rogan.dawes" Date: Wed, 11 Jul 2007 12:51:29 +0000 Subject: [PATCH] Migrate the labs to direct/Random access stages git-svn-id: http://webgoat.googlecode.com/svn/trunk@158 4033779f-a91e-0410-96ef-6bf7bf53c507 --- .../CrossSiteScripting.java | 72 +++++++++------- .../CrossSiteScripting/FindProfile.java | 8 +- .../CrossSiteScripting/UpdateProfile.java | 4 +- .../CrossSiteScripting/ViewProfile.java | 23 +++-- .../DefaultLessonAction.java | 8 +- .../GoatHillsFinancial.java | 8 +- .../webgoat/lessons/RandomLessonAdapter.java | 45 ++++++++++ .../RoleBasedAccessControl/DeleteProfile.java | 4 +- .../RoleBasedAccessControl.java | 53 +++++++----- .../RoleBasedAccessControl/ViewProfile.java | 4 +- .../webgoat/lessons/SQLInjection/Login.java | 16 ++-- .../lessons/SQLInjection/SQLInjection.java | 35 +++++--- .../lessons/SQLInjection/ViewProfile.java | 16 ++-- .../RoleBasedAccessControl_i.java | 2 +- .../webgoat/session/RandomLessonTracker.java | 86 +++++++++++++++++++ .../org/owasp/webgoat/session/WebSession.java | 12 +++ .../main/project/WebContent/WEB-INF/web.xml | 0 .../WebContent/WEB-INF/webgoat.properties | 0 webgoat/main/project/WebContent/main.jsp | 18 ++++ 19 files changed, 300 insertions(+), 114 deletions(-) create mode 100755 webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/RandomLessonAdapter.java create mode 100755 webgoat/main/project/JavaSource/org/owasp/webgoat/session/RandomLessonTracker.java mode change 100644 => 100755 webgoat/main/project/WebContent/WEB-INF/web.xml mode change 100644 => 100755 webgoat/main/project/WebContent/WEB-INF/webgoat.properties diff --git a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/CrossSiteScripting.java b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/CrossSiteScripting.java index 943dd8103..7bf96665f 100644 --- a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/CrossSiteScripting.java +++ b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/CrossSiteScripting.java @@ -54,6 +54,18 @@ public class CrossSiteScripting extends GoatHillsFinancial { private final static Integer DEFAULT_RANKING = new Integer(100); + public final static String STAGE1 = "Stage 1"; + + public final static String STAGE2 = "Stage 2"; + + public final static String STAGE3 = "Stage 3"; + + public final static String STAGE4 = "Stage 4"; + + public final static String STAGE5 = "Stage 5"; + + public final static String STAGE6 = "Stage 6"; + protected void registerActions(String className) { registerAction(new ListStaff(this, className, LISTSTAFF_ACTION)); @@ -140,52 +152,47 @@ public class CrossSiteScripting extends GoatHillsFinancial if (!getLessonTracker(s).getCompleted()) { - switch (getStage(s)) + String stage = getStage(s); + if (STAGE1.equals(stage)) { - case 1: - instructions = "Stage " - + getStage(s) + instructions = getStage(s) + ": Execute a Stored Cross Site Scripting (XSS) attack.
" + "For this exercise, your mission is to cause the application to serve a script of your making " + " to some other user."; - break; - case 2: - instructions = "Stage " - + getStage(s) + } + else if (STAGE2.equals(stage)) + { + instructions = getStage(s) + ": Block Stored XSS using Input Validation.
" + "You will modify the application to perform input validation on the vulnerable input field " + "you just exploited."; - break; - case 3: - instructions = "Stage " - + getStage(s) + } + else if (STAGE3.equals(stage)) + { + instructions = getStage(s) + ": Execute a previously Stored Cross Site Scripting (XSS) attack.
" + "The application is still vulnerable to scripts in the database. Trigger a pre-stored " + "script by logging in as employee 'David' and viewing Bruce's profile."; - break; - case 4: - instructions = "Stage " - + getStage(s) + } + else if (STAGE4.equals(stage)) + { + instructions = getStage(s) + ": Block Stored XSS using Output Encoding.
" + "Encode data served from the database to the client so that any scripts are rendered harmless."; - break; - case 5: - instructions = "Stage " - + getStage(s) + } + else if (STAGE5.equals(stage)) + { + instructions = getStage(s) + ": Execute a Reflected XSS attack.
" + "Your goal here is to craft a link containing a script which the application will " + "serve right back to any client that activates the link."; - break; - case 6: - instructions = "Stage " - + getStage(s) + } + else if (STAGE6.equals(stage)) + { + instructions = getStage(s) + ": Block Reflected XSS using Input Validation.
" + "Use the input validation techniques learned ealier in this lesson to close the vulnerability " + "you just exploited."; - break; - default: - // Illegal stage value - break; } } @@ -194,8 +201,8 @@ public class CrossSiteScripting extends GoatHillsFinancial } @Override - public int getStageCount() { - return 6; + public String[] getStages() { + return new String[] {STAGE1, STAGE2, STAGE3, STAGE4, STAGE5, STAGE6}; } public void handleRequest(WebSession s) @@ -290,12 +297,11 @@ public class CrossSiteScripting extends GoatHillsFinancial public String htmlEncode(WebSession s, String text) { //System.out.println("Testing for stage 4 completion in lesson " + getCurrentLesson().getName()); - if (getStage(s) == 4 && + if (STAGE4.equals(getStage(s)) && text.indexOf("") > -1) { s.setMessage( "Welcome to stage 5 -- exploiting the data layer" ); - // Set a phantom stage value to setup for the 4-5 transition - setStage(s, 1005); + setStageComplete(s, STAGE5); } return HtmlEncoder.encode(text); diff --git a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/FindProfile.java b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/FindProfile.java index 97b1a22e2..6449bca27 100644 --- a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/FindProfile.java +++ b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/FindProfile.java @@ -88,23 +88,23 @@ public class FindProfile extends DefaultLessonAction } catch (ValidationException e) { - if (getStage(s) == 6) + if (CrossSiteScripting.STAGE6.equals(getStage(s))) { s .setMessage("Congratulations. You have successfully completed this lesson"); - getLesson().getLessonTracker(s).setCompleted(true); + setStageComplete(s, CrossSiteScripting.STAGE6); } throw e; } - if (getStage(s) == 5) + if (CrossSiteScripting.STAGE5.equals(getStage(s))) { if (searchName.indexOf("") > -1) { s.setMessage("Welcome to stage 6 - more input validation"); - setStage(s, 6); + setStageComplete(s, CrossSiteScripting.STAGE5); } } diff --git a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/UpdateProfile.java b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/UpdateProfile.java index d04699b09..193ce168a 100644 --- a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/UpdateProfile.java +++ b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/UpdateProfile.java @@ -81,11 +81,11 @@ public class UpdateProfile extends DefaultLessonAction } catch (ValidationException e) { - if (getStage(s) == 2) + if (CrossSiteScripting.STAGE2.equals(getStage(s))) { s .setMessage("Welcome to stage 3 - demonstrate Stored XSS again"); - setStage(s, 3); + setStageComplete(s, CrossSiteScripting.STAGE2); } throw e; } diff --git a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/ViewProfile.java b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/ViewProfile.java index d9d75f36c..9b2e6e47b 100644 --- a/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/ViewProfile.java +++ b/ webgoat/main/project/JavaSource/org/owasp/webgoat/lessons/CrossSiteScripting/ViewProfile.java @@ -212,9 +212,9 @@ public class ViewProfile extends DefaultLessonAction private void updateLessonStatus(WebSession s, Employee employee) { - switch (getStage(s)) + String stage = getStage(s); + if (CrossSiteScripting.STAGE1.equals(stage)) { - case 1: String address1 = employee.getAddress1().toLowerCase(); if (address1.indexOf("