Skip to content

Instantly share code, notes, and snippets.

@amtal
Created September 29, 2016 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amtal/0b6c52fe51c8748efe40d916d3cb1ebb to your computer and use it in GitHub Desktop.
Save amtal/0b6c52fe51c8748efe40d916d3cb1ebb to your computer and use it in GitHub Desktop.
LD_PRELOAD scripting
#!/usr/bin/tcc -run
#include <stdio.h> // printf, perror, vsprintf
// injector
#include <stdlib.h> // setenv
#include <unistd.h> // execve
// hoooooks
#define __USE_GNU // man page says _GNU_SOURCE but is wrong lol
#include <dlfcn.h> // dlsym
#include <string.h> // strcmp
#include <curses.h>
int main(int ac, char** av) {
if (getenv("LD_PRELOAD")) {
static int (*fun)();
fun = dlsym(RTLD_NEXT, __func__);
fun(ac, av);
} else {
printf("%d\n", system("/usr/bin/tcc " __FILE__ " -ldl -lncursesw -shared -o lmao.so"));
// ^ ^ lmao
setenv("LD_PRELOAD", "lmao.so", 1);
extern char** environ;
int ret = execve("/usr/bin/vbindiff", av, environ);
perror("wat");
}
}
int __sprintf_chk(char* str, int flag, size_t strlen, const char* format, ...) {
if (0 == strcmp(format, "%02X ")) {format = "%02x";}
va_list args;
va_start(args, format);
int ret = vsprintf(str, format, args);
va_end(args);
return ret;
}
int waddnstr(WINDOW* win, const char* str, int n) {
static int (*fun)();
if (!fun) {fun = dlsym(RTLD_NEXT, __func__);}
fun(win, str, n);
if (2 == strlen(str)) {
int val;
scanf("%02x", val);
wattr_set(win, val, val, NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment