mirror of
https://github.com/hohn/codeql-intro-csharp.git
synced 2025-12-16 10:43:05 +01:00
SQL Injection Code Sample Run
This commit is contained in:
committed by
=Michael Hohn
parent
75ed1f7b00
commit
a2466b0a2d
34
SqlInjection.ql
Normal file
34
SqlInjection.ql
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @name SQLI Vulnerability
|
||||
* @description Using untrusted strings in a sql query allows sql injection attacks.
|
||||
* @kind path-problem
|
||||
* @id workshop/sqlivulnerable
|
||||
* @problem.severity warning
|
||||
*/
|
||||
|
||||
import csharp
|
||||
|
||||
module MyFlowConfiguration implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) {
|
||||
exists(MethodCall call |
|
||||
call.getTarget().getDeclaringType().hasFullyQualifiedName("System", "Console") and
|
||||
call.getTarget().getName() = "ReadLine" and
|
||||
source.asExpr() = call
|
||||
)
|
||||
}
|
||||
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
exists(ObjectCreation oc, Expr queryArg |
|
||||
oc.getObjectType().getName() = "SqliteCommand" and
|
||||
oc.getArgument(0) = queryArg and
|
||||
sink.asExpr() = queryArg
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module Flow = DataFlow::Global<MyFlowConfiguration>;
|
||||
import Flow::PathGraph
|
||||
|
||||
from Flow::PathNode source, Flow::PathNode sink
|
||||
where Flow::flowPath(source, sink)
|
||||
select sink, source, sink, "Dataflow found"
|
||||
Reference in New Issue
Block a user