Skip to content

Commit 94cdfc8

Browse files
committed
feat(java): Update CommandInjectionRuntimeExec queries
1 parent 641065c commit 94cdfc8

File tree

4 files changed

+37
-68
lines changed

4 files changed

+37
-68
lines changed

java/src/security/CWE-078/CommandInjectionRuntimeExec.ql

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,3 @@ where
3232
select sink, source, sink,
3333
"Call to dangerous java.lang.Runtime.exec() with command '$@' with arg from untrusted input '$@'",
3434
source, source.toString(), source.getNode(), source.toString()
35-
//
36-
//
37-
// from
38-
// DataFlow::PathNode source, DataFlow::PathNode sink, ExecTaintConfiguration2 conf,
39-
// MethodAccess call, DataFlow::Node sourceCmd, DataFlow::Node sinkCmd,
40-
// ExecTaintConfiguration confCmd
41-
// where
42-
// call.getMethod() instanceof RuntimeExecMethod and
43-
// // this is a command-accepting call to exec, e.g. rt.exec(new String[]{"/bin/sh", ...})
44-
// (
45-
// confCmd.hasFlow(sourceCmd, sinkCmd) and
46-
// sinkCmd.asExpr() = call.getArgument(0)
47-
// ) and
48-
// // it is tainted by untrusted user input
49-
// (
50-
// conf.hasFlow(source.getNode(), sink.getNode()) and
51-
// sink.getNode().asExpr() = call.getArgument(0)
52-
// )
53-
// select sink, source, sink,
54-
// "Call to dangerous java.lang.Runtime.exec() with command '$@' with arg from untrusted input '$@'",
55-
// sourceCmd, sourceCmd.toString(), source.getNode(), source.toString()

java/src/security/CWE-078/CommandInjectionRuntimeExecLocal.ql

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,25 @@
1111
* external/cwe/cwe-078
1212
*/
1313

14-
import DataFlow::PathGraph
1514
import ghsl.CommandInjectionRuntimeExec
1615

1716
class LocalSource extends Source {
1817
LocalSource() { this instanceof LocalUserInput }
1918
}
2019

21-
from
22-
DataFlow::PathNode source, DataFlow::PathNode sink, ExecTaintConfiguration2 conf, MethodCall call,
23-
DataFlow::Node sourceCmd, DataFlow::Node sinkCmd, ExecTaintConfiguration confCmd
20+
module Flow = TaintTracking::Global<RuntimeExec::RuntimeExecConfiguration>;
21+
22+
module Flow2 = TaintTracking::Global<ExecTaint::ExecTaintConfiguration>;
23+
24+
module FlowGraph =
25+
DataFlow::MergePathGraph<Flow::PathNode, Flow2::PathNode, Flow::PathGraph, Flow2::PathGraph>;
26+
27+
import FlowGraph::PathGraph
28+
29+
from FlowGraph::PathNode source, FlowGraph::PathNode sink
2430
where
25-
call.getMethod() instanceof RuntimeExecMethod and
26-
// this is a command-accepting call to exec, e.g. rt.exec(new String[]{"/bin/sh", ...})
27-
(
28-
confCmd.hasFlow(sourceCmd, sinkCmd) and
29-
sinkCmd.asExpr() = call.getArgument(0)
30-
) and
31-
// it is tainted by untrusted user input
32-
(
33-
conf.hasFlow(source.getNode(), sink.getNode()) and
34-
sink.getNode().asExpr() = call.getArgument(0)
35-
)
31+
Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or
32+
Flow2::flowPath(source.asPathNode2(), sink.asPathNode2())
3633
select sink, source, sink,
3734
"Call to dangerous java.lang.Runtime.exec() with command '$@' with arg from untrusted input '$@'",
38-
sourceCmd, sourceCmd.toString(), source.getNode(), source.toString()
35+
source, source.toString(), source.getNode(), source.toString()

