mirror of
https://github.com/hohn/codeql-workshop-sql-injection-java.git
synced 2025-12-16 10:43:05 +01:00
Add parts to build the codeql database in steps and provide log for comparison
This commit is contained in:
committed by
=Michael Hohn
parent
161a1d54f8
commit
5aadf85fb6
@@ -1,47 +0,0 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
break!!!
|
||||
|
||||
public class AddUser {
|
||||
public static Connection connect() {
|
||||
Connection conn = null;
|
||||
try {
|
||||
String url = "jdbc:sqlite:users.sqlite";
|
||||
conn = DriverManager.getConnection(url);
|
||||
System.out.println("Connected...");
|
||||
} catch (SQLException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
static String get_user_info() {
|
||||
System.out.println("Enter name:");
|
||||
return System.console().readLine();
|
||||
}
|
||||
|
||||
static void write_info(int id, String info) {
|
||||
try (Connection conn = connect()) {
|
||||
String query = String.format("INSERT INTO users VALUES (%d, '%s')", id, info);
|
||||
conn.createStatement().executeUpdate(query);
|
||||
System.err.printf("Sent: %s", query);
|
||||
} catch (SQLException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
static int get_new_id() {
|
||||
return (int)(Math.random()*100000);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String info;
|
||||
int id;
|
||||
|
||||
info = get_user_info();
|
||||
id = get_new_id();
|
||||
write_info(id, info);
|
||||
}
|
||||
}
|
||||
13
session/simple.ql
Normal file
13
session/simple.ql
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @name simple test
|
||||
* @description simple test
|
||||
* @kind problem
|
||||
* @id cpp/simple
|
||||
* @problem.severity warning
|
||||
*/
|
||||
|
||||
import java
|
||||
|
||||
from Call read
|
||||
where read.getCallee().getName() = "readLine"
|
||||
select read, "Found readline"
|
||||
Reference in New Issue
Block a user