-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog4j2.ql
50 lines (42 loc) · 1.55 KB
/
log4j2.ql
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
41
42
43
44
45
46
47
48
49
50
/**
* @name log4jshell
* @description log4j2->rce
* @kind path-problem
* @problem.severity error
* @precision high
* @id java/jndi-injection
* @tags security
*/
import java
import semmle.code.java.security.JndiInjectionQuery
import DataFlow::PathGraph
class LoggerSource extends DataFlow::Node {
LoggerSource() {
exists(Method method |
method.getParameter(0) = this.asParameter() and
method.getQualifiedName() = "AbstractLogger.error" and
method.getNumberOfParameters() = 1 and
method.getParameter(0).getType().getName() = "String"
)
}
}
class Log4j2Config extends TaintTracking::Configuration {
Log4j2Config() { this = "Log4j2Config" }
override predicate isSource(DataFlow::Node source) { source instanceof LoggerSource }
override predicate isSink(DataFlow::Node sink) { sink instanceof JndiInjectionSink }
override predicate isSanitizer(DataFlow::Node node) {
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
or node.getLocation().toString().regexpMatch(".*src/test/.*")
}
override predicate isAdditionalTaintStep(DataFlow::Node n1, DataFlow::Node n2) {
exists(MethodAccess call | call.getMethod().getName() = "newMessage" |
n1.asExpr() = call.getAnArgument() and
n2.asExpr() = call
)
or
any(JndiInjectionAdditionalTaintStep c).step(n1, n2)
}
}
from Log4j2Config config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
select sink, source, sink, "log4j2 rce"