# CSAW 2013: GameMan

nc 128.238.66.223 1025 < hello_world.gbc


This challenge gives you a gameboy color rom that you have to send to the server, which in turn will respond with some text output of your rom, in this case “hello world!”… wait what? If you put the provided rom into an emulator, it will boot but it seems it won’t do anything at all.

Lets look at the hexdump:

00000150  90 68 0a 00 00 00 68 72  6c 64 21 68 6f 20 57 6f  |.h....hrld!ho Wo|


As you can see, there are parts of the “hello world!” string, in 4 byte chunks and reversed. But since when is the gameboy color a 32bit little endian architecture? Turns out, this is just plain x86 code at offset 0x156.

push    21646C72h
push    6F57206Fh
push    6C6C6548h
mov     eax, 4
mov     ebx, 1
mov     ecx, esp
mov     edx, 14h
int     80h
mov     eax, 1
int     80h


So let’s just modify this code and send the new file to the server (I inserted some code instead, that will call “/bin/cat *’.

Insert Cartridge...
global checksum is NOT OK


Ok, so it turns out, the gameboy color file format has a checksum over the whole file in it’s header, which is just the sum of all bytes mod 2**16 in big endian format. Let’s recalculate the checksum and try it again:

Insert Cartridge...