mirror of
https://github.com/hohn/codeql-dataflow-sql-injection.git
synced 2025-12-16 18:23:05 +01:00
sql injection: taintstep across macro under snprintf as predicate
This commit is contained in:
committed by
=Michael Hohn
parent
4060f31100
commit
5bce3ae696
@@ -23,7 +23,22 @@ class SqliFlowConfig extends TaintTracking::Configuration {
|
|||||||
|
|
||||||
override predicate isSanitizer(DataFlow::Node sanitizer) { none() }
|
override predicate isSanitizer(DataFlow::Node sanitizer) { none() }
|
||||||
|
|
||||||
override predicate isAdditionalTaintStep(DataFlow::Node n1, DataFlow::Node n2) { none() }
|
override predicate isAdditionalTaintStep(DataFlow::Node into, DataFlow::Node out) {
|
||||||
|
// Extra taint step
|
||||||
|
// snprintf(query, bufsize, "INSERT INTO users VALUES (%d, '%s')", id, info);
|
||||||
|
// But snprintf is a macro on mac os. The actual function's name is
|
||||||
|
// #undef snprintf
|
||||||
|
// #define snprintf(str, len, ...) \
|
||||||
|
// __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
|
||||||
|
// #endif
|
||||||
|
exists(FunctionCall printf |
|
||||||
|
printf.getTarget().getName().matches("%snprintf%") and
|
||||||
|
printf.getArgument(0) = out.asExpr() and
|
||||||
|
// very specific: shifted index for macro. We can generalize this to consider
|
||||||
|
// all trailing arguments as sources.
|
||||||
|
printf.getArgument(6) = into.asExpr()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override predicate isSink(DataFlow::Node sink) {
|
override predicate isSink(DataFlow::Node sink) {
|
||||||
// rc = sqlite3_exec(db, query, NULL, 0, &zErrMsg);
|
// rc = sqlite3_exec(db, query, NULL, 0, &zErrMsg);
|
||||||
@@ -34,22 +49,6 @@ class SqliFlowConfig extends TaintTracking::Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// from SqliFlowConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink
|
from SqliFlowConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink
|
||||||
// where conf.hasFlowPath(source, sink)
|
where conf.hasFlowPath(source, sink)
|
||||||
// select sink, source, sink, "Possible SQL injection"
|
select sink, source, sink, "Possible SQL injection"
|
||||||
|
|
||||||
// Extra taint step
|
|
||||||
// snprintf(query, bufsize, "INSERT INTO users VALUES (%d, '%s')", id, info);
|
|
||||||
// But snprintf is a macro on mac os. The actual function's name is
|
|
||||||
// #undef snprintf
|
|
||||||
// #define snprintf(str, len, ...) \
|
|
||||||
// __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
|
|
||||||
// #endif
|
|
||||||
from FunctionCall printf, DataFlow::Node into, DataFlow::Node out
|
|
||||||
where
|
|
||||||
printf.getTarget().getName().matches("%snprintf%") and
|
|
||||||
printf.getArgument(0) = out.asExpr() and
|
|
||||||
// very specific: shifted index for macro. We can generalize this to consider
|
|
||||||
// all trailing arguments as sources.
|
|
||||||
printf.getArgument(6) = into.asExpr()
|
|
||||||
select printf, into, out
|
|
||||||
|
|||||||
Reference in New Issue
Block a user