Security Testing Tutorials

HOME

Multiple Choice Questions for Security Testing on API Testing
Multiple Choice Questions for Security Testing on Web Application

Understanding SQL Injection: Types and Prevention

HOME

String username = request.getParameter("username");
String forename = request.getParameter("forename");

String sql = "SELECT * FROM users WHERE username = '" + username + "' AND forename = '" + forename + "'";

Connection conn = DriverManager.getConnection(url, username, forename);
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery(sql);
if (result.next()) {
    // User is authenticated
    String status = result.getString("success");
    System.out.println("Login to the application");
} else {
    // Authentication failed
  System.out.println("Unable to Login");
}

SELECT * FROM users WHERE username = 'admin'  AND forename = 'admin';

SELECT * FROM users WHERE username = 'admin'  -- AND forename = 'admin';

SELECT * FROM users WHERE username = 'admin'

String username = request.getParameter("username");
String forename = request.getParameter("forename");

String sql = "SELECT * FROM users WHERE username = ? AND forename = ?";

Connection conn = DriverManager.getConnection(url, username, forename);
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, username);
preparedStatement.setString(2, forename);
ResultSet result = preparedStatement.executeQuery();
if (result.next()) {
    // User is authenticated
       String status = result.getString("success");
       System.out.println("Login to the application");
} else {
    // Authentication failed
    System.out.println("Unable to Login");
}

SELECT ProductName, ProductDescription, ProductCost
FROM Products
WHERE ProductId = '100' UNION SELECT Username, Password FROM Users;