Go Binary Reverse Engineering
Recovering function names and structure from compiled, often stripped Go binaries. The main anchor is the
.gopclntabtable. 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.gopclntaband 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 isheader[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-shellcodeimplements Windows shellcode runners over many execution primitives (CreateThread and CreateRemoteThread variants, CreateFiber, EarlyBird APC,EtwpCreateEtwThread,RtlCreateUserThread,UuidFromStringA, direct syscalls), both withgolang.org/x/sys/windowsand with self-resolved DLL procs.bluesentinelsec/OffensiveGoLangpackages 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-trimpathremove 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