# Go Binary Reverse Engineering
> Recovering function names and structure from compiled, often stripped Go binaries. The main anchor is the `.gopclntab` table. Its counterpart is the obfuscation that malware and red-team tooling apply because Go cross-compiles easily and is hard to analyze.
## How it works
- Go binaries are large and statically linked, and they embed the whole runtime and stdlib. Even with `-ldflags="-s -w"` (which drops symbols and DWARF), the **`.gopclntab`** (PC-line table) remains. It lists every function's entry address and an offset to its name.
- Most static RE tooling for Go, such as strazzere's `golang_loader_assist`, finds `.gopclntab` and renames stripped functions to their real names. In practice, a stripped Go binary still hands back stdlib and package function names.
- Locating the table: scan for the header magic `FB FF FF FF 00 00`, then validate that the first function entry's address matches the address at its recorded offset. The layout is `header[8]`, `function_count`, then `{address, nameOffset}[function_count]`. Function length isn't stored and has to be inferred.
## Obfuscation and counter-techniques
| Obfuscation | Approach |
|---|---|
| `unixpickle/gobfuscate` | Source-level: rewrites package and identifier names before compiling |
| `sysopfb/GoMang` | Post-compile: enumerates `.gopclntab` and mangles the names |
| Zeroing `.gopclntab` | The runtime doesn't strictly need it for execution, so it can be wiped |
**De-obfuscation by signature matching:** build a catalog of stdlib function bytes per Go version and arch (`GOOS=<os> GOARCH=<arch> go install -v std`, then parse the object files with `goobj`), then match function bodies in the target binary. Null bytes in the object code mark relocation slots, so skip them during comparison. This identifies stdlib functions regardless of their names and can rebuild a `.gopclntab`. The PoC targeted `windows_386` and `windows_amd64`.
## Why attackers use Go
- Trivial cross-compilation (`GOOS=windows GOARCH=amd64 go build`) and single static binaries.
- Public offensive libraries exist. Ne0nd0g's `go-shellcode` implements Windows shellcode runners over many execution primitives (CreateThread and CreateRemoteThread variants, CreateFiber, EarlyBird APC, `EtwpCreateEtwThread`, `RtlCreateUserThread`, `UuidFromStringA`, direct syscalls), both with `golang.org/x/sys/windows` and with self-resolved DLL procs. `bluesentinelsec/OffensiveGoLang` packages adversary-emulation functions (download/upload, shellcode execution, persistence).
- For defenders and detection engineers, these repos are a catalog of the API sequences to hunt for in Go-compiled samples.
## Defensive takeaways for your own binaries
- Stripping (`-s -w`) and `-trimpath` remove symbols, DWARF and build paths but not `.gopclntab`. Assume function names, package paths and string literals in a shipped Go binary are recoverable. Never rely on obscurity for embedded secrets (see [[Hardcoded Secrets]]).
- Use PIE builds so that an attacker who has the binary still doesn't know runtime addresses (see [[Go Build and Deployment Hardening]]).
## Related
- [[Go Security]] (hub) · [[Go Build and Deployment Hardening]] · [[Go unsafe and cgo]]
- [[Malicious Packages]] · [[Frida]]
## Sources
- [[raw/medium.com/de-ofuscating-golang-functions-1368|De-Obfuscating GoLang Functions]]
- [[raw/github.com/github-ne0nd0g-go-shellcode-a-repository-of-windows-shellcode-runners-1433|Ne0nd0g/go-shellcode: Windows shellcode runners]]
- [[raw/github.com/bluesentinelsec-offensivegolang-a-collection-of-offensive-go-packages-1223|bluesentinelsec/OffensiveGoLang]]
- [[raw/snyk.io/go-security-cheatsheet-snyk-blog-1225|Go Security cheatsheet]]
- [[raw/rain-1.github.io/golang-aslr-rain-1-github-io-1098|Golang ASLR]]
- [[raw/arp242.net/statically-compiling-go-programs-1195|Statically compiling Go programs]]