Lesson Plan Title: Malicious File Execution

Concept / Topic To Teach:
Many sites allow the user to upload files, such as images or videos. Without the proper security, files containing malicious commands can be and then executed on the server.

General Goal(s):
The form below allows you to upload an image which will be displayed on this page. Features like this are often found on web based discussion boards and social networking sites. This feature is vulnerable to Malicious File Execution.
In order to pass this lession, upload and run a malicious file. In order to prove that your file can execute, it should create another file named guest.txt
Once you have created this file, you will pass the lesson.

Solution:
The first step of malicious file execution is to create a file that we can run on the server. In this lesson, our goal is to create the file guest.txt in the directory provided in the lesson (the path is generated based on your system).
To do this, we write a .jsp file that uses the java createNewFile() command. The file contents will look like this:
<HTML> <% java.io.File file = new java.io.File("filepath\\guest.txt"); file.createNewFile(); %> </HTML>
The <% indicates that the upcoming code is a java servlet, so java code is allowed. Make sure you fill in the filepath correctly - each directory must be separated by \\, not \. The filename of the .jsp doesn't matter, as long as you know what it is.
Next, we need to figure out where the files are being uploaded so we can execute them. In this case, since we are shown the image, this is very easy. Upload an image using the form, then right click on it and check its properties.
Viewing properties of the uploaded image in Firefox.
File path for the uploaded image (and our .jsp) in Firefox.
The URL should look something like http://localhost/webgoat/uploads/image.jpg.
The last step is to upload our malicious .jsp and browse to it so it will execute. Upload the file, then type its address into your browser. The address should be something like http://localhost/webgoat/uploads/yourfile.jsp.
A blank page will load. You can then return to the lesson and refresh, completing the lesson.