Added changes and example of building as .so file, a runner.c file, and how to run it for #1

This commit is contained in:
Kevin Haubris
2022-05-16 12:48:34 -05:00
parent 3e3c44f713
commit 34fd7ba6cc
6 changed files with 80 additions and 2 deletions
+7
View File
@@ -9,6 +9,12 @@ x86_64:
x86_64D:
gcc -g -DDEBUG -Wall -I ./includes/ -DTESTING_MAIN $(SOURCES) -ldl -o ELFLoaderD.out
x86_64so:
gcc -shared -fPIC -fvisibility=hidden -DLIBRARY -Wall -I ./includes/ -DTESTING_MAIN $(SOURCES) -ldl -o libELFLoader.so
x86_64runner:
gcc -I ./includes/ runner.c -o runner.out -L . -lELFLoader
x86_64_bsd:
gcc -Wall -I ./includes/ -DTESTING_MAIN $(SOURCES) -o ELFLoader_bsd.out
@@ -124,4 +130,5 @@ clean:
rm -f ./SA/src/*.o
rm -f testobjects/*.o
rm -f ELFLoader_public
rm -f libELFLoader.so
.PHONY: x86_64 x86_64D test2_dup test2 test clean
+8
View File
@@ -115,3 +115,11 @@ This is the generic example that doesn't take any arguments.
```
./ELFLoader.out SA/src/uname.o
```
### Runner and Library Example
```
make x86_64so
make x86_64runner
LD_LIBRARY_PATH=. ./runner.out ./SA/src/env.o
```
+8
View File
@@ -0,0 +1,8 @@
#ifndef ELFLOADER_INCLUDE_H_
#define ELFLOADER_INCLUDE_H_
int ELFRunner(char* functionName, unsigned char* elfObjectData, unsigned int size, unsigned char* argumentdata, int argumentSize);
char* BeaconGetOutputData(int *outsize);
unsigned char* unhexlify(unsigned char* value, int *outlen);
#endif
+48
View File
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ELFRunner_include.h>
int main(int argc, char** argv, char** envp)
{
//int (*ptr)(char*, int*);
unsigned char* buf = NULL;
int size = 0;
FILE* elf = NULL;
int checkcode = 0;
char* outputdata = NULL;
char* argumentdata = NULL;
int argumentdatalen = 0;
int outputdataLen = 0;
if (argc < 2){
printf("%s ./path/to/objectfile.o\n", argv[0]);
return 0;
}
elf = fopen(argv[1], "rb");
if (elf == NULL){
printf("ERROR: File doesn't exist\n");
return 0;
}
fseek(elf, 0, SEEK_END);
size = ftell(elf);
fseek(elf, 0, SEEK_SET);
buf = calloc(size, 1);
if (buf == NULL){
return 0;
}
(void)fread(buf, 1, size, elf);
argumentdata = (char*)unhexlify((unsigned char*)argv[2], &argumentdatalen);
checkcode = ELFRunner("go", buf, size, (unsigned char*)argumentdata, argumentdatalen );
if (checkcode == 0){
outputdata = BeaconGetOutputData(&outputdataLen);
printf("Output data : %s\n", outputdata);
free(outputdata);
}
free(buf);
fclose(elf);
return 0;
}
+6 -2
View File
@@ -14,7 +14,9 @@
#include "ELFLoader.h"
#include "beacon_compatibility.h"
#ifdef LIBRARY
__attribute__ ((visibility ("default")))
#endif
unsigned char* unhexlify(unsigned char* value, int *outlen){
unsigned char* retval = NULL;
char byteval[3] = {0};
@@ -48,7 +50,9 @@ errcase:
return retval;
}
#ifdef LIBRARY
__attribute__ ((visibility ("default")))
#endif
int ELFRunner(char* functionName, unsigned char* elfObjectData, unsigned int size, unsigned char* argumentdata, int argumentSize){
#if defined(__amd64__) || defined(__x86_64__) || defined(__i386__) || (defined(DEBUG) && defined(ELFRUNNERTEST))
ELFInfo_t elfinfo;
+3
View File
@@ -318,6 +318,9 @@ int BeaconIsAdmin(void){
return 0;
}
#ifdef LIBRARY
__attribute__ ((visibility ("default")))
#endif
char* BeaconGetOutputData(int *outsize){
char* outdata = beacon_compatibility_output;
*outsize = beacon_compatibility_size;