Skip to content

Instantly share code, notes, and snippets.

@ellcs
Created March 9, 2020 14:51
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 ellcs/9849d98638b397d9f820ceda8ca34d73 to your computer and use it in GitHub Desktop.
Save ellcs/9849d98638b397d9f820ceda8ca34d73 to your computer and use it in GitHub Desktop.
Override method in compiled file
// Step 1) gcc -fpic -shared -o execve.so execve_overload.c
#ifndef foo_h__
#define foo_h__
#include <stdio.h>
#include "stdlib.h"
int execve(const char *filename, char *const argv[], char *const envp[]) {
puts("Overwritten. Bye!");
exit(0);
}
#endif // foo_h__
// Step 2) gcc main.c
// Step 3) LD_PRELOAD=./execve.so ./a.out
int main() {
execve("/bin/bash");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment