Skip to content

Commit c885c73

Browse files
Merge branch 'master' into sanprabhu/cilium-node-subnet-nc
2 parents 6d39383 + 055577d commit c885c73

File tree

5 files changed

+43
-52
lines changed

5 files changed

+43
-52
lines changed

codeql/addipamconfig-to-exec.ql renamed to codeql/acn-addipamconfig.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111

1212
// Detect inputs from CNS add ipam result / CNS multitenancy ipam add result to command injection
1313
import go
14-
15-
private class Sink extends DataFlow2::Node {
16-
Sink() {
17-
exists(DataFlow::CallNode c |
18-
c.getTarget().hasQualifiedName("os/exec", "CommandContext") and
19-
(c.getArgument(2) = this or c.getArgument(1) = this)
20-
or
21-
c.getTarget().hasQualifiedName("os/exec", "Command") and
22-
(c.getArgument(0) = this or c.getArgument(1) = this)
23-
)
24-
}
25-
}
14+
import lib.ACN
2615

2716
private class Source extends DataFlow2::Node {
2817
Source() {
@@ -38,7 +27,7 @@ private class Source extends DataFlow2::Node {
3827
}
3928

4029
module MyConfiguration implements DataFlow::ConfigSig {
41-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
30+
predicate isSink(DataFlow::Node sink) { sink instanceof ACN::CommandSink }
4231

4332
predicate isSource(DataFlow::Node source) { source instanceof Source }
4433
}

codeql/cni-args-to-exec.ql renamed to codeql/acn-cni-args.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111

1212
// Detect inputs from CNI ARGS to command injection
1313
import go
14-
15-
private class Sink extends DataFlow2::Node {
16-
Sink() {
17-
exists(DataFlow::CallNode c |
18-
c.getTarget().hasQualifiedName("os/exec", "CommandContext") and
19-
(c.getArgument(2) = this or c.getArgument(1) = this)
20-
or
21-
c.getTarget().hasQualifiedName("os/exec", "Command") and
22-
(c.getArgument(0) = this or c.getArgument(1) = this)
23-
)
24-
}
25-
}
14+
import lib.ACN
2615

2716
private class Source extends DataFlow2::Node {
2817
Source() {
@@ -44,7 +33,7 @@ private class Source extends DataFlow2::Node {
4433
}
4534

4635
module MyConfiguration implements DataFlow::ConfigSig {
47-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
36+
predicate isSink(DataFlow::Node sink) { sink instanceof ACN::CommandSink }
4837

4938
predicate isSource(DataFlow::Node source) { source instanceof Source }
5039
}

codeql/cns-invoker-to-exec.ql renamed to codeql/acn-cns-invoker.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@
1212
// Detect inputs from CNS Invoker to command injection
1313
// Does not detect flow to outside the enclosed method (which is why we analyze addIpamInvoker's results too)
1414
import go
15-
16-
private class Sink extends DataFlow2::Node {
17-
Sink() {
18-
exists(DataFlow::CallNode c |
19-
c.getTarget().hasQualifiedName("os/exec", "CommandContext") and
20-
(c.getArgument(2) = this or c.getArgument(1) = this)
21-
or
22-
c.getTarget().hasQualifiedName("os/exec", "Command") and
23-
(c.getArgument(0) = this or c.getArgument(1) = this)
24-
)
25-
}
26-
}
15+
import lib.ACN
2716

2817
private class Source extends DataFlow2::Node {
2918
Source() {
@@ -45,7 +34,7 @@ private class Source extends DataFlow2::Node {
4534
}
4635

4736
module MyConfiguration implements DataFlow::ConfigSig {
48-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
37+
predicate isSink(DataFlow::Node sink) { sink instanceof ACN::CommandSink }
4938

5039
predicate isSource(DataFlow::Node source) { source instanceof Source }
5140
}

codeql/decode-to-exec.ql renamed to codeql/acn-decode.ql

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111

1212
// Detect flow from the DECODE method (which decodes http requests) to a command execution
1313
import go
14-
15-
private class Sink extends DataFlow2::Node {
16-
Sink() {
17-
exists(DataFlow::CallNode c |
18-
c.getTarget().hasQualifiedName("os/exec", "CommandContext") and
19-
(c.getArgument(2) = this or c.getArgument(1) = this)
20-
or
21-
c.getTarget().hasQualifiedName("os/exec", "Command") and
22-
(c.getArgument(0) = this or c.getArgument(1) = this)
23-
)
24-
}
25-
}
14+
import lib.ACN
2615

2716
private class Source extends DataFlow2::Node {
2817
Source() {
@@ -34,7 +23,7 @@ private class Source extends DataFlow2::Node {
3423
}
3524

3625
module MyConfiguration implements DataFlow::ConfigSig {
37-
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
26+
predicate isSink(DataFlow::Node sink) { sink instanceof ACN::CommandSink }
3827

3928
predicate isSource(DataFlow::Node source) { source instanceof Source }
4029
}

codeql/lib/ACN.qll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import go
2+
3+
module ACN {
4+
class CommandSink extends DataFlow2::Node {
5+
CommandSink() {
6+
exists(DataFlow::CallNode c, Method m |
7+
(
8+
// Detect dangerous usage of command wrappers with the command in the 0th arg position
9+
(
10+
m.hasQualifiedName("github.com/Azure/azure-container-networking/platform", "execClient",
11+
"ExecuteRawCommand") or
12+
m.hasQualifiedName("github.com/Azure/azure-container-networking/platform", "execClient",
13+
"ExecutePowershellCommand")
14+
) and
15+
c.getArgument(0) = this
16+
or
17+
// Detect dangerous usage of command wrappers with the command in the 1st arg position
18+
m.hasQualifiedName("github.com/Azure/azure-container-networking/platform", "execClient",
19+
"ExecutePowershellCommandWithContext") and
20+
c.getArgument(1) = this
21+
) and
22+
c = m.getACall()
23+
or
24+
// Detect dangerous calls directly to os exec
25+
(
26+
c.getTarget().hasQualifiedName("os/exec", "CommandContext") and
27+
(c.getArgument(2) = this or c.getArgument(1) = this)
28+
or
29+
c.getTarget().hasQualifiedName("os/exec", "Command") and
30+
(c.getArgument(0) = this or c.getArgument(1) = this)
31+
)
32+
)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)