Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d5d9bf7
commit message
StefaniaOYoda Jan 22, 2025
0665f00
commit message
StefaniaOYoda Jan 22, 2025
7645d08
Delete =main
StefaniaOYoda Jan 22, 2025
42be25d
Delete =AIcode
StefaniaOYoda Jan 22, 2025
291b64f
commit message
StefaniaOYoda Jan 22, 2025
1572d39
commit message2
StefaniaOYoda Jan 22, 2025
83afe6a
Commit Message
StefaniaOYoda Jan 23, 2025
cc3536c
Update README.md
StefaniaOYoda Jan 23, 2025
0830c8c
Add files via upload
StefaniaOYoda Jan 23, 2025
debe999
1 - The hard-coded password 'bm5nhSkxCXZkKRy4' in the login function …
StefaniaOYoda Jan 23, 2025
71302b1
1 - The code already uses a try-with-resources statement for the Conn…
StefaniaOYoda Jan 23, 2025
ccdcb77
1 - The code was updated to replace the use of the deprecated MD5 has…
StefaniaOYoda Jan 23, 2025
2ebe508
Commit Message
StefaniaOYoda Feb 24, 2025
186b24c
1 - The original code snippet lacked proper closing of the ResultSet …
StefaniaOYoda Feb 24, 2025
9d3779e
1 - The code was updated to use SHA-256 instead of MD5. SHA-256 is a…
StefaniaOYoda Feb 24, 2025
f8dc50d
Commit Message
StefaniaOYoda Feb 24, 2025
6788a90
1 - The original code directly used user-provided numeric input (`log…
StefaniaOYoda Feb 24, 2025
3d0c54d
1 - Replaced the MD5 hash algorithm with SHA-256. MD5 is considered …
StefaniaOYoda Feb 24, 2025
250673e
1 - The original code lacked proper closing of the ResultSet and Stat…
StefaniaOYoda Feb 24, 2025
1902c9a
1 - The original code used a numeric user input ('login_count') direc…
StefaniaOYoda Feb 24, 2025
7140e62
1 - The MD5 algorithm was replaced with SHA-256, a more secure hashin…
StefaniaOYoda Feb 24, 2025
25bb42b
1 - The original code snippet lacked proper handling of the ResultSet…
StefaniaOYoda Feb 24, 2025
9b78b19
1 - The original code used a numeric user input (`login_count`) direc…
StefaniaOYoda Feb 24, 2025
6a80b0e
1 - The MD5 hashing algorithm was replaced with SHA-256, a more secur…
StefaniaOYoda Feb 24, 2025
a477721
First Load
StefaniaOYoda Feb 24, 2025
a0be445
1 - The provided code snippet does not contain any JWT token handling…
StefaniaOYoda Feb 24, 2025
1d89d10
1 - The hard-coded password 'bm5nhSkxCXZkKRy4' in the login function …
StefaniaOYoda Feb 24, 2025
4c7d95e
Add files via upload
StefaniaOYoda Feb 24, 2025
4d92aea
deepseek - 1 - The code was updated to avoid numeric user inputs in S…
StefaniaOYoda Feb 24, 2025
6f05802
deepseek - 1 - The code was updated to replace the deprecated MD5 has…
StefaniaOYoda Feb 24, 2025
b2f9a27
gemini - 1 - The hardcoded password "bm5nhSkxCXZkKRy4" in the `login`…
StefaniaOYoda Feb 24, 2025
ee8f11b
gemini - 1 - The issue was in MissingFunctionACUsers.java where strin…
StefaniaOYoda Feb 24, 2025
8ef7f10
gemini - 1 - The original code uses try-with-resources for the Connec…
StefaniaOYoda Feb 24, 2025
3115c0d
gemini - 1 - The original code was vulnerable to SQL injection becaus…
StefaniaOYoda Feb 24, 2025
9e29e78
gemini - 1 - The MD5 hashing algorithm was replaced with SHA-256 in t…
StefaniaOYoda Feb 24, 2025
6d2d508
Upload file via API
StefaniaOYoda Feb 24, 2025
5cf3f90
commit message2
StefaniaOYoda Feb 27, 2025
bd0f42c
Commit Message4create
StefaniaOYoda Feb 27, 2025
8b9272a
Commit Message4create
StefaniaOYoda Feb 27, 2025
389e287
Commit Message4create
StefaniaOYoda Feb 27, 2025
e8d3c12
Commit Message4create
StefaniaOYoda Feb 27, 2025
3ca3898
Delete test55.java
StefaniaOYoda Feb 27, 2025
e4c55e3
Commit Message4create
StefaniaOYoda Feb 27, 2025
056407f
Merge pull request #3 from StefaniaOYoda/main
StefaniaOYoda Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions DisplayUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.owasp.webgoat.lessons.missingac;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;
import lombok.Getter;

/**
* ************************************************************************************************
* 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 - 2014 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>
*/
@Getter
public class DisplayUser {
// intended to provide a display version of WebGoatUser for admins to view user attributes

private String username;
private boolean admin;
private String userHash;

public DisplayUser(User user, String passwordSalt) {
this.username = user.getUsername();
this.admin = user.isAdmin();

try {
this.userHash = genUserHash(user.getUsername(), user.getPassword(), passwordSalt);
} catch (Exception ex) {
this.userHash = "Error generating user hash";
}
}

protected String genUserHash(String username, String password, String passwordSalt)
throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA-256");
// salting is good, but static & too predictable ... short too for a salt
String salted = password + passwordSalt + username;
// md.update(salted.getBytes("UTF-8")); // Change this to "UTF-16" if needed
byte[] hash = md.digest(salted.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(hash);
}
}

89 changes: 89 additions & 0 deletions HashingAssignment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of WebGoat, an Open Web Application Security Project utility. For details, please see http://www.owasp.org/
*
* Copyright (c) 2002 - 2019 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.lessons.cryptography;

import static org.owasp.webgoat.container.assignments.AttackResultBuilder.failed;
import static org.owasp.webgoat.container.assignments.AttackResultBuilder.success;

import jakarta.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import javax.xml.bind.DatatypeConverter;
import org.owasp.webgoat.container.assignments.AssignmentEndpoint;
import org.owasp.webgoat.container.assignments.AssignmentHints;
import org.owasp.webgoat.container.assignments.AttackResult;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AssignmentHints({"crypto-hashing.hints.1", "crypto-hashing.hints.2"})
public class HashingAssignment implements AssignmentEndpoint {
public static final String[] SECRETS = {"secret", "admin", "password", "123456", "passw0rd"};

//Removed MD5 related code

@RequestMapping(path = "/crypto/hashing/sha256", produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String getSha256(HttpServletRequest request) throws NoSuchAlgorithmException {

String sha256 = (String) request.getSession().getAttribute("sha256");
if (sha256 == null) {
String secret = SECRETS[new Random().nextInt(SECRETS.length)];
sha256 = getHash(secret, "SHA-256");
request.getSession().setAttribute("sha256Hash", sha256);
request.getSession().setAttribute("sha256Secret", secret);
}
return sha256;
}

@PostMapping("/crypto/hashing")
@ResponseBody
public AttackResult completed(
HttpServletRequest request,
@RequestParam String answer_pwd1,
@RequestParam String answer_pwd2) {

String sha256Secret = (String) request.getSession().getAttribute("sha256Secret");

if (answer_pwd1 != null && answer_pwd2 != null) {
if (answer_pwd2.equals(sha256Secret)) {
return success(this).feedback("crypto-hashing.success").build();
} else if (answer_pwd2.equals(sha256Secret)) {
return failed(this).feedback("crypto-hashing.oneok").build();
}
}
return failed(this).feedback("crypto-hashing.empty").build();
}

public static String getHash(String secret, String algorithm) throws NoSuchAlgorithmException {
java.security.MessageDigest md = java.security.MessageDigest.getInstance(algorithm);
md.update(secret.getBytes());
byte[] digest = md.digest();
return DatatypeConverter.printHexBinary(digest).toUpperCase();
}
}

39 changes: 39 additions & 0 deletions JWTDecodeEndpointTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.owasp.webgoat.lessons.jwt;

import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.owasp.webgoat.container.plugins.LessonTest;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

public class JWTDecodeEndpointTest extends LessonTest {

@BeforeEach
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}

@Test
public void solveAssignment() throws Exception {
mockMvc
.perform(
MockMvcRequestBuilders.post("/JWT/decode").param("jwt-encode-user", "user").content(""))
.andExpect(status().isOk())
.andExpect(jsonPath("$.lessonCompleted", is(true)));
}

@Test
public void wrongUserShouldNotSolveAssignment() throws Exception {
mockMvc
.perform(
MockMvcRequestBuilders.post("/JWT/decode")
.param("jwt-encode-user", "wrong")
.content(""))
.andExpect(status().isOk())
.andExpect(jsonPath("$.lessonCompleted", is(false)));
}
}
Loading