Obfusk8: lightweight Obfuscation library based on C++17 / Header Only for windows binaries
Obfusk8: lightweight Obfuscation library based on C++17 / Header Only for windows binaries
Obfusk8 is a lightweight, header-only C++17 library designed to significantly enhance the obfuscation of your applications, making reverse engineering a substantially more challenging endeavor. It achieves this through a diverse set of compile-time and runtime techniques aimed at protecting your code's logic and data.
main Function Wrapping (_main Macro)The entry point of your application (main) is transformed into a complex, multi-layered obfuscation engine:
main_body code is executed, a mini-VM (simulated CPU) runs a sequence of "encrypted" instructions. This conceals the true entry point and initial operations. The VM's state (registers, program counter, dispatch key) is initialized with runtime-randomized values._main macro (both in the prologue and epilogue) are transformed into intricate state machines. Control flow is not direct but determined by heavily "encrypted" state variables. The encoding/decoding keys for these state variables are dynamic, derived from VM state, loop counters, compile-time randomness (like __COUNTER__, __LINE__, __TIME__), and a global opaque seed. This makes static analysis of the control flow exceptionally difficult.obf_icff_ns_dcff and obf_icff_ns_epd) are used with different state transition logic and key generation, further complicating analysis.OBF_BOGUS_FLOW_* macros): Numerous misleading jump patterns and convoluted conditional structures are injected throughout _main. These use goto statements combined with opaque predicates (conditions that always evaluate to true or false but are computationally expensive or hard to determine statically). This creates a labyrinth of false paths for disassemblers and decompilers.OBF_BOGUS_FLOW_LABYRINTH, OBF_BOGUS_FLOW_GRID, OBF_BOGUS_FLOW_SCRAMBLE, OBF_BOGUS_FLOW_WEAVER, OBF_BOGUS_FLOW_CASCADE, and OBF_BOGUS_FLOW_CYCLONE to generate diverse and complex bogus flows.Runtime macro, SEH):__except blocks can alter program state, making it hard to follow if the debugger skips exceptions.Runtime macro contains conditions that, if met (due to specific VM states or timing), could trigger __debugbreak() or throw exceptions, designed to disrupt debugging sessions.obf_vm_engine)A core component of the _main macro's obfuscation:
r0, r1, r2), a program counter (pc), and a dispatch_key. It executes custom "instructions" (handlers).reg_dispatch_idx).get_mem_dispatch_table).mixed_dispatch_idx).
The dispatch_key is constantly mutated, making the sequence of executed handlers highly unpredictable.vm_handler_table) is itself mutated at runtime within the _main prologue and epilogue, further obscuring the VM's behavior.OBFUSCATE_STRING from AES8.hpp)__FILE__, __LINE__), and build time (__DATE__, __TIME__).AES8.hpp).STEALTH_API_OBFSTR / STEALTH_API_OBF from Resolve8.hpp)GetModuleHandle and GetProcAddress for initial resolution if those themselves are not yet resolved by this mechanism.CT_HASH) of DLL and API names for lookups. This prevents plaintext DLL and API names from appearing in the binary's import-related data or string tables when using these macros.K8_SYSCALL)Obfusk8 now integrates a state-of-the-art Indirect Syscall mechanism to bypass User-Mode Hooks (EDRs/AVs) and static analysis checks.
K8_SYSCALL("ZwOpenProcess", ...) instead of NtOpenProcess.OBF_METHOD)Obfusk8 now provides granular control over your binary's security through Method-Based Obfuscation. Instead of obfuscating your entire project (which can impact performance), you can now selectively protect specific, high-value functions or class methods.
Include the Pass
Ensure you include the method obfuscation logic in your project:
#include "../transform/PASSES/obf_cmethods.cxx"The Macro Syntax
Define your method using the OBF_METHOD macro:
OBF_METHOD(ret_type, func_name, params, method_body)ret_type: The return type of your function (e.g., bool, int, void*).func_name: The name of the method.params: The function parameters (must be enclosed in parentheses).method_body: The actual logic of your function enclosed in { }.In this example, PrintStatus is a normal, readable function. Obfusk8_PrintStatus is protected by Obfusk8.
…You can view the full example here: obfusk8_methods.cpp
Obfusk8 provides helper classes that encapsulate common sets of Windows APIs. These classes automatically use the stealthy API resolution mechanism (STEALTH_API_OBFSTR) during their construction, ensuring that the underlying Windows functions are resolved without leaving obvious static import traces.
K8_ProcessManipulationAPIs::ProcessAPI (k8_ProcessManipulationAPIs.hpp):
OpenProcess, TerminateProcess, CreateRemoteThread, VirtualAllocEx, WriteProcessMemory, ReadProcessMemory, GetProcAddress, GetModuleHandleA, NtQueryInformationProcess, SuspendThread, and GetCurrentProcessId.kernel32.dll and ntdll.dll stealthily.PROCESSINFOCLASS enum for use with NtQueryInformationProcess.k8_CryptographyAPIs::CryptographyAPI (k8_CryptographyAPIs.hpp):
CryptAcquireContextA, CryptCreateHash, etc.)advapi32.dll (and kernel32.dll for core functions) stealthily.k8_NetworkingAPIs::NetworkingAPI (k8_NetworkingAPIs.hpp):
wininet.dll (e.g., InternetOpenA, HttpOpenRequestA, FtpPutFileA), urlmon.dll (e.g., URLDownloadToFileA), ws2_32.dll (e.g., socket, connect, WSAStartup), shell32.dll (e.g., ShellExecuteA), dnsapi.dll (e.g., DnsQuery_A), and mpr.dll (e.g., WNetOpenEnumA).STEALTH_API_OBFSTR and OBFUSCATE_STRING to resolve all required functions from their respective DLLs (and kernel32.dll for LoadLibraryA/GetLastError) without leaving obvious import traces.RegistryAPIs::RegistryAPI (k8_RegistryAPIs.hpp):
RegSetValueExA, RegCreateKeyExA, RegOpenKeyExA, RegQueryValueExA, RegCloseKey, etc.advapi32.dll (and kernel32.dll) stealthily during construction.Obfusk8Core.hpp)These are the building blocks used extensively throughout the library, especially in the _main macro and VM engine:
OBF_MBA_ADD, OBF_MBA_XOR). These are designed to be very difficult for decompilers to simplify back to their original forms.OBF_OPAQUE_PREDICATE_TRUE_1) or always false (e.g., OBF_OPAQUE_PREDICATE_FALSE_1). These conditions are constructed from complex, hard-to-statically-evaluate expressions involving __COUNTER__, __LINE__, `_No open issues yet, or sync has not completed.