File tree Expand file tree Collapse file tree 5 files changed +43
-52
lines changed Expand file tree Collapse file tree 5 files changed +43
-52
lines changed Original file line number Diff line number Diff line change 1111
1212// Detect inputs from CNS add ipam result / CNS multitenancy ipam add result to command injection
1313import 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
2716private class Source extends DataFlow2:: Node {
2817 Source ( ) {
@@ -38,7 +27,7 @@ private class Source extends DataFlow2::Node {
3827}
3928
4029module 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}
Original file line number Diff line number Diff line change 1111
1212// Detect inputs from CNI ARGS to command injection
1313import 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
2716private class Source extends DataFlow2:: Node {
2817 Source ( ) {
@@ -44,7 +33,7 @@ private class Source extends DataFlow2::Node {
4433}
4534
4635module 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}
Original file line number Diff line number Diff line change 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)
1414import 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
2817private class Source extends DataFlow2:: Node {
2918 Source ( ) {
@@ -45,7 +34,7 @@ private class Source extends DataFlow2::Node {
4534}
4635
4736module 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}
Original file line number Diff line number Diff line change 1111
1212// Detect flow from the DECODE method (which decodes http requests) to a command execution
1313import 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
2716private class Source extends DataFlow2:: Node {
2817 Source ( ) {
@@ -34,7 +23,7 @@ private class Source extends DataFlow2::Node {
3423}
3524
3625module 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments