mirror of
https://github.com/trustedsec/ELFLoader
synced 2026-06-08 17:56:51 +00:00
Misc changes for freebsd and openbsd
- getOSName and strcmp to check version of OS, and do different logic. - Hack to allocate memory closer together.
This commit is contained in:
+17
-3
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "beacon_api.h"
|
||||
@@ -9,12 +10,25 @@ int run_pwd(void){
|
||||
int retcode = 0;
|
||||
char workingdir[256] = {0};
|
||||
char* workdir = NULL;
|
||||
char* osversion = getOSName();
|
||||
workdir = getcwd(workingdir, 255);
|
||||
if (workdir == NULL){
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "ERROR\n");
|
||||
/* An example of working around BeaconPrintf failure for freebsd */
|
||||
if (strcmp("freebsd", osversion) == 0){
|
||||
if (workdir == NULL){
|
||||
BeaconOutput(CALLBACK_OUTPUT, "ERROR\n", 6);
|
||||
}
|
||||
else{
|
||||
BeaconOutput(CALLBACK_OUTPUT, workingdir, strlen(workingdir));
|
||||
BeaconOutput(CALLBACK_OUTPUT, "\n", 1);
|
||||
}
|
||||
}
|
||||
else{
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "%s\n", workingdir);
|
||||
if (workdir == NULL){
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "ERROR\n");
|
||||
}
|
||||
else{
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "%s\n", workingdir);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ int run_uname(void){
|
||||
retcode = uname(&values);
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "%s %s %s %s %s\n", values.sysname, values.nodename, values.release, values.version, values.machine);
|
||||
}
|
||||
else if (strcmp("apple", osversion) == 0){
|
||||
else if (strcmp("apple", osversion) == 0 || strcmp("freebsd", osversion) == 0|| strcmp("openbsd", osversion) == 0){
|
||||
retcode = uname((struct utsname*)&values_mac);
|
||||
BeaconPrintf(CALLBACK_OUTPUT, "%s %s %s %s %s\n", values_mac.sysname, values_mac.nodename, values_mac.release, values_mac.version, values_mac.machine);
|
||||
}
|
||||
|
||||
+4
-1
@@ -56,6 +56,7 @@ int ELFRunner(char* functionName, unsigned char* elfObjectData, unsigned int siz
|
||||
int c2 = 0;
|
||||
int (*ptr)(unsigned char*, int) = (int (*)(unsigned char *, int))NULL;
|
||||
int retcode = 0;
|
||||
int tempOffsetCounter = 0;
|
||||
|
||||
memset(&elfinfo, 0, sizeof(ELFInfo_t));
|
||||
|
||||
@@ -119,6 +120,7 @@ int ELFRunner(char* functionName, unsigned char* elfObjectData, unsigned int siz
|
||||
elfinfo.tempOffsetTable = VirtualAlloc(NULL, 255*ThunkTrampolineSize, MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE);
|
||||
#else
|
||||
elfinfo.tempOffsetTable = mmap(NULL, 255*ThunkTrampolineSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
tempOffsetCounter += 0x5000;
|
||||
#endif
|
||||
elfinfo.tempOffsetCounter = 0;
|
||||
if (elfinfo.tempOffsetTable == NULL || elfinfo.tempOffsetTable == (void*)-1){
|
||||
@@ -147,7 +149,8 @@ int ELFRunner(char* functionName, unsigned char* elfObjectData, unsigned int siz
|
||||
#ifdef WIN32
|
||||
elfinfo.sectionMappings[counter] = VirtualAlloc(NULL, elfinfo.sectHeader[counter].sh_size, MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE);
|
||||
#else
|
||||
elfinfo.sectionMappings[counter] = mmap(NULL, elfinfo.sectHeader[counter].sh_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
elfinfo.sectionMappings[counter] = mmap(elfinfo.tempOffsetTable+tempOffsetCounter, elfinfo.sectHeader[counter].sh_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
tempOffsetCounter += 0x5000;
|
||||
#endif
|
||||
if (elfinfo.sectionMappings[counter] == NULL || elfinfo.sectionMappings[counter] == (void*)-1){
|
||||
DEBUG_PRINT("\t\t\tFailed to allocate memory for section\n");
|
||||
|
||||
Reference in New Issue
Block a user