Skip to content

Instantly share code, notes, and snippets.

@chemikadze
Created June 16, 2019 04:44
Show Gist options
  • Save chemikadze/7c319251cdfa94f23b2cdb6b481843ba to your computer and use it in GitHub Desktop.
Save chemikadze/7c319251cdfa94f23b2cdb6b481843ba to your computer and use it in GitHub Desktop.

Add more 420 to your files!

chemikadze@chemikadze:~/fakels$ make
gcc -shared -o lib420.so lib420.c
LD_PRELOAD=./lib420.so ls -l
total 16
-rw-rw-r-- 1 chemikadze chemikadze 1013 Apr 20 04:20 lib420.c
-rwxrwxr-x 1 chemikadze chemikadze 7816 Apr 20 04:20 lib420.so
-rw-rw-r-- 1 chemikadze chemikadze  137 Apr 20 04:20 Makefile

Illustrates hooking into existing binary by redefining existing dynamically-linked symbols.

#define _GNU_SOURCE
#include <unistd.h>
#include <dlfcn.h>
#include <sys/stat.h>
static int (*orig___lxstat)(int version, const char * __path, struct stat *__statbuf);
#define TIME_420 1555734000
void __attribute__ ((constructor)) resolve_dynamic_symbols(void) {
*(void**)(&orig___lxstat) = dlsym(RTLD_NEXT, "__lxstat");
}
int __lxstat(int version, const char * __path, struct stat *__statbuf) {
int res = orig___lxstat(version, __path, __statbuf);
if (__statbuf != NULL) {
__statbuf->st_mtime = TIME_420;
}
return res;
}
demo: lib420.so
LD_PRELOAD=./lib420.so ls -l
.PHONY: demo
lib420.so: lib420.c
gcc -shared -o lib420.so lib420.c
clean:
rm lib420.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment