forked from CSPF-Founder/JavaVulnerableLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlInjectionCustom.ql
More file actions
40 lines (35 loc) · 1.18 KB
/
Copy pathSqlInjectionCustom.ql
File metadata and controls
40 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @name Custom: SQL injection via string concatenation
* @description Detects SQL queries built by concatenating HTTP request parameters
* directly into a query string — no prepared statement used.
* @kind problem
* @problem.severity error
* @id java/custom-sql-injection
* @tags security
* correctness
* custom
*/
import java
class GetParameterCall extends MethodAccess {
GetParameterCall() {
this.getMethod().getName() = "getParameter" and
this.getMethod().getDeclaringType().hasQualifiedName("javax.servlet.http", "HttpServletRequest")
}
}
class ExecuteQueryCall extends MethodAccess {
ExecuteQueryCall() {
this.getMethod().getName().matches("execute%") and
this.getMethod().getDeclaringType().getASupertype*().hasQualifiedName("java.sql", "Statement")
}
}
predicate containsGetParameter(Expr e) {
e instanceof GetParameterCall
or
containsGetParameter(e.(AddExpr).getLeftOperand())
or
containsGetParameter(e.(AddExpr).getRightOperand())
}
from ExecuteQueryCall exec
where containsGetParameter(exec.getArgument(0))
select exec,
"SQL query is built using HTTP request parameter directly — use PreparedStatement instead."