Initial Commit of SSRF Lesson
This commit is contained in:
parent
5ba6492684
commit
98f75e34d5
@ -34,6 +34,7 @@
|
||||
<module>missing-function-ac</module>
|
||||
<module>csrf</module>
|
||||
<module>password-reset</module>
|
||||
<module>ssrf</module>
|
||||
<!-- uncomment below to include lesson template in build, also uncomment the dependency in webgoat-server/pom.xml to have it run in the project fully -->
|
||||
<!--<module>webgoat-lesson-template</module>-->
|
||||
</modules>
|
||||
|
34
webgoat-lessons/ssrf/pom.xml
Executable file
34
webgoat-lessons/ssrf/pom.xml
Executable file
@ -0,0 +1,34 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ssrf</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<parent>
|
||||
<groupId>org.owasp.webgoat.lesson</groupId>
|
||||
<artifactId>webgoat-lessons-parent</artifactId>
|
||||
<version>v8.0.0.SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<version>4.1.3.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
63
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRF.java
Executable file
63
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRF.java
Executable file
@ -0,0 +1,63 @@
|
||||
package org.owasp.webgoat.plugin;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import org.owasp.webgoat.lessons.Category;
|
||||
import org.owasp.webgoat.lessons.NewLesson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ************************************************************************************************
|
||||
* This file is part of WebGoat, an Open Web Application Security Project utility. For details,
|
||||
* please see http://www.owasp.org/
|
||||
* <p>
|
||||
* Copyright (c) 2002 - 20014 Bruce Mayhew
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Getting Source ==============
|
||||
* <p>
|
||||
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
|
||||
* projects.
|
||||
* <p>
|
||||
*
|
||||
* @author WebGoat
|
||||
* @version $Id: $Id
|
||||
* @since October 12, 2016
|
||||
*/
|
||||
public class SSRF extends NewLesson {
|
||||
@Override
|
||||
public Category getDefaultCategory() {
|
||||
return Category.REQUEST_FORGERIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHints() {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDefaultRanking() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "ssrf.title";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "SSRF";
|
||||
}
|
||||
}
|
98
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRFTask1.java
Executable file
98
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRFTask1.java
Executable file
@ -0,0 +1,98 @@
|
||||
package org.owasp.webgoat.plugin;
|
||||
|
||||
import org.owasp.webgoat.assignments.AssignmentEndpoint;
|
||||
import org.owasp.webgoat.assignments.AssignmentHints;
|
||||
import org.owasp.webgoat.assignments.AssignmentPath;
|
||||
import org.owasp.webgoat.assignments.AttackResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.sun.net.httpserver.Authenticator.Success;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
|
||||
/**
|
||||
* *************************************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of WebGoat, an Open Web Application Security Project
|
||||
* utility. For details, please see http://www.owasp.org/
|
||||
*
|
||||
* Copyright (c) 2002 - 2014 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.
|
||||
*
|
||||
* For details, please see http://webgoat.github.io
|
||||
*
|
||||
* @author Alex Fry <a href="http://code.google.com/p/webgoat">WebGoat</a>
|
||||
* @created December 26, 2018
|
||||
*/
|
||||
@AssignmentPath("/SSRF/task1")
|
||||
@AssignmentHints({"ssrf.hint1","ssrf.hint2"})
|
||||
public class SSRFTask1 extends AssignmentEndpoint {
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
|
||||
AttackResult completed(@RequestParam String url) throws IOException {
|
||||
return stealTheCheese(url);
|
||||
}
|
||||
|
||||
protected AttackResult stealTheCheese(String url) {
|
||||
try {
|
||||
StringBuffer html = new StringBuffer();
|
||||
|
||||
if (url.matches("images/tom.png")) {
|
||||
html.append("<img class=\"image\" alt=\"Tom\" src=\"images/tom.png\" width=\"25%\" height=\"25%\">");
|
||||
return trackProgress(failed()
|
||||
.feedback("ssrf.tom")
|
||||
.output(html.toString())
|
||||
.build());
|
||||
}else if (url.matches("images/jerry.png")){
|
||||
html.append("<img class=\"image\" alt=\"Jerry\" src=\"images/jerry.png\" width=\"25%\" height=\"25%\">");
|
||||
return trackProgress(success()
|
||||
.feedback("ssrf.success")
|
||||
.output(html.toString())
|
||||
.build());
|
||||
}else{
|
||||
html.append("<img class=\"image\" alt=\"Silly Cat\" src=\"images/cat.jpg\">");
|
||||
return trackProgress(failed()
|
||||
.feedback("ssrf.failure")
|
||||
.output(html.toString())
|
||||
.build());
|
||||
}
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return trackProgress(failed()
|
||||
.output(e.getMessage())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
101
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRFTask2.java
Executable file
101
webgoat-lessons/ssrf/src/main/java/org/owasp/webgoat/plugin/SSRFTask2.java
Executable file
@ -0,0 +1,101 @@
|
||||
package org.owasp.webgoat.plugin;
|
||||
|
||||
import org.owasp.webgoat.assignments.AssignmentEndpoint;
|
||||
import org.owasp.webgoat.assignments.AssignmentHints;
|
||||
import org.owasp.webgoat.assignments.AssignmentPath;
|
||||
import org.owasp.webgoat.assignments.AttackResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.sun.net.httpserver.Authenticator.Success;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
|
||||
/**
|
||||
* *************************************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of WebGoat, an Open Web Application Security Project
|
||||
* utility. For details, please see http://www.owasp.org/
|
||||
*
|
||||
* Copyright (c) 2002 - 2014 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.
|
||||
*
|
||||
* For details, please see http://webgoat.github.io
|
||||
*
|
||||
* @author Alex Fry <a href="http://code.google.com/p/webgoat">WebGoat</a>
|
||||
* @created December 26, 2018
|
||||
*/
|
||||
@AssignmentPath("/SSRF/task2")
|
||||
@AssignmentHints({"ssrf.hint3"})
|
||||
public class SSRFTask2 extends AssignmentEndpoint {
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
|
||||
AttackResult completed(@RequestParam String url) throws IOException {
|
||||
return furBall(url);
|
||||
}
|
||||
|
||||
protected AttackResult furBall(String url) {
|
||||
try {
|
||||
StringBuffer html = new StringBuffer();
|
||||
|
||||
if (url.matches("http://ifconfig.pro")){
|
||||
URL u = new URL(url);
|
||||
URLConnection urlConnection = u.openConnection();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
String inputLine;
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
html.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
return trackProgress(success()
|
||||
.feedback("ssrf.success")
|
||||
.output(html.toString())
|
||||
.build());
|
||||
}else{
|
||||
html.append("<img class=\"image\" alt=\"image post\" src=\"images/cat.jpg\">");
|
||||
return trackProgress(failed()
|
||||
.feedback("ssrf.failure")
|
||||
.output(html.toString())
|
||||
.build());
|
||||
}
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return trackProgress(failed()
|
||||
.output(e.getMessage())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
58
webgoat-lessons/ssrf/src/main/resources/html/SSRF.html
Executable file
58
webgoat-lessons/ssrf/src/main/resources/html/SSRF.html
Executable file
@ -0,0 +1,58 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<div class="lesson-page-wrapper">
|
||||
<div class="adoc-content" th:replace="doc:SSRF_Intro.adoc"></div>
|
||||
</div>
|
||||
|
||||
<div class="lesson-page-wrapper">
|
||||
<div class="adoc-content" th:replace="doc:SSRF_Task1.adoc"></div>
|
||||
<div class="attack-container">
|
||||
<div class="assignment-success"><i class="fa fa-2 fa-check hidden" aria-hidden="true"></i></div>
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
method="POST" name="form"
|
||||
action="/WebGoat/SSRF/task1"
|
||||
enctype="application/json;charset=UTF-8">
|
||||
<table>
|
||||
<tr>
|
||||
<input type="hidden" id="url" name="url" value="images/tom.png"/>
|
||||
|
||||
<td><input
|
||||
name="Steal the Cheese" value="Steal the Cheese" type="SUBMIT"/></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<div class="attack-feedback"></div>
|
||||
<div class="attack-output"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="lesson-page-wrapper">
|
||||
<div class="adoc-content" th:replace="doc:SSRF_Task2.adoc"></div>
|
||||
<div class="attack-container">
|
||||
<div class="assignment-success"><i class="fa fa-2 fa-check hidden" aria-hidden="true"></i></div>
|
||||
<form class="attack-form" accept-charset="UNKNOWN"
|
||||
method="POST" name="form"
|
||||
action="/WebGoat/SSRF/task2"
|
||||
enctype="application/json;charset=UTF-8">
|
||||
<table>
|
||||
<tr>
|
||||
<input type="hidden" id="url" name="url" value="images/cat.png"/>
|
||||
|
||||
<td><input
|
||||
name="Run Ifconfig" value="Run Ifconfig" type="SUBMIT"/></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<div class="attack-feedback"></div>
|
||||
<div class="attack-output"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="lesson-page-wrapper">
|
||||
<div class="adoc-content" th:replace="doc:SSRF_Prevent.adoc"></div>
|
||||
</div>
|
||||
</html>
|
9
webgoat-lessons/ssrf/src/main/resources/i18n/WebGoatLabels.properties
Executable file
9
webgoat-lessons/ssrf/src/main/resources/i18n/WebGoatLabels.properties
Executable file
@ -0,0 +1,9 @@
|
||||
ssrf.title=Server-Side Request Forgery
|
||||
|
||||
ssrf.tom=You failed to steal the cheese!
|
||||
ssrf.success=You rocked the SSRF!
|
||||
ssrf.failure=You need to stick to the game plan!
|
||||
|
||||
ssrf.hint1=You should use an HTTP proxy to intercept the request and change the URL.
|
||||
ssrf.hint2=If Tom is images/tom.png, Jerry would be images/jerry.png.
|
||||
ssrf.hint3=You need to put the protocol, "http://" in front of ifconfig.pro.
|
BIN
webgoat-lessons/ssrf/src/main/resources/images/cat.jpg
Normal file
BIN
webgoat-lessons/ssrf/src/main/resources/images/cat.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
BIN
webgoat-lessons/ssrf/src/main/resources/images/jerry.png
Normal file
BIN
webgoat-lessons/ssrf/src/main/resources/images/jerry.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 100 KiB |
BIN
webgoat-lessons/ssrf/src/main/resources/images/tom.png
Normal file
BIN
webgoat-lessons/ssrf/src/main/resources/images/tom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 217 KiB |
6
webgoat-lessons/ssrf/src/main/resources/js/credentials.js
Executable file
6
webgoat-lessons/ssrf/src/main/resources/js/credentials.js
Executable file
@ -0,0 +1,6 @@
|
||||
function submit_secret_credentials() {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp['open']('POST', '#attack/307/100', true);
|
||||
//sending the request is obfuscated, to descourage js reading
|
||||
var _0xb7f9=["\x43\x61\x70\x74\x61\x69\x6E\x4A\x61\x63\x6B","\x42\x6C\x61\x63\x6B\x50\x65\x61\x72\x6C","\x73\x74\x72\x69\x6E\x67\x69\x66\x79","\x73\x65\x6E\x64"];xhttp[_0xb7f9[3]](JSON[_0xb7f9[2]]({username:_0xb7f9[0],password:_0xb7f9[1]}))
|
||||
}
|
12
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Intro.adoc
Executable file
12
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Intro.adoc
Executable file
@ -0,0 +1,12 @@
|
||||
|
||||
== Concept
|
||||
In a Server-Side Request Forgery (SSRF) attack, the attacker can abuse functionality on the server to read or update internal resources. The attacker can supply or a modify a URL which the code running on the server will read or submit data to, and by carefully selecting the URLs, the attacker may be able to read server configuration such as AWS metadata, connect to internal services like http enabled databases or perform post requests towards internal services which are not intended to be exposed.
|
||||
|
||||
== Goals
|
||||
* The user will need to modify the URL.
|
||||
|
||||
== SSRF How-To
|
||||
* https://www.hackerone.com/blog-How-To-Server-Side-Request-Forgery-SSRF
|
||||
|
||||
== A New Era of SSRF by Orange Tsai
|
||||
* https://www.youtube.com/watch?v=D1S-G8rJrEk
|
10
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Prevent.adoc
Executable file
10
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Prevent.adoc
Executable file
@ -0,0 +1,10 @@
|
||||
|
||||
== Prevent
|
||||
To prevent SSRF vulnerabilities in web applications, it is recommended to adhere to the following guidelines:
|
||||
|
||||
* Use a whitelist of allowed domains, resources and protocols from where the web server can fetch resources.
|
||||
* Any input accepted from the user should be validated and rejected if it does not match the positive specification expected.
|
||||
* If possible, do not accept user input in functions that control where the web server can fetch resources.
|
||||
|
||||
== References
|
||||
* https://www.owasp.org/index.php/Server_Side_Request_Forgery
|
2
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Task1.adoc
Executable file
2
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Task1.adoc
Executable file
@ -0,0 +1,2 @@
|
||||
=== Change the URL to display Jerry
|
||||
|
2
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Task2.adoc
Executable file
2
webgoat-lessons/ssrf/src/main/resources/lessonPlans/en/SSRF_Task2.adoc
Executable file
@ -0,0 +1,2 @@
|
||||
=== Change the URL to display the Interface Configuration with ifconfig.pro
|
||||
|
@ -0,0 +1,52 @@
|
||||
package org.owasp.webgoat.plugin;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.owasp.webgoat.plugins.LessonTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author afry
|
||||
* @since 12/28/18.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SSRFTest1 extends LessonTest {
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
SSRF ssrf = new SSRF();
|
||||
when(webSession.getCurrentLesson()).thenReturn(ssrf);
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyUrlTom() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/SSRF/task1")
|
||||
.param("url", "images/tom.png"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyUrlJerry() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/SSRF/task1")
|
||||
.param("url", "images/jerry.png"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyUrlCat() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/SSRF/task1")
|
||||
.param("url", "images/cat.jpg"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false)));
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package org.owasp.webgoat.plugin;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.owasp.webgoat.plugins.LessonTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author afry
|
||||
* @since 12/28/18.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SSRFTest2 extends LessonTest {
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
SSRF ssrf = new SSRF();
|
||||
when(webSession.getCurrentLesson()).thenReturn(ssrf);
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyUrlIfconfigPro() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/SSRF/task2")
|
||||
.param("url", "http://ifconfig.pro"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifyUrlCat() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/SSRF/task2")
|
||||
.param("url", "images/cat.jpg"))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false)));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user