|
29 | 29 | import org.owasp.webgoat.container.assignments.AssignmentHints; |
30 | 30 | import org.owasp.webgoat.container.assignments.AttackResult; |
31 | 31 | import org.springframework.util.StringUtils; |
| 32 | +import org.springframework.web.bind.annotation.GetMapping; |
32 | 33 | import org.springframework.web.bind.annotation.PutMapping; |
33 | 34 | import org.springframework.web.bind.annotation.RequestParam; |
34 | 35 | import org.springframework.web.bind.annotation.ResponseBody; |
@@ -101,4 +102,48 @@ private AttackResult checkArguments(String username_reg, String email_reg, Strin |
101 | 102 | } |
102 | 103 | return null; |
103 | 104 | } |
| 105 | + |
| 106 | + /** |
| 107 | + * VULNERABLE ENDPOINT - Demonstrates SQL Injection vulnerability This endpoint is intentionally |
| 108 | + * vulnerable to demonstrate security scanning |
| 109 | + */ |
| 110 | + @GetMapping("/SqlInjectionAdvanced/searchUser") |
| 111 | + @ResponseBody |
| 112 | + public AttackResult searchUser(@RequestParam("searchTerm") String searchTerm) { |
| 113 | + try (Connection connection = dataSource.getConnection()) { |
| 114 | + // VULNERABILITY: SQL Injection - Direct string concatenation |
| 115 | + String vulnerableQuery = |
| 116 | + "SELECT userid, email FROM sql_challenge_users WHERE userid LIKE '%" |
| 117 | + + searchTerm |
| 118 | + + "%' OR email LIKE '%" |
| 119 | + + searchTerm |
| 120 | + + "%'"; |
| 121 | + |
| 122 | + Statement statement = connection.createStatement(); |
| 123 | + ResultSet resultSet = statement.executeQuery(vulnerableQuery); |
| 124 | + |
| 125 | + StringBuilder results = new StringBuilder(); |
| 126 | + int count = 0; |
| 127 | + while (resultSet.next()) { |
| 128 | + results |
| 129 | + .append("User: ") |
| 130 | + .append(resultSet.getString("userid")) |
| 131 | + .append(", Email: ") |
| 132 | + .append(resultSet.getString("email")) |
| 133 | + .append("\n"); |
| 134 | + count++; |
| 135 | + } |
| 136 | + |
| 137 | + if (count > 0) { |
| 138 | + return success(this) |
| 139 | + .feedback("Found " + count + " user(s):\n" + results.toString()) |
| 140 | + .build(); |
| 141 | + } else { |
| 142 | + return success(this).feedback("No users found matching: " + searchTerm).build(); |
| 143 | + } |
| 144 | + } catch (SQLException e) { |
| 145 | + log.error("SQL error in searchUser", e); |
| 146 | + return failed(this).output("Database error: " + e.getMessage()).build(); |
| 147 | + } |
| 148 | + } |
104 | 149 | } |
0 commit comments