black electronics

Golang

Common Go commands for building and cross-compiling pentesting tools.

A lot of modern offensive tooling is written in Go, so it’s worth knowing the handful of go commands needed to build and tweak it yourself.

Terminal window
go run main.go # Run a Go file directly without producing a binary
Terminal window
go build main.go # Compile a Go file into a binary
Terminal window
go build -ldflags "-w -s" main.go # Build a smaller binary by stripping debug symbols and the symbol table
Terminal window
# Cross-compile on Windows to produce a Linux binary
$env:GOOS = "linux"
$env:GOARCH = "amd64"
go build -ldflags "-w -s" main.go
Terminal window
go doc fmt.Println # Show documentation for a package, function or method
Terminal window
go fmt main.go # Reformat a Go file to the standard style
Useful LinksPentest PayloadsCheat Sheets