diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java b/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java
deleted file mode 100644
index 074c61c91..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java
+++ /dev/null
@@ -1,120 +0,0 @@
-
-package org.owasp.webgoat;
-
-import java.io.IOException;
-import java.util.Enumeration;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.Course;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce Mayhew WebGoat
- * @since March 13, 2007
- * @version $Id: $Id
- */
-public class Catcher extends HammerHead
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 7441856110845727651L;
-
- /**
- * Description of the Field
- */
- public final static String START_SOURCE_SKIP = "START_OMIT_SOURCE";
-
- /** Constant END_SOURCE_SKIP="END_OMIT_SOURCE" */
- public final static String END_SOURCE_SKIP = "END_OMIT_SOURCE";
-
- /** Constant PROPERTY="PROPERTY" */
- public static final String PROPERTY = "PROPERTY";
-
- /** Constant EMPTY_STRING="" */
- public static final String EMPTY_STRING = "";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- * @exception IOException
- * Description of the Exception
- * @exception ServletException
- * Description of the Exception
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
- {
- try
- {
- // System.out.println( "Entering doPost: " );
- // System.out.println( " - request " + request);
- // System.out.println( " - principle: " + request.getUserPrincipal() );
- // setCacheHeaders(response, 0);
- WebSession session = (WebSession) request.getSession(true).getAttribute(WebSession.SESSION);
- session.update(request, response, this.getServletName()); // FIXME: Too much in this
- // call.
-
- int scr = session.getCurrentScreen();
- Course course = session.getCourse();
- AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
-
- log(request, lesson.getClass().getName() + " | " + session.getParser().toString());
-
- String property = new String(session.getParser().getStringParameter(PROPERTY, EMPTY_STRING));
-
- // if the PROPERTY parameter is available - write all the parameters to the
- // property file. No other control parameters are supported at this time.
- if (!property.equals(EMPTY_STRING))
- {
- Enumeration e = session.getParser().getParameterNames();
-
- while (e.hasMoreElements())
- {
- String name = (String) e.nextElement();
- String value = session.getParser().getParameterValues(name)[0];
- lesson.getLessonTracker(session).getLessonProperties().setProperty(name, value);
- }
- }
- lesson.getLessonTracker(session).store(session, lesson);
-
- // BDM MC
-// WEB-173 - removed for testing, as plugin architecture would not allow this
-// if ( request.getParameter("Deleter") != null ){org.owasp.webgoat.lessons.BlindScript.StaticDeleter();}
-
- } catch (Throwable t)
- {
- t.printStackTrace();
- log("ERROR: " + t);
- }
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
index e8f2cb828..9180277ad 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
@@ -1,398 +1,60 @@
package org.owasp.webgoat;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.WelcomeScreen;
-import org.owasp.webgoat.lessons.admin.WelcomeAdminScreen;
import org.owasp.webgoat.session.Course;
-import org.owasp.webgoat.session.ErrorScreen;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.servlet.ModelAndView;
/**
* *************************************************************************************************
- *
- *
+ *
+ *
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
- *
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
* Getting Source ==============
- *
+ *
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
* for free software projects.
*
- * @author Jeff Williams Aspect
- * Security
- * @author Bruce Mayhew WebGoat
- * @since October 28, 2003
+ * @author Jeff Williams
+ * @author Bruce Mayhew
+ * @author Nanne Baars
* @version $Id: $Id
+ * @since October 28, 2003
*/
-public class HammerHead extends HttpServlet {
+@Controller
+public class HammerHead {
- private static final long serialVersionUID = 645640331343188020L;
- private static SimpleDateFormat httpDateFormat;
- private final Logger logger = LoggerFactory.getLogger(HammerHead.class);
- private WebSession webSession;
+ private final Course course;
- public HammerHead() {
- //for catcher subclass
- }
-
- public HammerHead(WebSession webSession) {
- this.webSession = webSession;
+ public HammerHead(Course course) {
+ this.course = course;
}
/**
- * {@inheritDoc}
- *
- * Description of the Method
- * @exception IOException Description of the Exception
- * @exception ServletException Description of the Exception
+ * Entry point for WebGoat, redirects to the first lesson found within the course.
*/
- @Override
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- doPost(request, response);
- }
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- * @exception IOException Description of the Exception
- * @exception ServletException Description of the Exception
- */
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- Screen screen = null;
-
- WebSession mySession = null;
- try {
- logger.debug("Entering doPost");
- logger.debug("request: " + request);
- logger.debug("principle: " + request.getUserPrincipal());
- // setCacheHeaders(response, 0);
- ServletContext context = getServletContext();
-
- // FIXME: If a response is written by updateSession(), do not
- // call makeScreen() and writeScreen()
- mySession = updateSession(request, response, context);
-
- if (response.isCommitted()) {
- logger.debug("Response already committed, exiting");
- return;
- }
-
- if ("true".equals(request.getParameter("start")) || request.getQueryString() == null) {
- logger.warn("Redirecting to first lesson");
- response.sendRedirect("start.mvc" + mySession.getCourse().getFirstLesson().getLink());
- return;
- }
-
- // Note: For the lesson to track the status, we need to update
- // the lesson tracker object
- // from the screen.createContent() method. The create content is
- // the only point
- // where the lesson "knows" what has happened. To track it at a
- // latter point would
- // require the lesson to have memory.
- screen = makeScreen(mySession);
- // This calls the lesson's
- // handleRequest()
- if (response.isCommitted()) {
- return;
- }
-
- // perform lesson-specific tracking activities
- if (screen instanceof AbstractLesson) {
- AbstractLesson lesson = (AbstractLesson) screen;
-
- // we do not count the initial display of the lesson screen as a visit
- if ("GET".equals(request.getMethod())) {
- String uri = request.getRequestURI() + "?" + request.getQueryString();
- if (!uri.endsWith(lesson.getLink())) {
- screen.getLessonTracker(mySession).incrementNumVisits();
- }
- } else if ("POST".equals(request.getMethod())
- && mySession.getPreviousScreen() == mySession.getCurrentScreen()) {
- screen.getLessonTracker(mySession).incrementNumVisits();
- }
- }
-
- // log the access to this screen for this user
- UserTracker userTracker = UserTracker.instance();
- userTracker.update(mySession, screen);
- log(request, screen.getClass().getName() + " | " + mySession.getParser().toString());
-
- // Redirect the request to our View servlet
- String userAgent = request.getHeader("user-agent");
- String clientBrowser = "Not known!";
- if (userAgent != null) {
- clientBrowser = userAgent;
- }
- request.setAttribute("client.browser", clientBrowser);
- // removed - this is being done in updateSession call
- //request.getSession().setAttribute(WebSession.SESSION, mySession);
- // not sure why this is being set in the session?
- //request.getSession().setAttribute(WebSession.COURSE, mySession.getCourse());
- String viewPage = getViewPage(mySession);
- logger.debug("Forwarding to view: " + viewPage);
- logger.debug("Screen: " + screen);
- response.sendRedirect("startlesson.mvc");
-// request.getRequestDispatcher(viewPage).forward(request, response);
- } catch (Throwable t) {
- logger.error("Error handling request", t); screen = new ErrorScreen(mySession, t);
- } finally {
- try {
- if (screen instanceof ErrorScreen) {
- this.writeScreen(mySession, screen, response);
- }
- } catch (Throwable thr) {
- logger.error("Could not write error screen", thr);
- }
- WebSession.returnConnection(mySession);
- logger.debug("Leaving doPost: ");
- }
- }
-
- private String getViewPage(WebSession webSession) {
- // now always display the lesson content
- String page = "lesson_content";
- //page = "/main.jsp";
- return page;
- }
-
- /**
- * Description of the Method
- *
- * @param date Description of the Parameter
- * @return RFC 1123 http date format
- */
- protected static String formatHttpDate(Date date) {
- synchronized (httpDateFormat) {
- return httpDateFormat.format(date);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * Return information about this servlet
- */
- @Override
- public String getServletInfo() {
- return "WebGoat is sponsored by Aspect Security.";
- }
-
- /**
- * {@inheritDoc}
- *
- * Return properties path
- */
- @Override
- public void init() throws ServletException {
- logger.info("Initializing main webgoat servlet");
- httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyyy HH:mm:ss z", Locale.US);
- httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- }
-
- /**
- * Description of the Method
- *
- * @param request Description of the Parameter
- * @param message Description of the Parameter
- */
- public void log(HttpServletRequest request, String message) {
- String output = new Date() + " | " + request.getRemoteHost() + ":" + request.getRemoteAddr() + " | " + message;
- log(output);
- logger.debug(output);
- }
-
- /*
- * public List getLessons(Category category, String role) { Course course =
- * mySession.getCourse(); // May need to clone the List before returning it. //return new
- * ArrayList(course.getLessons(category, role)); return course.getLessons(category, role); }
- */
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- protected Screen makeScreen(WebSession s) {
- Screen screen = null;
- int scr = s.getCurrentScreen();
- Course course = s.getCourse();
-
- if (s.isUser() || s.isChallenge()) {
- if (scr == WebSession.WELCOME) {
- screen = new WelcomeScreen(s);
- } else {
- AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
- if (lesson == null && s.isHackedAdmin()) {
- // If admin was hacked, let the user see some of the
- // admin screens
- lesson = course.getLesson(s, scr, AbstractLesson.HACKED_ADMIN_ROLE);
- }
-
- if (lesson != null) {
- screen = lesson;
-
- // We need to do some bookkeeping for the hackable admin
- // interface.
- // This is the only place we can tell if the user
- // successfully hacked the hackable
- // admin and has actually accessed an admin screen. You
- // need BOTH pieces of information
- // in order to satisfy the remote admin lesson.
- s.setHasHackableAdmin(screen.getRole());
-
- lesson.handleRequest(s);
- s.setCurrentMenu(lesson.getCategory().getRanking());
- } else {
- screen = new ErrorScreen(s, "Invalid screen requested. Try: http://localhost/WebGoat/attack");
- }
- }
- } else if (s.isAdmin()) {
- if (scr == WebSession.WELCOME) {
- screen = new WelcomeAdminScreen(s);
- } else {
- // Admin can see all roles.
- // FIXME: should be able to pass a list of roles.
- AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.ADMIN_ROLE);
- if (lesson == null) {
- lesson = course.getLesson(s, scr, AbstractLesson.HACKED_ADMIN_ROLE);
- }
- if (lesson == null) {
- lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
- }
-
- if (lesson != null) {
- screen = lesson;
-
- // We need to do some bookkeeping for the hackable admin
- // interface.
- // This is the only place we can tell if the user
- // successfully hacked the hackable
- // admin and has actually accessed an admin screen. You
- // need BOTH pieces of information
- // in order to satisfy the remote admin lesson.
- s.setHasHackableAdmin(screen.getRole());
-
- lesson.handleRequest(s);
- s.setCurrentMenu(lesson.getCategory().getRanking());
- } else {
- screen = new ErrorScreen(s,
- "Invalid screen requested. Try Setting Admin to false or Try: http://localhost/WebGoat/attack");
- }
- }
- }
-
- return (screen);
- }
-
- /**
- * Description of the Method
- *
- * @param request Description of the Parameter
- * @param response Description of the Parameter
- * @param context Description of the Parameter
- * @return Description of the Return Value
- * @throws java.io.IOException if any.
- */
- protected WebSession updateSession(HttpServletRequest request, HttpServletResponse response, ServletContext context)
- throws IOException {
- HttpSession hs;
- // session should already be created by spring security
- hs = request.getSession(false);
-
- //TODO rewrite this logic
- logger.debug("HH Entering Session_id: " + hs.getId());
- // dumpSession( hs );
- // Get our session object out of the HTTP session
- WebSession session = this.webSession;
- Object o = hs.getAttribute(WebSession.SESSION);
-
- if ((o != null) && o instanceof WebSession) {
- session = (WebSession) o;
- hs.setAttribute(WebSession.COURSE, session.getCourse());
- } else {
- // Create new custom session and save it in the HTTP session
- logger.warn("HH Creating new WebSession");
- // Ensure splash screen shows on any restart
- // rlawson - removed this since we show splash screen at login now
- //hs.removeAttribute(WELCOMED);
- //@TODO NO NEED TO PUT IN THE HTTP SESSION, FOCUS WILL FIX LATER
- hs.setAttribute(WebSession.SESSION, session);
- }
-
- session.update(request, response, this.getServletName());
- // update last attack request info (cookies, parms)
- // this is so the REST services can have access to them via the session
- session.updateLastAttackRequestInfo(request);
-
- // to authenticate
- logger.debug("HH Leaving Session_id: " + hs.getId());
- //dumpSession( hs );
- return (session);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @param screen a {@link org.owasp.webgoat.session.Screen} object.
- * @param screen a {@link org.owasp.webgoat.session.Screen} object.
- * @param response Description of the Parameter
- * @exception IOException Description of the Exception
- * @throws java.io.IOException if any.
- */
- protected void writeScreen(WebSession s, Screen screen, HttpServletResponse response) throws IOException {
- response.setContentType("text/html");
-
- PrintWriter out = response.getWriter();
-
- if (s == null) {
- screen = new ErrorScreen(s, "Page to display was null");
- }
-
- // set the content-length of the response.
- // Trying to avoid chunked-encoding. (Aspect required)
- response.setContentLength(screen.getContentLength());
- response.setHeader("Content-Length", screen.getContentLength() + "");
-
- screen.output(out);
- out.flush();
- out.close();
+ //// TODO: 11/6/2016 course necessary?
+ @RequestMapping(path = "/attack", method = {RequestMethod.GET, RequestMethod.POST})
+ public ModelAndView attack() {
+ return new ModelAndView("redirect:" + "start.mvc" + course.getFirstLesson().getLink());
}
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java b/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
index 5f7fc0fd8..02ab81b6d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/MvcConfiguration.java
@@ -31,11 +31,10 @@
package org.owasp.webgoat;
import com.google.common.collect.Sets;
+import org.owasp.webgoat.session.Course;
import org.owasp.webgoat.session.LabelDebugger;
-import org.owasp.webgoat.session.WebSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -103,12 +102,6 @@ public class MvcConfiguration extends WebMvcConfigurerAdapter {
return engine;
}
-
- @Bean
- public ServletRegistrationBean servletRegistrationBean(HammerHead hammerHead) {
- return new ServletRegistrationBean(hammerHead, "/attack/*");
- }
-
/**
* This way we expose the plugins target directory as a resource within the web application.
*
@@ -120,8 +113,8 @@ public class MvcConfiguration extends WebMvcConfigurerAdapter {
}
@Bean
- public HammerHead hammerHead(WebSession webSession) {
- return new HammerHead(webSession);
+ public HammerHead hammerHead(Course course) {
+ return new HammerHead(course);
}
@Bean
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java b/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
index 444ee08fb..7fde94e7e 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/WebGoat.java
@@ -35,26 +35,21 @@ import org.owasp.webgoat.plugins.PluginClassLoader;
import org.owasp.webgoat.plugins.PluginEndpointPublisher;
import org.owasp.webgoat.plugins.PluginsLoader;
import org.owasp.webgoat.session.Course;
-import org.owasp.webgoat.session.UserTracker;
import org.owasp.webgoat.session.WebSession;
import org.owasp.webgoat.session.WebgoatContext;
-import org.owasp.webgoat.session.WebgoatProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
-import javax.servlet.ServletContext;
import java.io.File;
import java.util.List;
@SpringBootApplication
-@PropertySource("classpath:/webgoat.properties")
public class WebGoat extends SpringBootServletInitializer {
@Override
@@ -68,13 +63,16 @@ public class WebGoat extends SpringBootServletInitializer {
@Bean(name = "pluginTargetDirectory")
public File pluginTargetDirectory() {
- File tempDir = com.google.common.io.Files.createTempDir();
- tempDir.deleteOnExit();
- return tempDir;
+ return com.google.common.io.Files.createTempDir();
}
+// @Bean
+// public ApplicationListener closeEvent(@Qualifier("pluginTargetDirectory") File pluginTargetDirectory) {
+// return e -> pluginTargetDirectory.delete();
+// }
+
@Bean
- public PluginClassLoader pluginClassLoader(@Qualifier("pluginTargetDirectory") File pluginTargetDirectory) {
+ public PluginClassLoader pluginClassLoader() {
return new PluginClassLoader(PluginClassLoader.class.getClassLoader());
}
@@ -85,25 +83,17 @@ public class WebGoat extends SpringBootServletInitializer {
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
- public WebSession webSession(Course course, WebgoatContext webgoatContext, ServletContext context) {
- return new WebSession(course, webgoatContext, context);
+ public WebSession webSession(WebgoatContext webgoatContext) {
+ return new WebSession(webgoatContext);
}
@Bean
- public Course course(PluginsLoader pluginsLoader, WebgoatContext webgoatContext, ServletContext context, WebgoatProperties webgoatProperties,
- PluginEndpointPublisher pluginEndpointPublisher) {
- Course course = new Course(webgoatProperties);
- course.loadCourses(webgoatContext, context, "/");
+ public Course course(PluginsLoader pluginsLoader, PluginEndpointPublisher pluginEndpointPublisher) {
+ Course course = new Course();
List plugins = pluginsLoader.loadPlugins();
- course.loadLessonFromPlugin(plugins);
+ course.createLessonsFromPlugins(plugins);
plugins.forEach(p -> pluginEndpointPublisher.publish(p));
return course;
}
-
- @Bean
- public UserTracker userTracker() {
- UserTracker userTracker = UserTracker.instance();
- return userTracker;
- }
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
index 94e00fb9d..6af1770f3 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/StartLesson.java
@@ -31,8 +31,7 @@
package org.owasp.webgoat.controller;
import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.NewLesson;
-import org.owasp.webgoat.lessons.RandomLessonAdapter;
+import org.owasp.webgoat.session.Course;
import org.owasp.webgoat.session.WebSession;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
@@ -50,24 +49,25 @@ import java.util.Optional;
@Controller
public class StartLesson {
+ private final WebSession ws;
+ private final Course course;
+
+ public StartLesson(final WebSession ws, final Course course) {
+ this.ws = ws;
+ this.course = course;
+ }
+
/**
*
start.
*
- * @param request a {@link HttpServletRequest} object.
* @return a {@link ModelAndView} object.
*/
@RequestMapping(path = "startlesson.mvc", method = {RequestMethod.GET, RequestMethod.POST})
- public ModelAndView start(HttpServletRequest request) {
+ public ModelAndView start() {
ModelAndView model = new ModelAndView();
- WebSession ws = (WebSession) request.getSession().getAttribute(WebSession.SESSION);
- model.addObject("has_stages", ws.getCurrentLesson() instanceof RandomLessonAdapter);
- model.addObject("course", ws.getCourse());
+ model.addObject("course", course);
model.addObject("lesson", ws.getCurrentLesson());
- model.addObject("message", ws.getMessage());
- model.addObject("instructions", ws.getInstructions());
- boolean isMigrated = ws.getCurrentLesson() instanceof NewLesson;
- model.addObject("migrated", isMigrated); //remove after ECS removal otherwise you will see the lesson twice
model.setViewName("lesson_content");
return model;
}
@@ -80,13 +80,11 @@ public class StartLesson {
GrantedAuthority authority = context.getAuthentication().getAuthorities().iterator().next();
String path = request.getServletPath(); // we now got /a/b/c/AccessControlMatrix.lesson
String lessonName = path.substring(path.lastIndexOf('/') + 1, path.indexOf(".lesson"));
- WebSession ws = (WebSession) request.getSession().getAttribute(WebSession.SESSION);
- List lessons = ws.getCourse()
- .getLessons(ws, AbstractLesson.USER_ROLE);//TODO this should work with the security roles of Spring
+ List lessons = course.getLessons();
Optional lesson = lessons.stream()
.filter(l -> l.getId().equals(lessonName))
.findFirst();
- ws.setCurrentScreen(lesson.get().getScreenId());
+ ws.setCurrentLesson(lesson.get());
model.setViewName("lesson_content");
model.addObject("lesson", lesson.get());
return model;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManager.java
similarity index 98%
rename from webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java
rename to webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManager.java
index a0f42adc9..21990bf6e 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManager.java
@@ -1,5 +1,5 @@
-package org.owasp.webgoat.util;
+package org.owasp.webgoat.i18n;
import java.util.Locale;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManagerImpl.java
similarity index 81%
rename from webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java
rename to webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManagerImpl.java
index f98b1a981..0e3ed00c4 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/i18n/LabelManagerImpl.java
@@ -1,8 +1,7 @@
-package org.owasp.webgoat.util;
+package org.owasp.webgoat.i18n;
import org.owasp.webgoat.session.LabelDebugger;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.Serializable;
@@ -38,30 +37,22 @@ import java.util.Locale;
* @version $Id: $Id
* @author dm
*/
-@Component("labelManager")
+@Component
public class LabelManagerImpl implements LabelManager, Serializable
{
private static final long serialVersionUID = 1L;
- @Autowired
- private transient LabelProvider labelProvider;
- @Autowired
+ private LabelProvider labelProvider;
private LabelDebugger labelDebugger;
-
- /** Locale mapped with current session. */
private Locale locale = new Locale(LabelProvider.DEFAULT_LANGUAGE);
- /**
- *
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a boolean.
- */
- public boolean isCompleted(WebSession s) {
- return getLessonTracker(s, this).getCompleted();
- }
/**
* {@inheritDoc}
@@ -205,7 +93,7 @@ public abstract class AbstractLesson extends Screen implements ComparablegetHints.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
* @return a {@link java.util.List} object.
*/
- protected abstract List getHints(WebSession s);
-
- // @TODO we need to restrict access at the service layer
- // rather than passing session object around
-
- /**
- *
getHintsPublic.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.util.List} object.
- */
- public List getHintsPublic(WebSession s) {
- List hints = getHints(s);
- return hints;
- }
-
- /**
- * Fill in a minor hint that will help people who basically get it, but are
- * stuck on somthing silly.
- *
- * @param s The users WebSession
- * @param hintNumber a int.
- * @return The hint1 value
- */
- public String getHint(WebSession s, int hintNumber) {
- return "Hint: " + getHints(s).get(hintNumber);
- }
-
- /**
- * Gets the instructions attribute of the AbstractLesson object
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return The instructions value
- */
- public abstract String getInstructions(WebSession s);
-
- /**
- * Gets the lessonPlan attribute of the Lesson object
- *
- * @return The lessonPlan value
- */
- public String getLessonName() {
- return this.getClass().getSimpleName();
- }
+ public abstract List getHints();
/**
* Gets the title attribute of the HelloScreen object
@@ -414,36 +146,6 @@ public abstract class AbstractLesson extends Screen implements ComparablegetHtml_DELETE_ME.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getHtml_DELETE_ME(WebSession s) {
- String html = null;
-
- // FIXME: This doesn't work for the labs since they do not implement
- // createContent().
- String rawHtml = createContent(s).toString();
- // System.out.println("Getting raw html content: " +
- // rawHtml.substring(0, Math.min(rawHtml.length(), 100)));
- html = convertMetachars(AbstractLesson.readFromFile(new BufferedReader(new StringReader(rawHtml)), true));
- // System.out.println("Getting encoded html content: " +
- // html.substring(0, Math.min(html.length(), 100)));
-
- return html;
- }
-
- /**
- *
getSource.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getSource(WebSession s) {
- String source = null;
- String src = null;
-
- try {
- // System.out.println("Loading source file: " +
- // getSourceFileName());
- src = convertMetacharsJavaCode(readFromFile(new BufferedReader(new FileReader(getSourceFileName())), true));
-
- // TODO: For styled line numbers and better memory efficiency,
- // use a custom FilterReader
- // that performs the convertMetacharsJavaCode() transform plus
- // optionally adds a styled
- // line number. Wouldn't color syntax be great too?
- } catch (Exception e) {
- s.setMessage("Could not find source file");
- src = ("Could not find the source file or source file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + "");
- }
-
- Html html = new Html();
-
- Head head = new Head();
- head.addElement(new Title(getSourceFileName()));
-
- Body body = new Body();
- body.addElement(new StringElement(src));
-
- html.addElement(head);
- html.addElement(body);
-
- source = html.toString();
-
- return source;
- }
-
- /**
- *
getRawSource.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getRawSource(WebSession s) {
- String src = "";
-
- try {
- logger.debug("Loading source file: " + getSourceFileName());
- if (getSourceFileName() != null) {
- src = readFromFile(new BufferedReader(new FileReader(getSourceFileName())), false);
- }
-
- } catch (FileNotFoundException e) {
- s.setMessage("Could not find source file");
- src = ("Could not find the source file or source file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + "");
- }
-
- return src;
- }
-
- /**
- *
getSolution.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getSolution(WebSession s) {
- String src = null;
-
- try {
- // System.out.println("Solution: " + getLessonSolutionFileName());
- src = readFromFile(new BufferedReader(new FileReader(getLessonSolutionFileName())), false);
- } catch (Exception e) {
- logger.error("Could not find solution for {}", getLessonSolutionFileName());
- s.setMessage("Could not find the solution file");
- src = ("Could not find the solution file or solution file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + "");
- }
-
- // Solutions are html files
- return src;
- }
-
/**
*
Returns the default "path" portion of a lesson's URL.
*
@@ -643,244 +199,9 @@ public abstract class AbstractLesson extends Screen implements Comparable
- * Unlike getLink() this method does not require rendering the output of
- * the request to the link in order to execute the servlet's method with
- * conventional HTTP query parameters.
- *
- * @return a {@link java.lang.String} object.
- */
- public String getServletLink() {
- StringBuffer link = new StringBuffer("attack");
-
- return link
- .append("?Screen=").append(getScreenId())
- .append("&menu=").append(getCategory().getRanking()).toString();
- }
-
- /**
- * Get the link to the jsp page used to render this screen.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getPage(WebSession s) {
- return null;
- }
-
- /**
- * Get the link to the jsp template page used to render this screen.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public String getTemplatePage(WebSession s) {
- return null;
- }
-
- /**
- *
getCurrentAction.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- */
- public abstract String getCurrentAction(WebSession s);
-
- /**
- * Initiates lesson restart functionality
- */
- public abstract void restartLesson();
-
-
- /**
- *
setCurrentAction.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @param lessonScreen a {@link java.lang.String} object.
- */
- public abstract void setCurrentAction(WebSession s, String lessonScreen);
-
- /**
- * Override this method to implement accesss control in a lesson.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @param functionId a {@link java.lang.String} object.
- * @param employeeId a int.
- * @return a boolean.
- */
- public boolean isAuthorized(WebSession s, int employeeId, String functionId) {
- return false;
- }
-
- /**
- * Override this method to implement accesss control in a lesson.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @param functionId a {@link java.lang.String} object.
- * @param role a {@link java.lang.String} object.
- * @return a boolean.
- */
- public boolean isAuthorized(WebSession s, String role, String functionId) {
- logger.info("Checking if " + role + " authorized for: " + functionId);
- boolean authorized = false;
- try {
- String query = "SELECT * FROM auth WHERE role = '" + role + "' and functionid = '" + functionId + "'";
- try {
- Statement answer_statement = WebSession.getConnection(s)
- .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet answer_results = answer_statement.executeQuery(query);
- authorized = answer_results.first();
- logger.info("authorized: " + authorized);
- } catch (SQLException sqle) {
- s.setMessage("Error authorizing");
- logger.error("Error authorizing", sqle);
- }
- } catch (Exception e) {
- s.setMessage("Error authorizing");
- logger.error("Error authorizing", e);
- }
- return authorized;
- }
-
- /**
- *
getUserId.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a int.
- * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
- */
- public int getUserId(WebSession s) throws ParameterNotFoundException {
- return -1;
- }
-
- /**
- *
getUserName.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link java.lang.String} object.
- * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
- */
- public String getUserName(WebSession s) throws ParameterNotFoundException {
- return null;
- }
-
- /**
- * Description of the Method
- *
- * @param windowName Description of the Parameter
- * @return Description of the Return Value
- */
- public static String makeWindowScript(String windowName) {
- // FIXME: make this string static
- StringBuffer script = new StringBuffer();
- script.append("\n");
-
- return script.toString();
- }
-
- /**
- * Simply reads a url into an Element for display. CAUTION: you might want
- * to tinker with any non-https links (href)
- *
- * @param url Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element readFromURL(String url) {
- ElementContainer ec = new ElementContainer();
-
- try {
- URL u = new URL(url);
- HttpURLConnection huc = (HttpURLConnection) u.openConnection();
- BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
- String line;
-
- while ((line = reader.readLine()) != null) {
- ec.addElement(new StringElement(line));
- }
-
- reader.close();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param reader Description of the Parameter
- * @param numbers Description of the Parameter
- * @param methodName Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element readMethodFromFile(BufferedReader reader, String methodName, boolean numbers) {
- PRE pre = new PRE().addElement(getFileMethod(reader, methodName, numbers));
-
- return (pre);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- */
- public void handleRequest(WebSession s) {
- // call createContent first so messages will go somewhere
- Form form = new Form(getFormAction(), Form.POST).setName("form").setEncType("");
- form.addElement(createContent(s));
- setContent(form);
- s.getRequest().getRequestURL();
- }
-
- /**
- *
getFormAction.
- *
- * @return a {@link java.lang.String} object.
- */
- public String getFormAction() {
- return getLink();
- }
-
/**
* Description of the Method
*
@@ -890,116 +211,6 @@ public abstract class AbstractLesson extends Screen implements ComparableGetter for the field defaultLanguage.
- *
- * @return a {@link org.owasp.webgoat.util.LabelManager} object.
- */
- protected LabelManager getLabelManager() {
- if (labelManager == null) {
- labelManager = BeanProvider.getBean("labelManager", LabelManager.class);
- }
- return labelManager;
- }
-
public String getId() {
return "";
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpoint.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AssignmentEndpoint.java
similarity index 86%
rename from webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpoint.java
rename to webgoat-container/src/main/java/org/owasp/webgoat/lessons/AssignmentEndpoint.java
index f7a8a8a0d..1a7e3aee2 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpoint.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AssignmentEndpoint.java
@@ -28,7 +28,6 @@ package org.owasp.webgoat.lessons;
import org.owasp.webgoat.lessons.model.AttackResult;
import org.owasp.webgoat.session.LessonTracker;
import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.endpoint.Endpoint;
@@ -46,14 +45,13 @@ import java.io.File;
* Note: each subclass should declare this annotation otherwise the WebGoat framework cannot find your endpoint.
*/
@LessonEndpointMapping
-public abstract class LessonEndpoint implements MvcEndpoint {
+public abstract class AssignmentEndpoint implements MvcEndpoint {
@Autowired
@Qualifier("pluginTargetDirectory")
private File pluginDirectory;
@Autowired
- private WebSession webSession;
- private boolean solved = false;
+ private UserTracker userTracker;
/**
* The directory of the plugin directory in which the lessons resides, so if you want to access the lesson 'ClientSideFiltering' you will
@@ -71,15 +69,21 @@ public abstract class LessonEndpoint implements MvcEndpoint {
return new File(this.pluginDirectory, "plugin");
}
+ /**
+ * Get the lesson tracker which is based on the current user and do the
+ * @return
+ */
protected LessonTracker getLessonTracker() {
- UserTracker userTracker = UserTracker.instance();
- LessonTracker lessonTracker = userTracker.getLessonTracker(webSession, webSession.getCurrentLesson());
+ LessonTracker lessonTracker = userTracker.getCurrentLessonTracker();
return lessonTracker;
}
protected AttackResult trackProgress(AttackResult attackResult) {
- this.solved = attackResult.isLessonCompleted();
- getLessonTracker().setCompleted(solved);
+ //// TODO: 11/5/2016 improve
+ if (attackResult.isLessonCompleted()) {
+ getLessonTracker().incrementNumVisits();
+ }
+ getLessonTracker().setCompleted(attackResult.isLessonCompleted());
return attackResult;
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Attack.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Attack.java
deleted file mode 100644
index c8976dce6..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Attack.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.owasp.webgoat.lessons;
-
-
-import org.owasp.webgoat.lessons.model.AttackResult;
-
-/**
- * ************************************************************************************************
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
- *
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
* Getting Source ==============
- *
+ *
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
* for free software projects.
*
* @author Bruce Mayhew WebGoat
- * @since October 28, 2003
* @version $Id: $Id
+ * @since October 28, 2003
*/
-public class Category implements Comparable {
+public enum Category {
- /** Constant INTRODUCTION */
- public final static Category INTRODUCTION = new Category("Introduction", new Integer(5));
-
- /** Constant GENERAL */
- public final static Category GENERAL = new Category("General", new Integer(100));
-
- /** Constant ACCESS_CONTROL */
- public final static Category ACCESS_CONTROL = new Category("Access Control Flaws", new Integer(200));
-
- /** Constant AJAX_SECURITY */
- public final static Category AJAX_SECURITY = new Category("AJAX Security", new Integer(400));
-
- /** Constant AUTHENTICATION */
- public final static Category AUTHENTICATION = new Category("Authentication Flaws", new Integer(500));
-
- /** Constant BUFFER_OVERFLOW */
- public final static Category BUFFER_OVERFLOW = new Category("Buffer Overflows", new Integer(600));
-
- /** Constant CODE_QUALITY */
- public final static Category CODE_QUALITY = new Category("Code Quality", new Integer(700));
-
- /** Constant CONCURRENCY */
- public final static Category CONCURRENCY = new Category("Concurrency", new Integer(800));
-
- /** Constant XSS */
- public final static Category XSS = new Category("Cross-Site Scripting (XSS)", new Integer(900));
-
- /** Constant ERROR_HANDLING */
- public final static Category ERROR_HANDLING = new Category("Improper Error Handling", new Integer(1000));
-
- /** Constant INJECTION */
- public final static Category INJECTION = new Category("Injection Flaws", new Integer(1100));
-
- /** Constant DOS */
- public final static Category DOS = new Category("Denial of Service", new Integer(1200));
-
- /** Constant INSECURE_COMMUNICATION */
- public final static Category INSECURE_COMMUNICATION = new Category("Insecure Communication", new Integer(1300));
-
- /** Constant INSECURE_CONFIGURATION */
- public final static Category INSECURE_CONFIGURATION = new Category("Insecure Configuration", new Integer(1400));
-
- /** Constant INSECURE_STORAGE */
- public final static Category INSECURE_STORAGE = new Category("Insecure Storage", new Integer(1500));
-
- /** Constant MALICIOUS_EXECUTION */
- public final static Category MALICIOUS_EXECUTION = new Category("Malicious Execution", new Integer(1600));
-
- /** Constant PARAMETER_TAMPERING */
- public final static Category PARAMETER_TAMPERING = new Category("Parameter Tampering", new Integer(1700));
-
- /** Constant SESSION_MANAGEMENT */
- public final static Category SESSION_MANAGEMENT = new Category("Session Management Flaws", new Integer(1800));
-
- /** Constant WEB_SERVICES */
- public final static Category WEB_SERVICES = new Category("Web Services", new Integer(1900));
-
- /** Constant ADMIN_FUNCTIONS */
- public final static Category ADMIN_FUNCTIONS = new Category("Admin Functions", new Integer(2000));
-
- /** Constant CHALLENGE */
- public final static Category CHALLENGE = new Category("Challenge", new Integer(3000));
-
- private static final List categories = new ArrayList();
-
- private String category;
+ INTRODUCTION("Introduction", new Integer(5)),
+ GENERAL("General", new Integer(100)),
+ ACCESS_CONTROL("Access Control Flaws", new Integer(200)),
+ AJAX_SECURITY("AJAX Security", new Integer(400)),
+ AUTHENTICATION("Authentication Flaws", new Integer(500)),
+ BUFFER_OVERFLOW("Buffer Overflows", new Integer(600)),
+ CODE_QUALITY("Code Quality", new Integer(700)),
+ CONCURRENCY("Concurrency", new Integer(800)),
+ XSS("Cross-Site Scripting (XSS)", new Integer(900)),
+ ERROR_HANDLING("Improper Error Handling", new Integer(1000)),
+ INJECTION("Injection Flaws", new Integer(1100)),
+ DOS("Denial of Service", new Integer(1200)),
+ INSECURE_COMMUNICATION("Insecure Communication", new Integer(1300)),
+ INSECURE_CONFIGURATION("Insecure Configuration", new Integer(1400)),
+ INSECURE_STORAGE("Insecure Storage", new Integer(1500)),
+ MALICIOUS_EXECUTION("Malicious Execution", new Integer(1600)),
+ PARAMETER_TAMPERING("Parameter Tampering", new Integer(1700)),
+ SESSION_MANAGEMENT("Session Management Flaws", new Integer(1800)),
+ WEB_SERVICES("Web Services", new Integer(1900)),
+ ADMIN_FUNCTIONS("Admin Functions", new Integer(2000)),
+ CHALLENGE("Challenge", new Integer(3000));
+ @Getter
+ private String name;
+ @Getter
private Integer ranking;
- static {
- categories.add(INTRODUCTION);
- categories.add(PARAMETER_TAMPERING);
- categories.add(ACCESS_CONTROL);
- categories.add(AUTHENTICATION);
- categories.add(SESSION_MANAGEMENT);
- categories.add(XSS);
- categories.add(BUFFER_OVERFLOW);
- categories.add(INJECTION);
- categories.add(MALICIOUS_EXECUTION);
- categories.add(ERROR_HANDLING);
- categories.add(INSECURE_STORAGE);
- categories.add(DOS);
- categories.add(INSECURE_CONFIGURATION);
- categories.add(WEB_SERVICES);
- categories.add(AJAX_SECURITY);
- categories.add(ADMIN_FUNCTIONS);
- categories.add(GENERAL);
- categories.add(CODE_QUALITY);
- categories.add(CONCURRENCY);
- categories.add(INSECURE_COMMUNICATION);
- categories.add(CHALLENGE);
- }
-
- /**
- *
addCategory.
- *
- * @param c a {@link org.owasp.webgoat.lessons.Category} object.
- */
- public static synchronized void addCategory(Category c) {
- categories.add(c);
- }
-
- /**
- *
Getter for the field category.
- *
- * @param name a {@link java.lang.String} object.
- * @return a {@link org.owasp.webgoat.lessons.Category} object.
- */
- public static synchronized Category getCategory(String name) {
- Iterator it = categories.iterator();
- while (it.hasNext()) {
- Category c = it.next();
- if (c.getName().equals(name)) {
- return c;
- }
- }
- return null;
- }
-
- /**
- *
Constructor for Category.
- *
- * @param category a {@link java.lang.String} object.
- * @param ranking a {@link java.lang.Integer} object.
- */
- public Category(String category, Integer ranking) {
- this.category = category;
+ Category(String name, Integer ranking) {
+ this.name = name;
this.ranking = ranking;
}
- /** {@inheritDoc} */
- @Override
- public int compareTo(Object obj) {
- int value = 1;
-
- if (obj instanceof Category) {
- value = this.getRanking().compareTo(((Category) obj).getRanking());
- }
-
- return value;
- }
-
/**
- *
- *
- * @return a {@link java.lang.String} object.
- */
- public String getName() {
- return category;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean equals(Object obj) {
- return (obj instanceof Category) && getName().equals(((Category) obj).getName());
- }
-
- /** {@inheritDoc} */
@Override
public String toString() {
return getName();
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
index 993c18694..2825ef6e7 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
@@ -30,76 +30,8 @@
*/
package org.owasp.webgoat.lessons;
-import com.google.common.base.Joiner;
-import org.apache.commons.io.IOUtils;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H3;
-import org.apache.ecs.html.P;
-import org.apache.ecs.html.PRE;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.WebSession;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-
public abstract class LessonAdapter extends AbstractLesson {
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s) {
- // Mark this lesson as completed.
- makeSuccess(s);
-
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(new Center().addElement(new H3().addElement(new StringElement(
- "Detailed Lesson Creation Instructions."))));
- ec.addElement(new P());
- ec
- .addElement(new StringElement(
- "Lesson are simple to create and very little coding is required. "
- + "In fact, most lessons can be created by following the easy to use instructions in the "
- + "WebGoat User Guide. "
- + "If you would prefer, send your lesson ideas to "
- + getWebgoatContext().getFeedbackAddressHTML()));
-
- try (InputStream is = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("New Lesson Instructions.txt")) {
- if (is != null) {
- PRE pre = new PRE();
- pre.addElement(Joiner.on("\n").join(IOUtils.readLines(is)));
- ec.addElement(pre);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return (ec);
- }
-
- /**
- * Gets the category attribute of the LessonAdapter object. The default
- * category is "General" Only override this method if you wish to create a
- * new category or if you wish this lesson to reside within a category other
- * the "General"
- *
- * @return The category value
- */
- protected Category getDefaultCategory() {
- return Category.GENERAL;
- }
/**
*
getDefaultHidden.
@@ -129,29 +61,6 @@ public abstract class LessonAdapter extends AbstractLesson {
return DEFAULT_RANKING;
}
- /**
- * {@inheritDoc}
- *
- * Gets the hintCount attribute of the LessonAdapter object
- */
- public int getHintCount(WebSession s) {
- return getHints(s).size();
- }
-
- /**
- * {@inheritDoc}
- *
- * Fill in a minor hint that will help people who basically get it, but are
- * stuck on somthing silly. Hints will be returned to the user in the order
- * they appear below. The user must click on the "next hint" button before
- * the hint will be displayed.
- */
- protected List getHints(WebSession s) {
- List hints = new ArrayList();
- hints.add("There are no hints defined.");
- return hints;
- }
-
/**
* provide a default submitMethod of lesson does not implement
*
@@ -161,44 +70,6 @@ public abstract class LessonAdapter extends AbstractLesson {
return "GET";
}
- /**
- * {@inheritDoc}
- *
- * Gets the instructions attribute of the LessonAdapter object. Instructions
- * will rendered as html and will appear below the control area and above
- * the actual lesson area. Instructions should provide the user with the
- * general setup and goal of the lesson.
- */
- public String getInstructions(WebSession s) {
- StringBuffer buff = new StringBuffer();
- String lang = s.getCurrrentLanguage();
- try {
- String fileName = getLessonPlanFileName(lang);
- if (fileName != null) {
- BufferedReader in = new BufferedReader(new FileReader(fileName));
- String line = null;
- boolean startAppending = false;
- while ((line = in.readLine()) != null) {
- if (line.indexOf("") != -1) {
- startAppending = true;
- continue;
- }
- if (line.indexOf("") != -1) {
- startAppending = false;
- continue;
- }
- if (startAppending) {
- buff.append(line + "\n");
- }
- }
- }
- } catch (Exception e) {
- }
-
- return buff.toString();
-
- }
-
/**
* Fill in a descriptive title for this lesson. The title of the lesson.
* This will appear above the control area at the top of the page. This
@@ -210,71 +81,5 @@ public abstract class LessonAdapter extends AbstractLesson {
return "Untitled Lesson " + getScreenId();
}
- /** {@inheritDoc} */
- public String getCurrentAction(WebSession s) {
- return s.getLessonSession(this).getCurrentLessonScreen();
- }
-
- /** {@inheritDoc} */
- public void setCurrentAction(WebSession s, String lessonScreen) {
- s.getLessonSession(this).setCurrentLessonScreen(lessonScreen);
- }
-
- @Override
- protected Element makeMessages(WebSession s) {
- return super.makeMessages(s);
- }
-
- /**
- *
getSessionAttribute.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @param key a {@link java.lang.String} object.
- * @return a {@link java.lang.Object} object.
- */
- public Object getSessionAttribute(WebSession s, String key) {
- return s.getRequest().getSession().getAttribute(key);
- }
-
- /**
- *
setSessionAttribute.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @param key a {@link java.lang.String} object.
- * @param value a {@link java.lang.Object} object.
- */
- public void setSessionAttribute(WebSession s, String key, Object value) {
- s.getRequest().getSession().setAttribute(key, value);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeSuccess(WebSession s) {
- getLessonTracker(s).setCompleted(true);
-
- //s.setMessage(getLabelManager().get("LessonCompleted"));
-
- return (null);
- }
-
- /**
- * Gets the credits attribute of the AbstractLesson object
- *
- * @return The credits value
- * @param text a {@link java.lang.String} object.
- * @param e a {@link org.apache.ecs.Element} object.
- */
- protected Element getCustomCredits(String text, Element e) {
- Table t = new Table().setCellSpacing(0).setCellPadding(0).setBorder(0).setWidth("90%").setAlign("RIGHT");
- TR tr = new TR();
- tr.addElement(new TD(text).setVAlign("MIDDLE").setAlign("RIGHT").setWidth("100%"));
- tr.addElement(new TD(e).setVAlign("MIDDLE").setAlign("RIGHT"));
- t.addElement(tr);
- return t;
- }
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpointMapping.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpointMapping.java
index a328f992d..94bc84c2c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpointMapping.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonEndpointMapping.java
@@ -39,7 +39,7 @@ import java.lang.annotation.Target;
/**
* Annotation as a marker annotation. During the startup we scan the plugins for classes which use this annotation.
- * @see LessonEndpoint for more information.
+ * @see AssignmentEndpoint for more information.
*/
@Component
@Target(ElementType.TYPE)
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java
index b19db4194..074391ba6 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/NewLesson.java
@@ -1,5 +1,7 @@
package org.owasp.webgoat.lessons;
+import lombok.Getter;
+import lombok.Setter;
import org.owasp.webgoat.session.WebSession;
import java.util.List;
@@ -35,18 +37,28 @@ import java.util.List;
*/
public abstract class NewLesson extends LessonAdapter {
+ @Setter
+ @Getter
+ private int totalNumberOfAssignments = 0;
+
@Override
public abstract Category getDefaultCategory();
- @Override
- public abstract List getHints(WebSession s); //TODO we should probably remove WebSession due to old lessons still here
+ public abstract List getHints();
@Override
- public abstract Integer getDefaultRanking();
+ public abstract Integer getDefaultRanking();
@Override
- public abstract String getTitle();
+ public abstract String getTitle();
@Override
public abstract String getId();
+
+ public final List getHints(WebSession w) {
+ throw new IllegalStateException("Do not use");
+ }
+
+
+
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java
deleted file mode 100644
index e4a815f1c..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java
+++ /dev/null
@@ -1,143 +0,0 @@
-
-package org.owasp.webgoat.lessons;
-
-import org.owasp.webgoat.session.CreateDB;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.RandomLessonTracker;
-import org.owasp.webgoat.session.WebSession;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-
-/**
- *
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- */
- protected Element createStagedContent(WebSession s)
- {
- try
- {
- int stage = getLessonTracker(s).getStage();
- // int stage = Integer.parseInt(
- // getLessonTracker(s).getLessonProperties().getProperty(WebSession.STAGE,"1"));
-
- switch (stage)
- {
- case 1:
- return (doStage1(s));
- case 2:
- return (doStage2(s));
- case 3:
- return (doStage3(s));
- case 4:
- return (doStage4(s));
- case 5:
- return (doStage5(s));
- case 6:
- return (doStage6(s));
- default:
- throw new Exception("Invalid stage");
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- // System.out.println(e);
- e.printStackTrace();
- }
-
- return (new StringElement(""));
- }
-
- /**
- *
doStage1.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage1(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 1 Stub");
- return ec;
- }
-
- /**
- *
doStage2.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage2(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 2 Stub");
- return ec;
- }
-
- /**
- *
doStage3.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage3(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 3 Stub");
- return ec;
- }
-
- /**
- *
doStage4.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage4(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 4 Stub");
- return ec;
- }
-
- /**
- *
doStage5.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage5(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 5 Stub");
- return ec;
- }
-
- /**
- *
doStage6.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- * @throws java.lang.Exception if any.
- */
- protected Element doStage6(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 6 Stub");
- return ec;
- }
-
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java
deleted file mode 100644
index d9ac9328e..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java
+++ /dev/null
@@ -1,159 +0,0 @@
-
-package org.owasp.webgoat.lessons;
-
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.Form;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.*;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class WelcomeScreen extends Screen
-{
-
- /**
- * Constructor for the WelcomeScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public WelcomeScreen(WebSession s)
- {
- setup(s);
- }
-
- /**
- * Constructor for the WelcomeScreen object
- */
- public WelcomeScreen()
- {
- }
-
- /**
- *
setup.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- */
- public void setup(WebSession s)
- {
- // call createContent first so messages will go somewhere
-
- Form form = new Form("attack", Form.POST).setName("form").setEncType("");
-
- form.addElement(wrapForm(s));
-
- TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
- TR row = new TR().addElement(lowerright);
- Table layout = new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);
-
- layout.addElement(row);
-
- setContent(layout);
- }
-
- /**
- *
wrapForm.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- */
- protected Element wrapForm(WebSession s)
- {
- if (s == null) { return new StringElement("Invalid Session"); }
-
- Table container = new Table().setWidth("100%").setCellSpacing(10).setCellPadding(0).setBorder(0);
-
- // CreateContent can generate error messages so you MUST call it before makeMessages()
- Element content = createContent(s);
- container.addElement(new TR().addElement(new TD().setColSpan(2).setVAlign("TOP").addElement(makeMessages(s))));
- container.addElement(new TR().addElement(new TD().setColSpan(2).addElement(content)));
- container.addElement(new TR());
-
- return (container);
- }
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- Element b = ECSFactory.makeButton("Start the Course!");
- ec.addElement(new Center(b));
-
- return (ec);
- }
-
- /**
- * Gets the instructions attribute of the WelcomeScreen object
- *
- * @return The instructions value
- */
- protected String getInstructions()
- {
- String instructions = "Enter your name and learn how HTTP really works!";
-
- return (instructions);
- }
-
- /**
- * Gets the title attribute of the WelcomeScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Welcome to the Penetration Testing Course");
- }
-
- /*
- * (non-Javadoc)
- * @see session.Screen#getRole()
- */
- /**
- *
getRole.
- *
- * @return a {@link java.lang.String} object.
- */
- public String getRole()
- {
- return AbstractLesson.USER_ROLE;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java
deleted file mode 100644
index ea1cbb175..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java
+++ /dev/null
@@ -1,109 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public abstract class AdminScreen extends Screen
-{
-
- /**
- * Description of the Field
- */
- protected String query = null;
-
- /**
- * Constructor for the AdminScreen object
- *
- * @param s
- * Description of the Parameter
- * @param q
- * Description of the Parameter
- */
- public AdminScreen(WebSession s, String q)
- {
- setQuery(q);
-
- // setupAdmin(s); FIXME: what was this supposed to do?
- }
-
- /**
- * Constructor for the AdminScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public AdminScreen(WebSession s)
- {
- }
-
- /**
- * Constructor for the AdminScreen object
- */
- public AdminScreen()
- {
- }
-
- /**
- * Gets the title attribute of the AdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Admin Information");
- }
-
- /**
- *
getRole.
- *
- * @return a {@link java.lang.String} object.
- */
- public String getRole()
- {
- return AbstractLesson.ADMIN_ROLE;
- }
-
- /**
- * Sets the query attribute of the AdminScreen object
- *
- * @param q
- * The new query value
- */
- public void setQuery(String q)
- {
- query = q;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/MenuToLessonMapperScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/MenuToLessonMapperScreen.java
deleted file mode 100644
index 5a5085ef5..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/MenuToLessonMapperScreen.java
+++ /dev/null
@@ -1,162 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.BR;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.WebSession;
-
-import java.net.URL;
-
-import static org.springframework.util.StringUtils.getFilename;
-import static org.springframework.util.StringUtils.stripFilenameExtension;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce Mayhew WebGoat
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class MenuToLessonMapperScreen extends LessonAdapter
-{
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement(new StringElement("This page describes an overview of all the lessons and maps the lesson to the WebGoat-Lessons project"));
- ec.addElement(new BR());
- ec.addElement(new BR());
- ec.addElement(makeMenuToLessonMapping(s));
-
- return ec;
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Lesson information");
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public Element makeMenuToLessonMapping(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1);
- t.addElement(makeHeaderRow());
-
- for (AbstractLesson lesson : s.getCourse().getLessons(s, AbstractLesson.USER_ROLE)) {
- TR tr = new TR();
- tr.addElement(new TD().addElement(lesson.getName()));
-
- URL jarLocation = lesson.getClass().getProtectionDomain().getCodeSource().getLocation();
- String projectName = removeVersion(stripFilenameExtension(getFilename(jarLocation.getFile())));
- tr.addElement(new TD().addElement(projectName));
-
- tr.addElement(new TD().addElement(lesson.getClass().getName() + ".java"));
- t.addElement(tr);
- }
- ec.addElement(t);
- return (ec);
- }
-
- //Remove version number and last '-'
- private static String removeVersion(String s) {
- return s.replaceAll("[^a-z\\-]", "").replaceAll("-$", "");
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- private TR makeHeaderRow()
- {
- TR tr = new TR();
-
- tr.addElement(new TH("Lesson menu item"));
- tr.addElement(new TH("Lesson project"));
- tr.addElement(new TH("Lesson source class"));
-
- return tr;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java
deleted file mode 100644
index 43b74795d..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java
+++ /dev/null
@@ -1,124 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class ProductsAdminScreen extends LessonAdapter
-{
-
- private final static String QUERY = "SELECT * FROM product_system_data";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(QUERY);
-
- if (results != null)
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the ProductsAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- /**
- * Gets the role attribute of the ProductsAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the ProductsAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Product Information");
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java
deleted file mode 100644
index 556701f0b..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java
+++ /dev/null
@@ -1,160 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import org.owasp.webgoat.lessons.*;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.A;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.*;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class RefreshDBScreen extends LessonAdapter
-{
-
- private final static String REFRESH = "Refresh";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- boolean refresh = s.getParser().getBooleanParameter(REFRESH, false);
-
- if (refresh)
- {
- refreshDB(s);
- ec.addElement(new StringElement("Successfully refreshed the database."));
- }
- else
- {
- Element label = new StringElement("Refresh the database? ");
- A link1 = ECSFactory.makeLink("Yes", REFRESH, true);
- A link2 = ECSFactory.makeLink("No", REFRESH, false);
- TD td1 = new TD().addElement(label);
- TD td2 = new TD().addElement(link1);
- TD td3 = new TD().addElement(link2);
- TR row = new TR().addElement(td1).addElement(td2).addElement(td3);
- Table t = new Table().setCellSpacing(40).setWidth("50%");
-
- if (s.isColor())
- {
- t.setBorder(1);
- }
-
- t.addElement(row);
- ec.addElement(t);
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the RefreshDBScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the RefreshDBScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the RefreshDBScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Refresh Database");
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- */
- public void refreshDB(WebSession s)
- {
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- CreateDB db = new CreateDB();
- db.makeDB(connection);
- System.out.println("Successfully refreshed the database.");
- } catch (Exception e)
- {
- s.setMessage("Error refreshing database " + this.getClass().getName());
- e.printStackTrace();
- }
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java
deleted file mode 100644
index 13f31a753..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java
+++ /dev/null
@@ -1,295 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.util.Iterator;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H2;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce Mayhew WebGoat
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class ReportCardScreen extends LessonAdapter
-{
-
- /**
- * Description of the Field
- */
- protected final static String USERNAME = "Username";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- String user = null;
-
- try
- {
- if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
- {
- user = s.getParser().getRawParameter(USERNAME);
- }
- else
- {
- user = s.getUserName();
- }
- } catch (Exception e)
- {
- }
-
- if (user == null)
- {
- user = s.getUserName();
- }
-
- ec.addElement(makeFeedback(s));
- ec.addElement(makeReportCard(s, user));
-
- return ec;
- }
-
- private Element makeFeedback(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement(new StringElement("Comments and suggestions are welcome. "
- + getWebgoatContext().getFeedbackAddressHTML() + "
"));
-
- return ec;
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return USER_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Report Card");
- }
-
- /**
- * Description of the Method
- *
- * @param screen
- * Description of the Parameter
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- private TR makeLessonRow(WebSession s, String user, Screen screen)
- {
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- TR tr = new TR();
- if (lessonTracker.getCompleted())
- {
- tr.setBgColor(HtmlColor.LIGHTGREEN);
- }
- else if (lessonTracker.getNumVisits() == 0)
- {
- tr.setBgColor(HtmlColor.LIGHTBLUE);
- }
- else if (!lessonTracker.getCompleted() && lessonTracker.getNumVisits() > 10)
- {
- tr.setBgColor(HtmlColor.RED);
- }
- else
- {
- tr.setBgColor(HtmlColor.YELLOW);
- }
- tr.addElement(new TD().addElement(screen.getTitle()));
- tr.addElement(new TD().setAlign("CENTER").addElement(lessonTracker.getCompleted() ? "Y" : "N"));
- tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getNumVisits())));
- tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getMaxHintLevel())));
- return tr;
- }
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element makeMessages(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public Element makeReportCard(WebSession s, String user)
- {
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(makeUser(s, user));
- Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1);
-
- if (s.isColor())
- {
- t.setBorder(1);
- }
- TR tr = new TR();
- t.addElement(makeUserHeaderRow());
-
- // These are all the user lesson
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Normal user lessons"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- // The user figured out there was a hackable admin acocunt
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Hackable Admin Screens"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- // The user figured out how to actually hack the admin acocunt
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Actual Admin Screens"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- ec.addElement(t);
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeUser(WebSession s, String user)
- {
- H2 h2 = new H2();
- // FIXME: The session is the current session, not the session of the user we are reporting.
- // String type = s.isAdmin() ? " [Administrative User]" : s.isHackedAdmin() ?
- // " [Normal User - Hacked Admin Access]" : " [Normal User]";
- String type = "";
- h2.addElement(new StringElement("Results for: " + user + type));
- return h2;
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- private TR makeUserHeaderRow()
- {
- TR tr = new TR();
-
- tr.addElement(new TH("Lesson"));
- tr.addElement(new TH("Complete"));
- tr.addElement(new TH("Visits"));
- tr.addElement(new TH("Hints"));
-
- return tr;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java
deleted file mode 100644
index 00225fcc8..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java
+++ /dev/null
@@ -1,326 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.util.Enumeration;
-import java.util.Iterator;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.Input;
-import org.apache.ecs.html.P;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce mayhew WebGoat
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class SummaryReportCardScreen extends LessonAdapter
-{
-
- private int totalUsersNormalComplete = 0;
-
- private int totalUsersAdminComplete = 0;
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- String selectedUser = null;
-
- try
- {
- if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
- {
- Enumeration e = s.getParser().getParameterNames();
-
- while (e.hasMoreElements())
- {
- String key = (String) e.nextElement();
- if (key.startsWith("View_"))
- {
- selectedUser = key.substring("View_".length());
- ReportCardScreen reportCard = new ReportCardScreen();
- return reportCard.makeReportCard(s, selectedUser);
- }
- if (key.startsWith("Delete_"))
- {
- selectedUser = key.substring("Delete_".length());
- deleteUser(selectedUser);
- }
- }
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
-
- ec.addElement(new Center().addElement(makeSummary(s)));
-
- ec.addElement(new P());
-
- Table t = new Table().setCellSpacing(0).setCellPadding(4).setBorder(1).setWidth("100%");
- if (s.isColor())
- {
- t.setBorder(1);
- }
- t.addElement(makeUserSummaryHeader());
-
- for (Iterator userIter = UserTracker.instance().getAllUsers(WebSession.WEBGOAT_USER).iterator(); userIter
- .hasNext();)
- {
-
- String user = userIter.next();
- t.addElement(makeUserSummaryRow(s, user));
- }
-
- ec.addElement(new Center().addElement(t));
-
- return ec;
- }
-
- /**
- *
makeSummary.
- *
- * @param s a {@link org.owasp.webgoat.session.WebSession} object.
- * @return a {@link org.apache.ecs.Element} object.
- */
- protected Element makeSummary(WebSession s)
- {
- Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(0).setWidth("100%");
- if (s.isColor())
- {
- t.setBorder(1);
- }
- TR tr = new TR();
- // tr.addElement( new TH().addElement( "Summary").setColSpan(1));
- // t.addElement( tr );
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users"));
- tr.addElement(new TD().setAlign("LEFT").addElement(
- Integer.toString(UserTracker.instance()
- .getAllUsers(WebSession.WEBGOAT_USER).size())));
- t.addElement(tr);
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all normal lessons"));
- tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersNormalComplete)));
- t.addElement(tr);
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all admin lessons"));
- tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersAdminComplete)));
- t.addElement(tr);
- return t;
- }
-
- private void deleteUser(String user)
- {
- UserTracker.instance().deleteUser(user);
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Summary Report Card");
- }
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element makeMessages(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- protected Element makeUserSummaryHeader()
- {
- TR tr = new TR();
-
- tr.addElement(new TH("User Name"));
- tr.addElement(new TH("Normal Complete"));
- tr.addElement(new TH("Admin Complete"));
- tr.addElement(new TH("View"));
- tr.addElement(new TH("Delete"));
-
- return tr;
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeUserSummaryRow(WebSession s, String user)
- {
- TR tr = new TR();
-
- tr.addElement(new TD().setAlign("LEFT").addElement(user));
- int lessonCount = 0;
- int passedCount = 0;
- boolean normalComplete = false;
- boolean adminComplete = false;
-
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- lessonCount++;
- Screen screen = (Screen) lessonIter.next();
-
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- if (lessonTracker.getCompleted())
- {
- passedCount++;
- }
- }
- if (lessonCount == passedCount)
- {
- normalComplete = true;
- totalUsersNormalComplete++;
- }
- String text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
- tr.addElement(new TD().setAlign("CENTER").addElement(text));
-
- lessonCount = 0;
- passedCount = 0;
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- lessonCount++;
- Screen screen = (Screen) lessonIter.next();
-
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- if (lessonTracker.getCompleted())
- {
- passedCount++;
- }
- }
- if (lessonCount == passedCount)
- {
- adminComplete = true;
- totalUsersAdminComplete++;
- }
- text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
- tr.addElement(new TD().setAlign("CENTER").addElement(text));
-
- tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "View_" + user, "View")));
- tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "Delete_" + user, "Delete")));
-
- if (normalComplete && adminComplete)
- {
- tr.setBgColor(HtmlColor.GREEN);
- }
- else if (normalComplete)
- {
- tr.setBgColor(HtmlColor.LIGHTGREEN);
- }
- else
- {
- tr.setBgColor(HtmlColor.LIGHTBLUE);
- }
-
- return (tr);
- }
-
- /**
- *
isEnterprise.
- *
- * @return a boolean.
- */
- public boolean isEnterprise()
- {
- return true;
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java
deleted file mode 100644
index 7cae656e5..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java
+++ /dev/null
@@ -1,124 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce Mayhew WebGoat
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class UserAdminScreen extends LessonAdapter
-{
-
- private final static String QUERY = "SELECT * FROM user_system_data";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(QUERY);
-
- if (results != null)
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("User Information");
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java
deleted file mode 100644
index c967255ff..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java
+++ /dev/null
@@ -1,165 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import org.owasp.webgoat.lessons.*;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Input;
-import org.owasp.webgoat.session.*;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class ViewDatabase extends LessonAdapter
-{
-
- private final static String SQL = "sql";
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- ec.addElement(new StringElement("Enter a SQL statement: "));
-
- StringBuffer sqlStatement = new StringBuffer(s.getParser().getRawParameter(SQL, ""));
- Input input = new Input(Input.TEXT, SQL, sqlStatement.toString());
- ec.addElement(input);
-
- Element b = ECSFactory.makeButton("Go!");
- ec.addElement(b);
-
- Connection connection = DatabaseUtilities.getConnection(s);
-
- if (sqlStatement.length() > 0)
- {
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(sqlStatement.toString());
-
- if ((results != null) && (results.first() == true))
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
-
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the DatabaseScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- /**
- *
getDefaultRanking.
- *
- * @return a {@link java.lang.Integer} object.
- */
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * {@inheritDoc}
- *
- * Gets the hints attribute of the DatabaseScreen object
- */
- protected List getHints(WebSession s)
- {
- List hints = new ArrayList();
- hints.add("There are no hints defined");
-
- return hints;
- }
-
- /**
- * {@inheritDoc}
- *
- * Gets the instructions attribute of the ViewDatabase object
- */
- public String getInstructions(WebSession s)
- {
- String instructions = "Please post a message to to the WebGoat forum. Your messages will be available for everyone to read.";
-
- return (instructions);
- }
-
- /**
- * Gets the role attribute of the ViewDatabase object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the DatabaseScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Adhoc Query");
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java
deleted file mode 100644
index b6b456a10..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java
+++ /dev/null
@@ -1,87 +0,0 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import org.owasp.webgoat.lessons.WelcomeScreen;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H1;
-import org.owasp.webgoat.session.WebSession;
-
-
-/**
- *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Jeff Williams Aspect Security
- * @since October 28, 2003
- * @version $Id: $Id
- */
-public class WelcomeAdminScreen extends WelcomeScreen
-{
-
- /**
- * Constructor for the WelcomeAdminScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public WelcomeAdminScreen(WebSession s)
- {
- super(s);
- }
-
- /**
- * Constructor for the WelcomeAdminScreen object
- */
- public WelcomeAdminScreen()
- {
- }
-
- /**
- * {@inheritDoc}
- *
- * Description of the Method
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(new Center(new H1("You are logged on as an administrator")));
- ec.addElement(super.createContent(s));
-
- return (ec);
- }
-
- /**
- * Gets the title attribute of the WelcomeAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Admin Welcome");
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonInfoModel.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonInfoModel.java
index a08decbc6..ad661ab59 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonInfoModel.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonInfoModel.java
@@ -1,7 +1,6 @@
package org.owasp.webgoat.lessons.model;
import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
import org.owasp.webgoat.session.WebSession;
/**
@@ -10,6 +9,7 @@ import org.owasp.webgoat.session.WebSession;
* @author dm
* @version $Id: $Id
*/
+//// TODO: 11/5/2016 this can be removed???
public class LessonInfoModel {
private String lessonTitle;
@@ -27,78 +27,11 @@ public class LessonInfoModel {
public LessonInfoModel(WebSession webSession) {
AbstractLesson lesson = webSession.getCurrentLesson();
//TODO make these first class citizens of the lesson itself; and stop passing the session all over ... and generally tighten the checks up
- this.hasSource = !lesson.getSource(webSession).contains("Could not find the source file or source file does not exist");
- this.hasPlan = !lesson.getSource(webSession).contains("Could not find lesson plan");
- this.hasSolution = !lesson.getSolution(webSession).contains("Could not find the solution file or solution file does not exist");
+ this.hasSource = false;
+ this.hasPlan = false;
+ this.hasSolution = false;
this.lessonTitle = lesson.getTitle();
- this.numberHints = lesson.getHintCount(webSession);
+ this.numberHints = lesson.getHintCount();
this.submitMethod = lesson.getSubmitMethod();
-
- if ( this.numberHints < 1 || lesson.getHint(webSession,0).equals("Hint: There are no hints defined.")) {
- this.numberHints = 0;
- }
- //special challenge case
- if (lesson.getCategory().equals(Category.CHALLENGE)) {
- this.numberHints = (lesson.isAuthorized(webSession, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS)) ? lesson.getHintCount(webSession) : 0;
- this.hasSource = (lesson.isAuthorized(webSession, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS));
- this.hasSolution = (lesson.isAuthorized(webSession, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS)); //assuming we want this to fall in line with source and solution
- this.hasPlan = (lesson.isAuthorized(webSession, AbstractLesson.CHALLENGE_ROLE, WebSession.SHOWHINTS)); //assuming we want this to fall in line with source and solutionn
- }
}
-
- // GETTERS
- /**
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * @author Bruce Mayhew WebGoat
- * @version $Id: $Id
- * @since October 28, 2003
- */
-@Slf4j
-public class LegacyLoader {
-
- private final List files = new LinkedList();
-
- /**
- *
Constructor for LegacyLoader.
- */
- public LegacyLoader() {
- }
-
- /**
- * Take an absolute file and return the filename.
- *
- * Ex. /etc/password becomes password
- *
- * @param s
- * @return the file name
- */
- private static String getFileName(String s) {
- String fileName = new File(s).getName();
-
- if (fileName.contains("/")) {
- fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
- }
-
- if (fileName.contains(".")) {
- fileName = fileName.substring(0, fileName.indexOf("."));
- }
-
- return fileName;
- }
-
- /**
- * Take a class name and return the equivalent file name
- *
- * Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
- *
- * @param className
- * @return
- */
- private static String getSourceFile(String className) {
- StringBuilder sb = new StringBuilder();
-
- sb.append(className.replace(".", "/"));
- sb.append(".java");
-
- return sb.toString();
- }
-
- /**
- * Takes a file name and builds the class file name
- *
- * @param fileName Description of the Parameter
- * @param path Description of the Parameter
- * @return Description of the Return Value
- */
- private static String getClassFile(String fileName, String path) {
- String ext = ".class";
- fileName = fileName.trim();
-
- /**
- * We do not handle directories. We do not handle files with different
- * extensions
- */
- if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
- return null;
- }
-
- // skip over plugins and/or extracted plugins
- if (fileName.indexOf("lessons/plugin") >= 0 || fileName.indexOf("plugin_extracted") >= 0) {
- return null;
- }
-
- // if the file is in /WEB-INF/classes strip the dir info off
- int index = fileName.indexOf("/WEB-INF/classes/");
- if (index != -1) {
- fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
- fileName = fileName.replace('/', '.');
- fileName = fileName.replace('\\', '.');
- } else {
- // Strip off the leading path info
- fileName = fileName.substring(path.length(), fileName.length() - ext.length());
- }
-
- return fileName;
- }
-
-
- /**
- * Load all of the filenames into a temporary cache
- *
- * @param context a {@link javax.servlet.ServletContext} object.
- * @param path a {@link java.lang.String} object.
- */
- public void loadFiles(ServletContext context, String path) {
- log.debug("Loading files into cache, path: " + path);
- Resource resource = new ClassPathResource("/");
- //resource.get
- Set resourcePaths = null;
- if (resourcePaths == null) {
- log.error("Unable to load file cache for courses, this is probably a bug or configuration issue");
- return;
- }
- Iterator itr = resourcePaths.iterator();
-
- while (itr.hasNext()) {
- String file = (String) itr.next();
-
- if (file.length() != 1 && file.endsWith("/")) {
- loadFiles(context, file);
- } else {
- files.add(file);
- }
- }
- }
-
- /**
- * Instantiate all the lesson objects into a cache
- *
- * @param path a {@link java.lang.String} object.
- * @param context a {@link javax.servlet.ServletContext} object.
- * @param webgoatContext a {@link org.owasp.webgoat.session.WebgoatContext} object.
- * @param properties a {@link org.owasp.webgoat.session.WebgoatProperties} object.
- * @return a {@link java.util.List} object.
- */
- public List loadLessons(WebgoatContext webgoatContext, ServletContext context, String path, WebgoatProperties properties) {
- BeanDefinitionRegistry bdr = new SimpleBeanDefinitionRegistry();
- ClassPathBeanDefinitionScanner s = new ClassPathBeanDefinitionScanner(bdr);
-
- TypeFilter tf = new AssignableTypeFilter(AbstractLesson.class);
- s.addIncludeFilter(tf);
- s.setIncludeAnnotationConfig(false);
- s.scan("org.owasp.webgoat.lessons.admin");
- String[] beanDefinitionNames = bdr.getBeanDefinitionNames();
-
- List lessons = new LinkedList();
-
- for (String file : beanDefinitionNames) {
- String className = bdr.getBeanDefinition(file).getBeanClassName();
-
- try {
- Class c = Class.forName(className);
- Object o = c.newInstance();
-
- if (o instanceof AbstractLesson) {
- AbstractLesson lesson = (AbstractLesson) o;
- lesson.setWebgoatContext(webgoatContext);
-
- lesson.update(properties);
-
- if (lesson.getHidden() == false) {
- lessons.add(lesson);
- }
- }
- } catch (Exception e) {
- // Bruce says:
- // I don't think we want to log the exception here. We could
- // be potentially showing a lot of exceptions that don't matter.
- // We would only care if the lesson extended AbstractLesson and we
- // can't tell that because it threw the exception. Catch 22
- // logger.error("Error in loadLessons: ", e);
- }
- }
- loadResources(lessons);
- return lessons;
- }
-
- private String getLanguageFromFileName(String first, String absoluteFile) {
- int p1 = absoluteFile.indexOf("/", absoluteFile.indexOf(first) + 1);
- int p2 = absoluteFile.indexOf("/", p1 + 1);
- String langStr = absoluteFile.substring(p1 + 1, p2);
-
- return langStr;
- }
-
- /**
- * For each lesson, set the source file and lesson file
- *
- * @param lessons a {@link java.util.List} object.
- */
- public void loadResources(List lessons) {
- for (AbstractLesson lesson : lessons) {
- log.info("Loading resources for lesson -> " + lesson.getName());
- String className = lesson.getClass().getName();
- String classFile = getSourceFile(className);
- log.info("Lesson classname: " + className);
- log.info("Lesson java file: " + classFile);
-
- for (String absoluteFile : files) {
- String fileName = getFileName(absoluteFile);
- //logger.debug("Course: looking at file: " + absoluteFile);
-
- if (absoluteFile.endsWith(classFile)) {
- log.info("Set source file for " + classFile);
- lesson.setSourceFileName(absoluteFile);
- }
-
- if (absoluteFile.startsWith("/lesson_plans") && absoluteFile.endsWith(".html")
- && className.endsWith(fileName)) {
- log.info("setting lesson plan file " + absoluteFile + " for lesson "
- + lesson.getClass().getName());
- log.info("fileName: " + fileName + " == className: " + className);
- String language = getLanguageFromFileName("/lesson_plans", absoluteFile);
- lesson.setLessonPlanFileName(language, absoluteFile);
- }
- if (absoluteFile.startsWith("/lesson_solutions") && absoluteFile.endsWith(".html")
- && className.endsWith(fileName)) {
- log.info("setting lesson solution file " + absoluteFile + " for lesson "
- + lesson.getClass().getName());
- log.info("fileName: " + fileName + " == className: " + className);
- lesson.setLessonSolutionFileName(absoluteFile);
- }
- }
- }
- }
-
-
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
index f1bdf8cb0..b34a1b351 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
@@ -3,7 +3,7 @@ package org.owasp.webgoat.plugins;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.LessonEndpoint;
+import org.owasp.webgoat.lessons.AssignmentEndpoint;
import org.owasp.webgoat.lessons.NewLesson;
import org.springframework.util.StringUtils;
@@ -28,9 +28,8 @@ public class Plugin {
private static final String NAME_LESSON_PLANS_DIRECTORY = "lessonPlans";
private PluginClassLoader classLoader;
- private Class lesson;
private Class newLesson;
- private List> lessonEndpoints = Lists.newArrayList();
+ private List> lessonEndpoints = Lists.newArrayList();
private Map solutionLanguageFiles = new HashMap<>();
private Map lessonPlansLanguageFiles = new HashMap<>();
private List pluginFiles = Lists.newArrayList();
@@ -40,7 +39,7 @@ public class Plugin {
this.classLoader = classLoader;
}
- public List> getLessonEndpoints() {
+ public List> getLessonEndpoints() {
return this.lessonEndpoints;
}
@@ -56,15 +55,10 @@ public class Plugin {
}
private void findLesson(String name) {
- //Old code remove after we migrated the lessons
String realClassName = StringUtils.trimLeadingCharacter(name, '/').replaceAll("/", ".").replaceAll(".class", "");
try {
Class clazz = classLoader.loadClass(realClassName);
-
- if (AbstractLesson.class.isAssignableFrom(clazz)) {
- this.lesson = clazz;
- }
if (NewLesson.class.isAssignableFrom(clazz)) {
this.newLesson = clazz;
}
@@ -80,7 +74,7 @@ public class Plugin {
try {
Class clazz = classLoader.loadClass(realClassName);
- if (LessonEndpoint.class.isAssignableFrom(clazz)) {
+ if (AssignmentEndpoint.class.isAssignableFrom(clazz)) {
this.lessonEndpoints.add(clazz);
}
} catch (ClassNotFoundException ce) {
@@ -118,14 +112,11 @@ public class Plugin {
*/
public Optional getLesson() {
try {
- if (lesson != null) {
- return Optional.of(lesson.newInstance());
- }
if (newLesson != null) {
return Optional.of(newLesson.newInstance());
}
} catch (IllegalAccessException | InstantiationException e) {
- throw new PluginLoadingFailure("Unable to instantiate the lesson " + lesson.getName(), e);
+ throw new PluginLoadingFailure("Unable to instantiate the lesson " + newLesson.getName(), e);
}
return Optional.absent();
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
index e07206f25..5139a19f7 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
@@ -3,8 +3,7 @@ package org.owasp.webgoat.plugins;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
-import org.owasp.webgoat.util.LabelProvider;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.owasp.webgoat.i18n.LabelProvider;
import org.springframework.util.ResourceUtils;
import java.io.File;
@@ -43,7 +42,6 @@ public class PluginsLoader {
private final File pluginTargetDirectory;
private final PluginClassLoader classLoader;
- @Autowired
public PluginsLoader(File pluginTargetDirectory, PluginClassLoader pluginClassLoader) {
this.classLoader = pluginClassLoader;
this.pluginTargetDirectory = pluginTargetDirectory;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java
deleted file mode 100644
index aec0d2076..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- */
-package org.owasp.webgoat.service;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import org.owasp.webgoat.session.WebSession;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-/**
- *
- *
- * @param request a {@link javax.servlet.http.HttpServletRequest} object.
- * @param ex a {@link java.lang.Exception} object.
- * @return a {@link org.owasp.webgoat.service.ExceptionInfo} object.
- */
- @ExceptionHandler(Exception.class)
- @ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT)
- public @ResponseBody
- ExceptionInfo handleException(HttpServletRequest request, Exception ex) {
- String url = request.getRequestURL().toString();
- logger.error("Exception handler for service caught exception when processing: " + url, ex);
- ExceptionInfo response = new ExceptionInfo();
- response.setUrl(url);
-
- response.setMessage(getStringStackTrace(ex));
-
- return response;
- }
-
- /**
- *
getWebSession.
- *
- * @param session a {@link javax.servlet.http.HttpSession} object.
- * @return a {@link org.owasp.webgoat.session.WebSession} object.
- */
- public WebSession getWebSession(HttpSession session) {
- WebSession ws;
- Object o = session.getAttribute(WebSession.SESSION);
- if (o == null) {
- throw new IllegalArgumentException("No valid WebSession object found, has session timed out? [" + session.getId() + "]");
- }
- if (!(o instanceof WebSession)) {
- throw new IllegalArgumentException("Invalid WebSession object found, this is probably a bug! [" + o.getClass() + " | " + session.getId() + "]");
- }
- ws = (WebSession) o;
- return ws;
- }
-
- /**
- *
getStringStackTrace.
- *
- * @param t a {@link java.lang.Throwable} object.
- * @return a {@link java.lang.String} object.
- */
- public String getStringStackTrace(Throwable t){
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- t.printStackTrace(pw);
- return sw.toString();
- }
-}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
index 69dd9e8fa..fd9f55ae0 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
@@ -29,16 +29,13 @@
*/
package org.owasp.webgoat.service;
-import org.owasp.webgoat.lessons.model.RequestParameter;
-import org.owasp.webgoat.session.WebSession;
+import com.google.common.collect.Lists;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
-import java.util.Collections;
import java.util.List;
/**
@@ -48,7 +45,7 @@ import java.util.List;
* @version $Id: $Id
*/
@Controller
-public class CookieService extends BaseService {
+public class CookieService {
/**
* Returns cookies for last attack
@@ -56,30 +53,11 @@ public class CookieService extends BaseService {
* @param session a {@link javax.servlet.http.HttpSession} object.
* @return a {@link java.util.List} object.
*/
- @RequestMapping(path = "/cookie.mvc", produces = "application/json")
+ @RequestMapping(path = "/service/cookie.mvc", produces = "application/json")
public @ResponseBody
- List showCookies(HttpSession session) {
- WebSession ws = getWebSession(session);
- List cookies = ws.getCookiesOnLastRequest();
+ List showCookies() {
+ //// TODO: 11/6/2016 to be decided
+ List cookies = Lists.newArrayList();
return cookies;
}
-
- /**
- * Returns cookies and params for current lesson
- *
- * @param session a {@link javax.servlet.http.HttpSession} object.
- * @return a {@link org.springframework.web.servlet.ModelAndView} object.
- */
- @RequestMapping(value = "/cookies_widget.mvc", produces = "text/html")
- public ModelAndView showCookiesAndParamsAsHtml(HttpSession session) {
- ModelAndView model = new ModelAndView();
- WebSession ws = getWebSession(session);
- List cookies = ws.getCookiesOnLastRequest();
- List listParms = ws.getParmsOnLastRequest();
- Collections.sort(listParms);
- model.addObject("wgcookies", cookies);
- model.addObject("wgparams", listParms);
- model.setViewName("widgets/cookies_and_params");
- return model;
- }
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java
deleted file mode 100644
index 80b40bef1..000000000
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- */
-package org.owasp.webgoat.service;
-
-/**
- *
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
- *
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *