The GOT and PLT are tables for which a program gets linked.
In Linux there is a way to get in between this linking called LD_PRELOAD
We want our library here!
#define _GNU_SOURCE
/* Most imports for things you might need, Do Not Delete any */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/fcntl.h>
#include <dlfcn.h>
#include <dirent.h>
/* Compile: gcc -Wall -fPIC -shared -o evil.so framework.c -ldl */
/* -ldl must be last!!! */
static int (*o_open)(const char *, int);
static void init (void) __attribute__ ((constructor));
/* loaded and executed when ld runs */
void init(void){
/* Get handle on original open */
o_open=dlsym(RTLD_NEXT, "open");
}
/* Try: LD_PRELOAD=./evil.so cat framework.c */
int open(const char *pathname, int flags, ...){
/* example */
printf("Hello world\n");
/* Your code here */
/* Preserve functionality */
return o_open(pathname, flags);
}
Imports for libraries we want to use or hook
SO compile flags
Dynamic set up to best mask our presence
The Hook:
Trace them! Last week we talked about Ltrace and Strace!
Ltrace is going be great, its output goes to STDERR or we can use the `-o FILE` option. Programs like Vim or Emacs will have long traces, and so we might want to grep for certain functions we hope to find. This is why I mention `-o FILE` so we can save output while running the program separately
Tracing slows the process a LOT, give it time to execute!
a means of analyzing a program to determine what inputs cause each part of a program to execute. An interpreter follows the program, assuming symbolic values for inputs rather than obtaining actual inputs as normal execution of the program would, a case of abstract interpretation. It thus arrives at expressions in terms of those symbols for expressions and variables in the program, and constraints in terms of those symbols for the possible outcomes of each conditional branch. -wiki
A Windows object is a data structure that represents a system resource
Windows objects are created and accessed using the Win32 API
In order to "attach" to a process we need to get a handle to the target process
OpenProcess to get a handle!
First we need to get the length of the path to our DLL
We can then directly request memory from the process we opened (remember the permissions we requested)
First we need to get LoadLibraryA from kernell32.dll
We're not actually going to load the DLL into memory directly. We're going to tell the process to do it for us
First we need to get LoadLibraryA from kernell32.dll
With this method we tell the process handle to create a remote thread and start the thread with LoadLibraryA, with the DLL name as the argument