[X] CairoSecurityCamp CTF 2014 WriteUp (ELF1)
[X] Author : fr0g
[X] Main : fr0g.security@gmail.com
[X] Greet'z : SaxX, NotFound, All Hexpresso team && HWC members
MD5SUM : 1299439f81e7d3bd5d32274dc2c44233
On passe le binaire à la commande file, on voit qu'il n'est pas stripped
$> file binary
binary: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x18dc5a21c6f0313a73840f9591328a75dbc1e624, not stripped
Première execution :
$> ./binary
*********************************
welcome to cracking challenge
*********************************
Enter you password: toto
$>
On le lance avec gdb, on break sur main, et c'est parti :)
1 2 0x0000000000400964 <+0>: push rbp 3 0x0000000000400965 <+1>: mov rbp,rsp 4 0x0000000000400968 <+4>: mov ecx,0x0 5 0x000000000040096d <+9>: mov edx,0x1 6 0x0000000000400972 <+14>: mov esi,0x0 7 0x0000000000400977 <+19>: mov edi,0x0 8 0x000000000040097c <+24>: mov eax,0x0 9 0x0000000000400981 <+29>: call 0x400590 <ptrace@plt> 10 0x0000000000400986 <+34>: test rax,rax 11 0x0000000000400989 <+37>: jns 0x400995 <main+49> 12 0x000000000040098b <+39>: mov edi,0x0 13 0x0000000000400990 <+44>: call 0x4005b0 <exit@plt> 14 0x0000000000400995 <+49>: mov eax,0x40077a 15 0x000000000040099a <+54>: mov eax,eax 16 0x000000000040099c <+56>: mov eax,DWORD PTR [rax] 17 0x000000000040099e <+58>: and eax,0xff 18 0x00000000004009a3 <+63>: cmp eax,0xcc 19 0x00000000004009a8 <+68>: jne 0x4009b4 <main+80> 20 0x00000000004009aa <+70>: mov edi,0x0 21 0x00000000004009af <+75>: call 0x4005b0 <exit@plt> 22 0x00000000004009b4 <+80>: mov eax,0x0 23 0x00000000004009b9 <+85>: call 0x400895 <xxxx> 24 0x00000000004009be <+90>: mov eax,0x0 25 0x00000000004009c3 <+95>: pop rbp 26 0x00000000004009c4 <+96>: ret
les fonctions du programme sont nommées :
-main() (anti debug puis appel à xxxx())
-x() (affichage du premier texte du binaire "banniere")
-xx() (un genre de strlen())
-xxx() (pas appelée, je suis pas allé fouiller)
-xxxx() (apelle x(), puis affiche le prompt suivi d'un scanf(), et apelle xxxxx())
-xxxxx() (fonction qui compare le password entré au pass attendu, et affiche le flag)
l'idéal est de break sur xxxxx() quand on a bypass le ptrace
xxxxx()
... Some stuff
1 2 0x00000000004007c0 <+70>: mov rdi,rax 3 0x00000000004007c3 <+73>: call 0x400c10 <base64_decode> 4 0x00000000004007c8 <+78>: lea rax,[rbp-0x30] 5 0x00000000004007cc <+82>: mov rdx,rax 6 0x00000000004007cf <+85>: mov eax,0x400f40 7 0x00000000004007d4 <+90>: mov ecx,0x5 8 0x00000000004007d9 <+95>: mov rsi,rdx 9 0x00000000004007dc <+98>: mov rdi,rax 10 0x00000000004007df <+101>: repz cmps BYTE PTR ds:[rsi],BYTE PTR es:[rdi] 11 ...
repz cmps BYTE PTR ds:[rsi],BYTE PTR es:[rdi] // à ce moment là rdi = "samir" && rsi = base64_decode(user_entry)
on en conclus donc que "samir" en base64 est le mot de passe attendu.
on essaye :
$> echo `python -c "print 'samir'.encode('base64')"`| ./binary
*********************************
welcome to cracking challenge
*********************************
Enter you password: Flag: ping-pong you pasamir
Et paf , le flag était "ping-pong" .
fr0g