
Decompiling Go binaries can be a complex task, but it's essential for understanding the inner workings of Go programs.
Go binaries are compiled into a format called ELF (Executable and Linkable Format), which is a standard format for Linux executables.
The Go compiler, also known as the Go toolchain, uses a combination of static and dynamic linking to create the final executable.
This process involves the use of a library called libgo, which is responsible for providing the runtime environment for the Go program.
On a similar theme: Golang Go
Reversing Go Binaries
Reversing Go Binaries can be a challenge, but there are ways to make it more manageable.
Go binaries still contain function metadata even after an attacker strips symbols. This metadata is stored in .gopclntab and .gofuncname sections.
You can use the go tool nm to view this metadata and potentially identify function names. Ghidra’s auto-recovery routines can also be used to rename functions.
Restoring the original identifiers, such as http.NewRequest and crypto/aes.newCipher, can help the high-level behavior of the binary snap into focus.
This process can be time-consuming, but it's a crucial step in understanding the functionality of the binary.
Obfuscation Techniques
Malware often uses XOR encoded strings, but Blackrota takes it a step further by generating a random XOR key per string and wrapping it in a function that XORs the string at runtime.
String obfuscation is a common technique used to conceal code. In the case of Blackrota, it generates a random XOR key per string, making it harder to reverse-engineer.
Gobfuscate is a tool that runs before compilation to produce an obfuscated version of your code, which is then compiled by the Go compiler. This process makes it difficult to manually XOR each string in a binary.
Binary Ninja's intermediate language (IL) is a powerful tool for operating on a representation of a function, regardless of the system architecture. This makes it an ideal choice for reversing-engineering code.
To extract strings from a binary, you need a way to identify the functions you want to extract from, which is known as candidate identification.
Analyzing Go Binaries
Parsing Go binaries can be a challenge, but having the right tools and knowledge can make it more manageable. Golang executables embed a structure called "pc line table", also known as pclntab, which can be used to improve control flow in a disassembler.
The pclntab structure contains a function symbol table that stores entry points and names of routines defined in the binary. This makes it a reliable way to disassemble functions and rename them.
Some popular disassemblers and decompilers for Go binaries include Ghidra with the GoDecompiler extension, IDA Pro + BinExport + GolangLoader, Binary Ninja with the Golang Analysis plugin, and Radare2/Cutter.
Parsing PC Line Table
Parsing the PC Line Table is a crucial step in analyzing Go binaries. It's a structure that's been embedded in Golang executables since version 1.2.
The PC Line Table, also known as pclntab, is an inherited concept from Plan9, where it was used to associate program counter values with line numbers in source code. This structure has evolved to store function symbol tables, including entry points and routine names.
The Golang runtime relies on pclntab for stack unwinding, call stack printing, and garbage collection. This makes it a reliable way to improve control flow in our disassembler.
To locate the pclntab structure, our script searches memory for the magic constant 0xFFFFFFFB. This constant is the starting point for pclntab, and we run some checks on the possible fields.
Parsing the pclntab structure allows us to disassemble all functions and rename them using its function symbol table. This is usually easier to do with Golang ELF files, as important runtime structures are stored in distinct sections.
A fresh viewpoint: Golang Stack
Tools for Analyzing Go Binaries
If you're looking to analyze Go binaries, you'll want to check out some of the top tools in the industry. Ghidra with the GoDecompiler extension is a great option, offering a free, scriptable, and increasingly accurate way to reconstruct Go types and methods.
For a more commercial powerhouse, consider IDA Pro + BinExport + GolangLoader. This combination provides a strong automation hook and solid type inference, making it a great choice for those who need a bit more oomph.
Another lightweight option worth exploring is Binary Ninja with the Golang Analysis plugin. This tool offers a solid interface, strong automation hooks, and excellent type inference.
If you prefer a more open-source alternative, Radare2/Cutter is definitely worth checking out. This terminal-driven workflow is favored by many researchers who love the flexibility and deep scripting capabilities it provides.
Here are some of the top tools for analyzing Go binaries:
- Ghidra with the GoDecompiler extension: Free, scriptable, and increasingly accurate at reconstructing Go types and methods.
- IDA Pro + BinExport + GolangLoader: A commercial powerhouse with community plugins that recover Go’s complex symbol tables.
- Binary Ninja with the Golang Analysis plugin: Lightweight interface, strong automation hooks, and solid type inference.
- Radare2/Cutter: Open-source alternative favored by researchers who love terminal-driven workflows and deep scripting.
Decrypting Embedded Resources
Go's standard library makes bundling data trivial, allowing attackers to embed configuration blobs, RSA keys, and second-stage payloads directly into the binary with the //go:embed directive.
This embedded data typically lands in the .rodata section as a byte slice, which can be a red flag for suspicious activity.
Locate large arrays in the binary, as they can indicate embedded resources.
References to encoding/base64 or crypto/cipher packages can also be a sign of embedded data.
Brute-force common XOR or AES keys to uncover potential encryption.
Recovered C2 addresses or JWT tokens can break the case wide open by revealing critical information.
Current Status
Analyzing Go binaries can be a bit tricky, especially when it comes to disassembling them. JEB disassembler can only partially disassemble Go executables compiled for Windows x64 PE files, leaving some code areas unexplored.
This is because JEB disassembler uses a CONSERVATIVE strategy, which only follows safe control flow relationships. As a result, it misses some code areas, especially when Go runtime calls native routines indirectly.
Opening a Linux executable in JEB brings a more positive situation, as it uses an AGGRESSIVE strategy for disassembling ELF files. This results in the whole code area being disassembled, including the main routine.
Data are not mixed with code in Go executables, at least not yet. In PE and ELF files, data are explicitly stored in separate sections than code.
Static Allocation
Static allocation can be used for global variables in Go binaries, where the entire structure is stored in the executable.
The code referencing these strings employs many different instructions, making pattern matching not suitable.
Static allocation can be identified by scanning data sections for possible StringHeader structures, which are characterized by a Data field pointing to a printable string of size Len.
This approach allows for the recovery of strings that might have been missed by previous heuristics.
The script also employs additional final heuristics to scan memory for printable strings located between two already-defined strings.
This allows for a more thorough recovery of strings, including those that might not have been caught by pattern matching or other methods.
Anti-Analysis Tricks
Anti-Analysis Tricks can be quite sneaky, making it difficult to decompile Go code. Attackers compile with -ldflags="-s -w" to strip debug info or embed conditional logic that activates only in non-debug environments. This makes it hard to analyze the code.
To uncover the real control flow, break on reflect.* functions in your debugger and single-step through the code. This will help you catch any indirect function calls via reflect.Value.Call.
Garbage-collector timing can also be used to delay execution or corrupt memory snapshots. Dump heap states at multiple intervals to catch volatile artifacts and stay one step ahead of the attackers.
Here are some common Anti-Analysis Tricks to watch out for:
- Custom build tags
- Reflection abuse
- Garbage-collector timing
Featured Images: pexels.com


