Runtime Environment 1
Basic Go reversing
Author: rootkid
GO and try to solve this basic challenge.
FAQ: If you found the input leading to the challenge.txt you are on the right trackAttack of the Gopher
From the challenge description, and the name of the downloadable tarball gogogo.tar.gz, it's pretty apparent that this is a Go binary. In my previous experience with Go-based challenges, oftentimes the greatest difficulty is in finding the main function. Luckily, running the file command assuages my worries.
❯ file binary
binary: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=OHBJFJh5S4MEkda8Q683/cMydJq6y9QbVjBCjK1KP/8R1f9ddSl9EfpM8KP2Dy/3G9-Ju3BW7WUsgoGNyvl, not strippedSo, it's not stripped. What does it do, then?
Running the binary just gives a prompt. Entering a string and hitting enter spits out an output that looks suspiciously like base64. We can test this hypothesis by checking the output of the binary if we vary the input string slightly:
❯ ./binary
aaaabaaacaaadaaa
CGTxCGmxCGT2CGTx+1TxCV--
❯ ./binary
aaaabaaacaaadaa
CGTxCGmxCGT2CGTx+1TxWe were also provided with a challenge.txt, containing the following textual data: GvVf+fHWz1tlOkHXUk3kz3bqh4UcFFwgDJmUDWxdDTTGzklgIJ+fXfHUh739+BUEbrmMzGoQOyDIFIz4GvTw+j--. We can assume that the correct input to the binary would produce the corresponding output to the contents of challenge.txt.
Going Deeper
With the help of the included debug symbols, finding the main function is trivial. Here's a snippet of the decompiled main function, retaining the important lines.
The main function doesn't do much beyond reading in the user's output, converting it to bytes and calling the main.Encode subfunction. The output of main.Encode is then printed to console. This is in line with the expected behaviour given our prior black-box testing.
Here's a snippet of main.Encode with Go-inserted error-handling snipped for easier reading:
In an attempt to understand this algorithm better, I converted it to Python, a language I'm more comfortable with. I've annotated portions of the translated code that I found interesting and indicative that my base64 hypothesis was right.
Curiously enough, while I was doing translation, GitHub Copilot was doing an excellent job of filling in the next lines of code I would write. Along with the behaviour I observed while translating the code, this further confirmed my base64 hypothesis. A quick Google search put any remaining doubt to rest.

Reversing the base64 encryption is easy with the help of Python's base64 module. This can be accomplished in a few steps:
Extract the custom base64 alphabet from our binary
Make a string translation mapping the encrypted base64 string to the default base64 alphabet.
Profit?
Running the function once spits out yet another base64-encoded string. Wrapping repeated calls to our custom base64 decode in a while loop yields the flag, eventually.
Last updated
Was this helpful?