Skip to content

Commit 2ed8d5d

Browse files
authored
Merge pull request github#11288 from pwntester/new_sudo_like_argument
Golang: add `rsync` as a program capable of arbitrary shell command execution
2 parents 51f11f1 + 49eedde commit 2ed8d5d

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* `rsync` has been added to the list of commands which may evaluate its parameters as a shell command.

go/ql/lib/semmle/go/frameworks/SystemCommandExecutors.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ private class ShellOrSudoExecution extends SystemCommandExecution::Range, DataFl
2020

2121
override DataFlow::Node getCommandName() { result = this.getAnArgument() }
2222

23-
override predicate doubleDashIsSanitizing() { shellCommand.getStringValue().matches("%git") }
23+
override predicate doubleDashIsSanitizing() {
24+
shellCommand.getStringValue().matches("%" + ["git", "rsync"])
25+
}
2426
}
2527

2628
private class SystemCommandExecutors extends SystemCommandExecution::Range, DataFlow::CallNode {
@@ -126,7 +128,7 @@ private string getASudoCommand() {
126128
"fakeroot", "fakeroot-sysv", "su", "fakeroot-tcp", "fstab-decode", "jrunscript", "nohup",
127129
"parallel", "find", "pkexec", "sg", "sem", "runcon", "sudoedit", "runuser", "stdbuf",
128130
"system", "timeout", "xargs", "time", "awk", "gawk", "mawk", "nawk", "doas", "git", "access",
129-
"vsys", "userv", "sus", "super"
131+
"vsys", "userv", "sus", "super", "rsync"
130132
]
131133
}
132134

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"os/exec"
6+
)
7+
8+
func handler2(req *http.Request) {
9+
path := req.URL.Query()["path"][0]
10+
cmd := exec.Command("rsync", path, "/tmp")
11+
cmd.Run()
12+
}

go/ql/test/query-tests/Security/CWE-078/CommandInjection.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
edges
2+
| ArgumentInjection.go:9:10:9:16 | selection of URL : pointer type | ArgumentInjection.go:10:31:10:34 | path |
23
| CommandInjection.go:9:13:9:19 | selection of URL : pointer type | CommandInjection.go:10:22:10:28 | cmdName |
34
| GitSubcommands.go:10:13:10:19 | selection of URL : pointer type | GitSubcommands.go:12:31:12:37 | tainted |
45
| GitSubcommands.go:10:13:10:19 | selection of URL : pointer type | GitSubcommands.go:13:31:13:37 | tainted |
@@ -25,6 +26,8 @@ edges
2526
| SanitizingDoubleDash.go:105:15:105:37 | slice literal [array] : string | SanitizingDoubleDash.go:106:24:106:31 | arrayLit |
2627
| SanitizingDoubleDash.go:105:30:105:36 | tainted : string | SanitizingDoubleDash.go:105:15:105:37 | slice literal [array] : string |
2728
nodes
29+
| ArgumentInjection.go:9:10:9:16 | selection of URL : pointer type | semmle.label | selection of URL : pointer type |
30+
| ArgumentInjection.go:10:31:10:34 | path | semmle.label | path |
2831
| CommandInjection.go:9:13:9:19 | selection of URL : pointer type | semmle.label | selection of URL : pointer type |
2932
| CommandInjection.go:10:22:10:28 | cmdName | semmle.label | cmdName |
3033
| GitSubcommands.go:10:13:10:19 | selection of URL : pointer type | semmle.label | selection of URL : pointer type |
@@ -55,6 +58,7 @@ nodes
5558
| SanitizingDoubleDash.go:152:24:152:30 | tainted | semmle.label | tainted |
5659
subpaths
5760
#select
61+
| ArgumentInjection.go:10:31:10:34 | path | ArgumentInjection.go:9:10:9:16 | selection of URL : pointer type | ArgumentInjection.go:10:31:10:34 | path | This command depends on a $@. | ArgumentInjection.go:9:10:9:16 | selection of URL | user-provided value |
5862
| CommandInjection.go:10:22:10:28 | cmdName | CommandInjection.go:9:13:9:19 | selection of URL : pointer type | CommandInjection.go:10:22:10:28 | cmdName | This command depends on a $@. | CommandInjection.go:9:13:9:19 | selection of URL | user-provided value |
5963
| GitSubcommands.go:12:31:12:37 | tainted | GitSubcommands.go:10:13:10:19 | selection of URL : pointer type | GitSubcommands.go:12:31:12:37 | tainted | This command depends on a $@. | GitSubcommands.go:10:13:10:19 | selection of URL | user-provided value |
6064
| GitSubcommands.go:13:31:13:37 | tainted | GitSubcommands.go:10:13:10:19 | selection of URL : pointer type | GitSubcommands.go:13:31:13:37 | tainted | This command depends on a $@. | GitSubcommands.go:10:13:10:19 | selection of URL | user-provided value |

0 commit comments

Comments
 (0)