fixed sql adv 5 progress and added prove in integration test
This commit is contained in:
parent
c93563da3f
commit
924a53c22a
@ -51,7 +51,11 @@ public class SqlInjectionChallenge extends AssignmentEndpoint {
|
|||||||
ResultSet resultSet = statement.executeQuery(checkUserQuery);
|
ResultSet resultSet = statement.executeQuery(checkUserQuery);
|
||||||
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
attackResult = failed().feedback("user.exists").feedbackArgs(username_reg).build();
|
if (username_reg.contains("tom'")) {
|
||||||
|
attackResult = trackProgress(success().feedback("user.exists").build());
|
||||||
|
} else {
|
||||||
|
attackResult = failed().feedback("user.exists").feedbackArgs(username_reg).build();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO " + USERS_TABLE_NAME + " VALUES (?, ?, ?)");
|
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO " + USERS_TABLE_NAME + " VALUES (?, ?, ?)");
|
||||||
preparedStatement.setString(1, username_reg);
|
preparedStatement.setString(1, username_reg);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.owasp.webgoat.plugin.advanced;
|
package org.owasp.webgoat.plugin.advanced;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.owasp.webgoat.assignments.AssignmentEndpoint;
|
import org.owasp.webgoat.assignments.AssignmentEndpoint;
|
||||||
import org.owasp.webgoat.assignments.AssignmentHints;
|
import org.owasp.webgoat.assignments.AssignmentHints;
|
||||||
import org.owasp.webgoat.assignments.AssignmentPath;
|
import org.owasp.webgoat.assignments.AssignmentPath;
|
||||||
@ -18,7 +16,6 @@ import java.sql.*;
|
|||||||
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||||
|
|
||||||
@AssignmentPath("/SqlInjectionAdvanced/challenge_Login")
|
@AssignmentPath("/SqlInjectionAdvanced/challenge_Login")
|
||||||
@Slf4j
|
|
||||||
@AssignmentHints(value ={"SqlInjectionChallengeHint1", "SqlInjectionChallengeHint2", "SqlInjectionChallengeHint3", "SqlInjectionChallengeHint4"})
|
@AssignmentHints(value ={"SqlInjectionChallengeHint1", "SqlInjectionChallengeHint2", "SqlInjectionChallengeHint3", "SqlInjectionChallengeHint4"})
|
||||||
public class SqlInjectionChallengeLogin extends AssignmentEndpoint {
|
public class SqlInjectionChallengeLogin extends AssignmentEndpoint {
|
||||||
|
|
||||||
@ -29,7 +26,6 @@ public class SqlInjectionChallengeLogin extends AssignmentEndpoint {
|
|||||||
@RequestMapping(method = POST)
|
@RequestMapping(method = POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AttackResult login(@RequestParam String username_login, @RequestParam String password_login) throws Exception {
|
public AttackResult login(@RequestParam String username_login, @RequestParam String password_login) throws Exception {
|
||||||
System.out.println("right Method");
|
|
||||||
Connection connection = DatabaseUtilities.getConnection(webSession);
|
Connection connection = DatabaseUtilities.getConnection(webSession);
|
||||||
SqlInjectionChallenge.checkDatabase(connection);
|
SqlInjectionChallenge.checkDatabase(connection);
|
||||||
|
|
||||||
@ -39,8 +35,8 @@ public class SqlInjectionChallengeLogin extends AssignmentEndpoint {
|
|||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return ("tom".equals(username_login)) ? success().build()
|
return ("tom".equals(username_login)) ? trackProgress(success().build())
|
||||||
: success().feedback("ResultsButNotTom").build();
|
: success().feedback("ResultsButNotTom").build();
|
||||||
} else {
|
} else {
|
||||||
return failed().feedback("NoResultsMatched").build();
|
return failed().feedback("NoResultsMatched").build();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,18 @@ public class SqlInjectionAdvanced_TestHelper extends TestHelper {
|
|||||||
startLesson(cookie, webgoatURL, "SqlInjectionAdvanced");
|
startLesson(cookie, webgoatURL, "SqlInjectionAdvanced");
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.clear();
|
||||||
|
params.put("username_reg", "tom' AND substring(password,1,1)='t");
|
||||||
|
params.put("password_reg", "password");
|
||||||
|
params.put("email_reg", "someone@microsoft.com");
|
||||||
|
params.put("confirm_password", "password");
|
||||||
|
checkAssignmentWithPUT(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/challenge", params, true);
|
||||||
|
|
||||||
|
params.clear();
|
||||||
|
params.put("username_login", "tom");
|
||||||
|
params.put("password_login", "thisisasecretfortomonly");
|
||||||
|
checkAssignment(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/challenge_Login", params, true);
|
||||||
|
|
||||||
params.clear();
|
params.clear();
|
||||||
params.put("userid_6a", "'; SELECT * FROM user_system_data;--");
|
params.put("userid_6a", "'; SELECT * FROM user_system_data;--");
|
||||||
checkAssignment(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/attack6a", params, true);
|
checkAssignment(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/attack6a", params, true);
|
||||||
@ -30,7 +42,7 @@ public class SqlInjectionAdvanced_TestHelper extends TestHelper {
|
|||||||
params.put("question_4_solution", "Solution 4: The database registers 'Robert' ); DROP TABLE Students;--'.");
|
params.put("question_4_solution", "Solution 4: The database registers 'Robert' ); DROP TABLE Students;--'.");
|
||||||
checkAssignment(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/quiz", params, true);
|
checkAssignment(cookie, webgoatURL+"/WebGoat/SqlInjectionAdvanced/quiz", params, true);
|
||||||
|
|
||||||
//checkResults(cookie, webgoatURL, "/SqlInjectionAdvanced/");
|
checkResults(cookie, webgoatURL, "/SqlInjectionAdvanced/");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,29 @@ public class TestHelper {
|
|||||||
.extract().path("lessonCompleted"), is(expectedResult));
|
.extract().path("lessonCompleted"), is(expectedResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method for most common type of test.
|
||||||
|
* PUT with parameters.
|
||||||
|
* Checks for 200 and lessonCompleted as indicated by expectedResult
|
||||||
|
* @param webgoatCookie
|
||||||
|
* @param url
|
||||||
|
* @param params
|
||||||
|
* @param expectedResult
|
||||||
|
*/
|
||||||
|
public void checkAssignmentWithPUT(String webgoatCookie, String url, Map<String, ?> params, boolean expectedResult) {
|
||||||
|
assertThat(
|
||||||
|
given()
|
||||||
|
.when()
|
||||||
|
.config(restConfig)
|
||||||
|
.cookie("JSESSIONID", webgoatCookie)
|
||||||
|
.formParams(params)
|
||||||
|
.put(url)
|
||||||
|
.then()
|
||||||
|
//.log().all()
|
||||||
|
.statusCode(200)
|
||||||
|
.extract().path("lessonCompleted"), is(expectedResult));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method at the end of a lesson.
|
* Helper method at the end of a lesson.
|
||||||
* Check if all path paramters are correct for the progress.
|
* Check if all path paramters are correct for the progress.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user