Created
May 9, 2021 12:52
-
-
Save luhenry/f20f9d0683dcacf4f3907de66d455287 to your computer and use it in GitHub Desktop.
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> | |
int foo(void) { | |
printf("hello from helper\n"); | |
return 1; | |
} |
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> | |
int foo(void) { | |
printf("hello from hijack\n"); | |
return 0; | |
} |
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 <stdlib.h> | |
#define _GNU_SOURCE 1 | |
#include <dlfcn.h> | |
// int foo(void); | |
int main(void) { | |
void *libhandle = dlopen("libhelper.so", RTLD_LAZY | RTLD_GLOBAL); | |
int (*foo)(void) = dlsym(NULL, "foo"); | |
return foo(); | |
} |
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
a.out: main.c | |
gcc $< -o $@ -ldl | |
libhijack.so: hijack.c | |
gcc $< -shared -o $@ | |
libhelper.so: helper.c | |
gcc $< -shared -o $@ | |
run: a.out libhijack.so libhelper.so | |
LD_DEBUG=libs,symbols LD_LIBRARY_PATH=`pwd` $(if $(HIJACK),LD_PRELOAD=libhijack.so) ./$< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment