Created
August 14, 2015 16:12
-
-
Save lattera/c07913190b0155094ac9 to your computer and use it in GitHub Desktop.
relro + dlopen
This file contains 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
laptop-dev-01[shawn]:/home/shawn/tmp $ cat dlopen.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <dlfcn.h> | |
int main(int argc, char *argv[]) | |
{ | |
void *handle; | |
if (argc < 3) { | |
printf("USAGE: %s /path/to/lib symname\n", argv[0]); | |
exit(1); | |
} | |
handle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL); | |
if (!(handle)) { | |
fprintf(stderr, "%s\n", dlerror()); | |
exit(1); | |
} | |
printf("%s: %p\n", argv[2], dlsym(handle, argv[2])); | |
dlclose(handle); | |
return 0; | |
} | |
laptop-dev-01[shawn]:/home/shawn/tmp $ clang -Wl,-z,relro -Wl,-z,now -fPIE -pie -o dlopen dlopen.c | |
laptop-dev-01[shawn]:/home/shawn/tmp $ ./dlopen /lib/libthr.so.3 pthread_create | |
pthread_create: 0x4a7781dc080 | |
laptop-dev-01[shawn]:/home/shawn/tmp $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment