Last active
July 6, 2019 16:17
-
-
Save integeruser/f6df45e1e0f05787d7799fe54af98b85 to your computer and use it in GitHub Desktop.
Preload read() to exit() on EOF
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
#define _GNU_SOURCE | |
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* gcc -shared -fPIC exit-on-EOF.c -o exit-on-EOF.so -ldl */ | |
/* LD_PRELOAD=./exit-on-EOF.so ./test */ | |
/* AFL_PRELOAD=./exit-on-EOF.so afl-fuzz -i in -o out -n -- ./test */ | |
typedef int (*orig_read_f_type)(int fd, void *buf, int count); | |
int read(int fd, void *buf, int count) { | |
orig_read_f_type orig_read = (orig_read_f_type)dlsym(RTLD_NEXT, "read"); | |
for (int i = 0; i < count; ++i) { | |
int n = orig_read(fd, buf++, 1); | |
if (n == 0) { | |
printf("EOF!\n"); | |
exit(-1337); | |
} | |
} | |
return count; | |
} |
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
#include <stdio.h> | |
#include <unistd.h> | |
int main(int argc, char const *argv[]) { | |
char c; | |
do { | |
read(STDIN_FILENO, &c, 1); | |
printf("%c", c); | |
} | |
while(1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment