-
Notifications
You must be signed in to change notification settings - Fork 459
How to Create a Web Shepherd Level
This wiki page will attempt to guide new Shepherd contributors in the effort of creating a Web Based level with View, Controller and Model type functionality. Where each piece operates the following type functionality;
- View
The view can be a web page, a mobile application or both. You could write a level that is simply one View, which stores a hard coded key for the user to find. Most mobile levels have two views, the Web page with instructions on the Shepherd Web Server and the Android Application.- Controller
The Controller is a Java Servlet that operates on the Shepherd Server. They are accessed by clients via url-mapping defined in the Shepherd Server's web.xml file. Many levels are made up of a View/Controller combo, with hardcoded base-keys which are made user specific when players complete the level.- Model
Not all levels in Security Shepherd offer model functionality, but it can be done. If a level needs a database, the schema is written and added to the moduleSchemas.sql file and a user defined for it. This user has READ ONLY access to the specified schema. It's not recommended to give any other permissions to the user without great care.
This wiki page will detail how to craft these aspects of a level.
Every level in Security Shepherd needs a .jsp page. This page tells a user what they have to do, revels hints and when the level is a lesson (First time a user encounters this type of security risk), it contains a description of the vulnerability. To Create this, use the following steps
- Open the directory "owaspSecurityShepherd\SecurityShepherdCore\src\jsp" in your local git repository
- Open the WebLevelTemplate.jsp or MobileLevelTemplate.jsp file, depending on which you are making
- Fill in the
levelName
parameter. This will be the name shown in the page and what will be entered into the logs as players access it. - You must go to the Create a Level Entry wiki page to get the
levelHash
parameter information - You can fill in the level information in the
levelBlurb
parameter if you like, or you can go down to the "contentDiv"element to write your own HTML. - If your .jsp is going to call a Controller on the web server, you can uncomment the form/javascript examples on how to do so starting at line 69 (This is unlikely to be necessary if you are making a mobile level)
- If calling a Servlet, Take note of what URL you are defining the javascript ajax call. You will need to use this in the servlet-mapping stage
- When you have completed the view, save the file as the
levelHash
.jsp (The hash you recovered from step 4) and put it in the Challenge or Lesson directory depending on which you have defined in step 4. - Open the Directory owaspSecurityShepherd\SecurityShepherdCore\src\servlets\module
- Open the file ModuleServletTemplate.java
- Update the
moduleName
,moduleHash
andmoduleResult
to match your DB settings. - Skip down to line 76, and add in the code you need to get the data submitted by the user in from the View portion of this level
- You can access the model from here as well, the template covers how, but the next section of this wiki will detail how to create it.
- If you wish to return user specific keys (Recommended where ever possible), use the template example.
- If your level has a hardcoded key, make sure it is the same in the level as it is in the DB. Also ensure the hardcoded flag is set in the module database entry in the core database.
- Once you have finished coding and your logic is sound, open the owaspSecurityShepherd\SecurityShepherdCore\site\WEB-INF directory
- Add the following infrormation to the XML file, updating the
levelhash
to the module level hash,ServletClassName
to the servlet class name and "challenges" to "lessons" if necessary; - After adding this information you can now test your Servlet. If you get a 404 error when trying to access the servlet, it is likely what your browser or client are attempting to access does not specifically match
- Open the owaspSecurityShepherd\SecurityShepherdCore\database\moduleSchemas.sql file
- Add a mySql Schema to it containing your level's database structure
- At the end of the file add a user with READ ONLY access like so;
- Then open the owaspSecurityShepherd\SecurityShepherdCore\site\WEB-INF\challenges directory and create a .properties file (You will have to call this properties file in your controller)
- Enter the following information into the file;
- Run the moduleSchemas.sql file on your database
- Build the Shepherd application
- You're level should now be calling the DB
The controller of a level is the brain of a level. This is most likely going to be the logic which the users will be attempting to exploit. To create this, use the following steps;
<servlet>
<servlet-name>/challenges/levelhash
</servlet-name>
<servlet-class>servlets.module.challenge.ServletClassName
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>/challenges/levelhash
</servlet-name>
<url-pattern>/challenges/levelhash
</url-pattern>
</servlet-mapping>
Model is the server side database. Follow these steps to make one and get your level to access it
DROP USER
creativeName
@'localhost';
CREATE USERcreativeName
@'localhost' IDENTIFIED BYsomePasswordHere
;
GRANT SELECT ONchallengeSchemaName
.challengeTableName
TOcreativeName
;
databaseConnectionURL=
challengeSchemaName
databaseUsername=creativeName
databasePassword=somePasswordHere
IF YOU MUST HAVE UPDATE PRIVILEGES ON YOUR SCHEMA FOR PLAYERS, PRACTISE EXTREME CAUTION AND BE AWARE OF RACE CONDITIONS