5
5
6
6
import go
7
7
8
+ private class DefaultSystemCommandExecution extends SystemCommandExecution:: Range ,
9
+ DataFlow:: CallNode
10
+ {
11
+ DataFlow:: ArgumentNode commandName ;
12
+
13
+ DefaultSystemCommandExecution ( ) {
14
+ sinkNode ( commandName , "command-injection" ) and
15
+ this = commandName .getCall ( )
16
+ }
17
+
18
+ override DataFlow:: Node getCommandName ( ) {
19
+ not commandName instanceof DataFlow:: ImplicitVarargsSlice and
20
+ result = commandName
21
+ or
22
+ commandName instanceof DataFlow:: ImplicitVarargsSlice and
23
+ result = this .getAnImplicitVarargsArgument ( )
24
+ }
25
+ }
26
+
8
27
/**
9
28
* An indirect system-command execution via an argument argument passed to a command interpreter
10
29
* such as a shell, `sudo`, or a programming-language interpreter.
@@ -26,85 +45,19 @@ private class ShellOrSudoExecution extends SystemCommandExecution::Range, DataFl
26
45
}
27
46
}
28
47
29
- private class SystemCommandExecutors extends SystemCommandExecution:: Range , DataFlow:: CallNode {
30
- int cmdArg ;
31
-
32
- SystemCommandExecutors ( ) {
33
- exists ( string pkg , string name | this .getTarget ( ) .hasQualifiedName ( pkg , name ) |
34
- pkg = "os" and name = "StartProcess" and cmdArg = 0
35
- or
36
- // assume that if a `Cmd` is instantiated it will be run
37
- pkg = "os/exec" and name = "Command" and cmdArg = 0
38
- or
39
- pkg = "os/exec" and name = "CommandContext" and cmdArg = 1
40
- or
41
- // NOTE: syscall.ForkExec exists only on unix.
42
- // NOTE: syscall.CreateProcess and syscall.CreateProcessAsUser exist only on windows.
43
- pkg = "syscall" and
44
- name = [ "Exec" , "ForkExec" , "StartProcess" , "CreateProcess" ] and
45
- cmdArg = 0
46
- or
47
- pkg = "syscall" and
48
- name = "CreateProcessAsUser" and
49
- cmdArg = 1
50
- )
51
- }
52
-
53
- override DataFlow:: Node getCommandName ( ) { result = this .getSyntacticArgument ( cmdArg ) }
54
- }
55
-
56
- /**
57
- * A call to the `Command` function, or `Call` or `Command` methods on a `Session` object
58
- * from the [go-sh](https://github.com/codeskyblue/go-sh) package, viewed as a
59
- * system-command execution.
60
- */
61
- private class GoShCommandExecution extends SystemCommandExecution:: Range , DataFlow:: CallNode {
62
- GoShCommandExecution ( ) {
63
- exists ( string packagePath | packagePath = package ( "github.com/codeskyblue/go-sh" , "" ) |
64
- // Catch method calls on the `Session` object:
65
- exists ( Method method |
66
- method .hasQualifiedName ( packagePath , "Session" , "Call" )
67
- or
68
- method .hasQualifiedName ( packagePath , "Session" , "Command" )
69
- or
70
- method .hasQualifiedName ( packagePath , "Session" , "Exec" )
71
- |
72
- this = method .getACall ( )
73
- )
74
- or
75
- // Catch calls to the `Command` function:
76
- this .getTarget ( ) .hasQualifiedName ( packagePath , "Command" )
77
- )
78
- }
79
-
80
- override DataFlow:: Node getCommandName ( ) { result = this .getSyntacticArgument ( 0 ) }
81
- }
82
-
83
48
/**
49
+ * DEPRECATED
50
+ *
84
51
* Provides classes for working with the
85
52
* [golang.org/x/crypto/ssh](https://pkg.go.dev/golang.org/x/crypto/ssh) package.
86
53
*/
87
- module CryptoSsh {
88
- /** Gets the package path `golang.org/x/crypto/ssh`. */
89
- string packagePath ( ) { result = package ( "golang.org/x/crypto" , "ssh" ) }
90
-
54
+ deprecated module CryptoSsh {
91
55
/**
92
- * A call to a method on a `Session` object from the [ssh](golang.org/x/crypto/ssh)
93
- * package, viewed as a system-command execution.
56
+ * DEPRECATED: Use `package("golang.org/x/crypto", "ssh")` instead.
57
+ *
58
+ * Gets the package path `golang.org/x/crypto/ssh`.
94
59
*/
95
- private class SshCommandExecution extends SystemCommandExecution:: Range , DataFlow:: CallNode {
96
- SshCommandExecution ( ) {
97
- // Catch method calls on the `Session` object:
98
- exists ( Method method , string methodName |
99
- methodName = [ "CombinedOutput" , "Output" , "Run" , "Start" ]
100
- |
101
- method .hasQualifiedName ( packagePath ( ) , "Session" , methodName ) and
102
- this = method .getACall ( )
103
- )
104
- }
105
-
106
- override DataFlow:: Node getCommandName ( ) { result = this .getSyntacticArgument ( 0 ) }
107
- }
60
+ deprecated string packagePath ( ) { result = package ( "golang.org/x/crypto" , "ssh" ) }
108
61
}
109
62
110
63
/**
0 commit comments