At the moment its not very efficient. to do so, you may need to implement your own api cash.
now just shift each char of the api string by 1, and define it like this #define obfuscated_apiname. now to call api, use something like this API(dll that contains the api, apiname)
Code #include <string.h>
#include <stdlib.h>
#include <Windows.h>
#include <stdio.h>
typedef int (WINAPI *typeMessageBoxA)(
HWND hWnd,
LPCSTR lpText,
LPCSTR lpCaption,
UINT uType
);
#define obfuscated_MessageBoxA "NfttbhfCpyB"
char* deob(char* str)
{
char* mystr = (char*)malloc(strlen(str) +1);
strcpy(mystr, str);
for(int i = 0; mystr[i];)
--mystr[i++];
return mystr;
}
#define API(DLL, FUNC) ((type##FUNC)GetProcAddress(LoadLibraryA(#DLL), deob(obfuscated_##FUNC)))
int main()
{
API(user32, MessageBoxA)(NULL, "putain d'merde", 0, 0);
}
you have 3 MessageBoxA != obfuscate api calls
Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Sep 8, 2019 01:19 PM
(This post was last modified: Sep 8, 2019 01:20 PM by myselfandi.)
(Sep 8, 2019 01:07 PM)HFDone Wrote: you have 3 MessageBoxA != obfuscate api calls
Not sure what you mean by that.
So basically an inefficient -ROT1 algorithm for a string that feeds GetProcAddress? > 🤨 Not terribly useful.
(Sep 8, 2019 05:55 PM)0xDEAD10CC Wrote: So basically an inefficient -ROT1 algorithm for a string that feeds GetProcAddress? > 🤨 Not terribly useful.
You are about right. In production code it would more convenient to hash the api strings then walk the export table of dlls comparing each api to the hash. You can even go further and create a hash table that holds a hash and pointer the previously called apis , so you don't need do an O(n) look up for each api call that has been made. nevertheless the inefficient ro1 algorithm was very suitable for my 5 api calls.
Sep 8, 2019 06:26 PM
(This post was last modified: Sep 8, 2019 06:26 PM by 0xDEAD10CC.)
This is still not terribly useful because in order for GetProcAddress() to do anything with the string, it must be the normal string - breakpoints are a very simple thing.. If you want to hide data from a hex editor, that can be done easily without any of this weird stuff.
(Sep 8, 2019 06:26 PM)0xDEAD10CC Wrote: This is still not terribly useful because in order for GetProcAddress() to do anything with the string, it must be the normal string - breakpoints are a very simple thing.. If you want to hide data from a hex editor, that can be done easily without any of this weird stuff.
Yes, i'm trying to hide data from a hex editor, and yes there are easier ways to do it, but i wanted to try something different :).
Sep 9, 2019 01:33 AM
(This post was last modified: Sep 9, 2019 01:34 AM by Friedrich Nietzsche.)
LoadLibrary + GetProcAddress is hardly good obfuscation.
You literally just have to hook GetProcAddress and you get exactly what API's the program is requesting.
Static wise, its ok though.
DO NOT DEAL WITH THIS MEMBER
(Sep 8, 2019 06:26 PM)0xDEAD10CC Wrote: This is still not terribly useful because in order for GetProcAddress() to do anything with the string, it must be the normal string - breakpoints are a very simple thing.. If you want to hide data from a hex editor, that can be done easily without any of this weird stuff.
It works for static analysis I guess if you can't read basic assembly and see that a function is subtracting/adding 1 to the dereferenced pointer value. Otherwise it's not very useful.
But a lot of times defeating static analysis is useful and a harder encryption would be better.
Sep 9, 2019 11:26 AM
(This post was last modified: Sep 9, 2019 11:26 AM by myselfandi.)
(Sep 9, 2019 01:33 AM)Friedrich Nietzsche Wrote: LoadLibrary + GetProcAddress is hardly good obfuscation.
You literally just have to hook GetProcAddress and you get exactly what API's the program is requesting.
Static wise, its ok though.
I'm aware of that. for my purposes i wanted to just obfuscate the api function from the .data section, and by calling it dynamically i avoid it being included in the import table.
And about hooking GetProcAddress, I don't think its always worth it to walk the export table to get api addresses, because function that are used to manipulate other process memory are most likely to be hooked.
|