“Shop” by picoCTF

The crackme is written in Go, so with my IDA Free without plugins and Lumina, it is quite difficult to understand the code generated by the Go compiler. Anyway, it’s a nice little game that simulates a store: you can buy or sell things, and the goal is to “buy” a flag when you’ve collected enough money. The only problem is that you don’t have enough items to sell to get it, so you need to find a way to cheat the game.

After going through the confusing code of calling functions from the standard library and trying to understand the logic, I eventually found the point where the actual purchase of things occurs. If you discard all unnecessary details, you will get something like this:

The problem with this code is that it does not validate the user-supplied howMuchToBuy value, so no one is stopping you from asking to buy a negative amount of things. Magically, the quantity of the selected item in the store will increase, including the money you have in your wallet.

Here’s a step-by-step solution:

Now, given that the flag is an array of numbers (each of which is an ASCII character), we need to convert it to a string, like this: