No cON Name CTF Quals 2014 : cannaBINoid bin300 writeup

Hello, The task was about finding the key that prints "You got it!" on the screen. This task can be solved by statically analyzing the binary. It requests 128 chars input from the stdin.

.text:08048525                 mov     eax, ds:stdin
.text:0804852A                 push    eax
.text:0804852B                 push    80h
.text:08048530                 push    1
.text:08048532                 lea     eax, [ebp-98h]
.text:08048538                 push    eax
.text:08048539                 call    _fread
.text:0804853E                 add     esp, 10h
.text:08048541                 cmp     eax, 80h


Then it reads 128 chars from its own memory space using them mmap() function. More details here http://man7.org/linux/man-pages/man2/mmap.2.html

.text:08048578                 sub     esp, 8
.text:0804857B                 push    0
.text:0804857D                 push    dword ptr [ebp-14h]
.text:08048580                 push    2
.text:08048582                 push    1
.text:08048584                 push    80h
.text:08048589                 push    0
.text:0804858B                 call    _mmap



Then it compares it to the entred key: it starts comparing the first char with 0x7f. ELF header ? (0x7F 'E' 'L' 'F')
.text:080485DB                 cmp     dword ptr [ebp-10h], 7Fh
So, to solve the task I just typed the following command :

head -c128 cannabinoid > ./cannabinoid
You got it!

Finally to get the validation key just type:
head -c128 cannabinoid | sha1sum
The flag :
NcN_effaf80a641b28a8d8a750b99ef740593bb3dcbd
Cheers :-)