Skip to content
RCE Write-up Advanced

How go get works#

The `go get` command could be tricked into using a malicious `.git` directory from a sub-package, leading to code execution when a user ran `go get -u` on a crafted package. An attacker could execute arbitrary commands on the victim's machine.

staaldraad.github.io

Published on staaldraad.github.io

Last year I stumbled across a vulnerability in Go’s go get command, which could lead to code execution when a malicious Go package was downloaded. I reported this to the Go team and it was subsequently assigned CVE-2018-16873.

Etienne Stalmans, on staaldraad.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, `go get` did not properly validate the order of package cloning and allowed a sub-package named `.git` to overwrite the parent's Git directory, which was then used by Git commands.

Impact

An attacker could execute arbitrary code on a victim's machine when the victim ran `go get -u` on a malicious package, but the exploit required the `--insecure` flag unless a parameter pollution trick was used.

What the attacker needed

Victim runs go get -u on malicious package; attacker controls a domain for meta tags; attacker can host Git repositories

The fix

The Go team fixed the vulnerability, and the issue only affected the older $GOPATH method, not Go modules.

How it was found

  1. Create a package with a sub-package named `.git` that contains a fake Git repository with a malicious `gitProxy` configuration.
  2. Use `go-import` meta tags to host the packages on a custom domain and control the clone order.
  3. Run `go get -u` on a trigger package that imports the malicious sub-package.
  4. The `go get` command clones the sub-package first, placing its content in the parent's `.git` directory.
  5. When updating the parent package, Git uses the fake `.git` directory and executes the `gitProxy` script.
  6. The script runs arbitrary commands, achieving code execution.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The `go get` tool downloads Go code from the internet. It could be fooled into running a hidden script because it trusted a folder named `.git` that came from a malicious package. This let an attacker run any command on the computer of someone who downloaded the package.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.