Created
December 13, 2020 13:25
-
-
Save jasperla/d925cabe5b1e1f273f1221de8b5a6cde to your computer and use it in GitHub Desktop.
Common CTF functions for LD_PRELOAD
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
/* | |
* cc -Wall -o funcs.so -shared funcs.c -DENABLE_ALL | |
* | |
* LD_PRELOAD=./funcs.so ./target | |
* or from inside gdb: | |
* set environment LD_PRELOAD=./funcs.so | |
*/ | |
#include <unistd.h> | |
#if defined(ENABLE_PTRACE) || defined(ENABLE_ALL) | |
#define PTRACE_TRACEME 0 | |
long | |
ptrace(int request, pid_t pid, void *addr, void *data) { | |
if (request == PTRACE_TRACEME) { | |
return 0; | |
} | |
/* Default to returning 0 for unrecognized requests. */ | |
return 0; | |
} | |
#endif /* ENABLE_PTRACE */ | |
#if defined(ENABLE_RAND) || defined(ENABLE_ALL) | |
int | |
rand(void) { | |
/* Chosen by fair dice roll. Guaranteed to be random. */ | |
return 4; | |
} | |
#endif /* ENABLE_RAND */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment