Skip to content
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

/*
* SPDX-FileCopyrightText: Copyright © 2016 WebGoat authors
* SPDX-FileCopyrightText: Copyright 2016 WebGoat authors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
package org.owasp.webgoat.lessons.sqlinjection.advanced;
Expand All @@ -8,6 +9,7 @@
import static org.owasp.webgoat.container.assignments.AttackResultBuilder.success;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
Expand Down Expand Up @@ -51,9 +53,9 @@ public AttackResult injectableQuery(String accountName) {
String query = "";
try (Connection connection = dataSource.getConnection()) {
boolean usedUnion = this.unionQueryChecker(accountName);
query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'";
query = "SELECT * FROM user_data WHERE last_name = ?";

return executeSqlInjection(connection, query, usedUnion);
return executeSqlInjection(connection, query, accountName, usedUnion);
} catch (Exception e) {
return failed(this)
.output(this.getClass().getName() + " : " + e.getMessage() + YOUR_QUERY_WAS + query)
Expand All @@ -65,11 +67,13 @@ private boolean unionQueryChecker(String accountName) {
return accountName.matches("(?i)(^[^-/*;)]*)(\\s*)UNION(.*$)");
}

private AttackResult executeSqlInjection(Connection connection, String query, boolean usedUnion) {
try (Statement statement =
connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
private AttackResult executeSqlInjection(Connection connection, String query, String accountName, boolean usedUnion) {
try (PreparedStatement statement =
connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {

statement.setString(1, accountName);

ResultSet results = statement.executeQuery(query);
ResultSet results = statement.executeQuery();

if (!((results != null) && results.first())) {
return failed(this)
Expand Down