java/src/security/CWE-078/CommandInjectionRuntimeExecTest.ql

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@ class DataSource extends Source {
1818
DataSource() { this instanceof RemoteFlowSource or this instanceof LocalUserInput }
1919
}
2020

21-
from
22-
DataFlow::Node source, DataFlow::Node sink, ExecTaintConfiguration2 conf, MethodCall call,
23-
int index, DataFlow::Node sourceCmd, DataFlow::Node sinkCmd, ExecTaintConfiguration confCmd
21+
module Flow = TaintTracking::Global<RuntimeExec::RuntimeExecConfiguration>;
22+
23+
module Flow2 = TaintTracking::Global<ExecTaint::ExecTaintConfiguration>;
24+
25+
module FlowGraph =
26+
DataFlow::MergePathGraph<Flow::PathNode, Flow2::PathNode, Flow::PathGraph, Flow2::PathGraph>;
27+
28+
from FlowGraph::PathNode source, FlowGraph::PathNode sink
2429
where
25-
call.getMethod() instanceof RuntimeExecMethod and
26-
// this is a command-accepting call to exec, e.g. exec("/bin/sh", ...)
27-
(
28-
confCmd.hasFlow(sourceCmd, sinkCmd) and
29-
sinkCmd.asExpr() = call.getArgument(0)
30-
) and
31-
// it is tainted by untrusted user input
32-
(
33-
conf.hasFlow(source, sink) and
34-
sink.asExpr() = call.getArgument(index)
35-
)
30+
Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or
31+
Flow2::flowPath(source.asPathNode2(), sink.asPathNode2())
3632
select sink,
3733
"Call to dangerous java.lang.Runtime.exec() with command '$@' with arg from untrusted input '$@'",
38-
sourceCmd, sourceCmd.toString(), source, source.toString()
34+
source, source.toString(), source, source.toString()

java/src/security/CWE-078/CommandInjectionRuntimeExecTestPath.ql

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,25 @@
1212
* external/cwe/cwe-078
1313
*/
1414

15-
import DataFlow::PathGraph
1615
import ghsl.CommandInjectionRuntimeExec
1716

1817
class DataSource extends Source {
1918
DataSource() { this instanceof RemoteFlowSource or this instanceof LocalUserInput }
2019
}
2120

22-
from
23-
DataFlow::PathNode source, DataFlow::PathNode sink, ExecTaintConfiguration2 conf, MethodCall call,
24-
DataFlow::Node sourceCmd, DataFlow::Node sinkCmd, ExecTaintConfiguration confCmd
21+
module Flow = TaintTracking::Global<RuntimeExec::RuntimeExecConfiguration>;
22+
23+
module Flow2 = TaintTracking::Global<ExecTaint::ExecTaintConfiguration>;
24+
25+
module FlowGraph =
26+
DataFlow::MergePathGraph<Flow::PathNode, Flow2::PathNode, Flow::PathGraph, Flow2::PathGraph>;
27+
28+
import FlowGraph::PathGraph
29+
30+
from FlowGraph::PathNode source, FlowGraph::PathNode sink
2531
where
26-
call.getMethod() instanceof RuntimeExecMethod and
27-
// this is a command-accepting call to exec, e.g. rt.exec(new String[]{"/bin/sh", ...})
28-
(
29-
confCmd.hasFlow(sourceCmd, sinkCmd) and
30-
sinkCmd.asExpr() = call.getArgument(0)
31-
) and
32-
// it is tainted by untrusted user input
33-
(
34-
conf.hasFlow(source.getNode(), sink.getNode()) and
35-
sink.getNode().asExpr() = call.getArgument(0)
36-
)
32+
Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or
33+
Flow2::flowPath(source.asPathNode2(), sink.asPathNode2())
3734
select sink, source, sink,
3835
"Call to dangerous java.lang.Runtime.exec() with command '$@' with arg from untrusted input '$@'",
39-
sourceCmd, sourceCmd.toString(), source.getNode(), source.toString()
36+
source, source.toString(), source.getNode(), source.toString()

0 commit comments

Comments
 (0)