gardenctl icon indicating copy to clipboard operation
gardenctl copied to clipboard

Sanitize user input when executing local commands

Open petersutter opened this issue 4 years ago • 6 comments

User input should be sanitized before local command execution, otherwise there is a possibility for command injection.

E.g. see this code https://github.com/gardener/gardenctl/blob/3ff05d6244a4cc19d618a55037dfd0ac1b9b31b8/pkg/cmd/ssh_alicloud.go#L202

a.MyPublicIP is determined by calling an external service https://github.com/gardener/gardenctl/blob/3ff05d6244a4cc19d618a55037dfd0ac1b9b31b8/pkg/cmd/miscellaneous.go#L327-L331

If this service returns a command instead of an IP, I assume that this command would get executed as per code above. There are a lot of other places where local commands are executed and most of them, if not all, do not sanitize the input.

And taking another look at the above example, why is the aliyun binary not called directly with the other parameters as arguments? https://github.com/gardener/gardenctl/blob/3ff05d6244a4cc19d618a55037dfd0ac1b9b31b8/pkg/cmd/ssh_alicloud.go#L202

See also https://github.com/gardener/gardenctl/issues/266 to further reduce the need to execute local commands and thereby reducing the attack vector.

petersutter avatar Aug 21 '20 14:08 petersutter

/assign

neo-liang-sap avatar Aug 21 '20 14:08 neo-liang-sap

Some comments on this in a related issue: https://github.com/gardener/gardenctl/pull/263/files#r473192089

dansible avatar Aug 24 '20 13:08 dansible

/unassign

unassign as:

  • not started working yet, @jfortin-sap if you have more insight and availability on this feel free take it ;)
  • pending other PRs , see comment above

neo-liang-sap avatar Aug 24 '20 13:08 neo-liang-sap

/assign

tedteng avatar Sep 14 '20 06:09 tedteng

/reopen

is every occurence really fixed now?

func ExecCmd(input []byte, cmd string, suppressedOutput bool, environment ...string) (err error) {
	var command *exec.Cmd
	parts := strings.Fields(cmd)
	head := parts[0]
	if len(parts) > 1 {
		parts = parts[1:]
	} else {
		parts = nil
	}
	command = exec.Command(head, parts...)
	...

the ExecCmd function should not be called with a cmd string and instead the caller should pass the name and arguments directly for exec.Command, otherwise an attacker could sneak in arguments

petersutter avatar Sep 21 '20 15:09 petersutter

/epic Please do not close this ticket which as epic ticket tracking all the sub-tasks.

tedteng avatar Sep 22 '20 07:09 tedteng