Skip to content

Instantly share code, notes, and snippets.

@jasperla
Created December 13, 2020 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperla/d925cabe5b1e1f273f1221de8b5a6cde to your computer and use it in GitHub Desktop.
Save jasperla/d925cabe5b1e1f273f1221de8b5a6cde to your computer and use it in GitHub Desktop.
Common CTF functions for LD_PRELOAD
/*
* 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