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-2015-2426/dll/src/ReflectiveLoader.h
Views: 11789
//===============================================================================================//1// Copyright (c) 2013, 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#ifndef _REFLECTIVEDLLINJECTION_REFLECTIVELOADER_H28#define _REFLECTIVEDLLINJECTION_REFLECTIVELOADER_H29//===============================================================================================//30#define WIN32_LEAN_AND_MEAN31#include <windows.h>32#include <Winsock2.h>33#include <intrin.h>3435#include "ReflectiveDLLInjection.h"3637// Enable this define to turn on OutputDebugString support38//#define ENABLE_OUTPUTDEBUGSTRING 13940// Enable this define to turn on locking of memory to prevent paging41#define ENABLE_STOPPAGING 14243#define EXITFUNC_SEH 0xEA320EFE44#define EXITFUNC_THREAD 0x0A2A1DE045#define EXITFUNC_PROCESS 0x56A2B5F04647typedef HMODULE (WINAPI * LOADLIBRARYA)( LPCSTR );48typedef FARPROC (WINAPI * GETPROCADDRESS)( HMODULE, LPCSTR );49typedef LPVOID (WINAPI * VIRTUALALLOC)( LPVOID, SIZE_T, DWORD, DWORD );50typedef DWORD (NTAPI * NTFLUSHINSTRUCTIONCACHE)( HANDLE, PVOID, ULONG );5152#define KERNEL32DLL_HASH 0x6A4ABC5B53#define NTDLLDLL_HASH 0x3CFA685D5455#define LOADLIBRARYA_HASH 0xEC0E4E8E56#define GETPROCADDRESS_HASH 0x7C0DFCAA57#define VIRTUALALLOC_HASH 0x91AFCA5458#define NTFLUSHINSTRUCTIONCACHE_HASH 0x534C0AB85960#ifdef ENABLE_STOPPAGING61typedef LPVOID (WINAPI * VIRTUALLOCK)( LPVOID, SIZE_T );62#define VIRTUALLOCK_HASH 0x0EF632F263#endif6465#ifdef ENABLE_OUTPUTDEBUGSTRING66typedef LPVOID (WINAPI * OUTPUTDEBUG)( LPCSTR );67#define OUTPUTDEBUG_HASH 0x470D22BC68#endif6970#define IMAGE_REL_BASED_ARM_MOV32A 571#define IMAGE_REL_BASED_ARM_MOV32T 77273#define ARM_MOV_MASK (DWORD)(0xFBF08000)74#define ARM_MOV_MASK2 (DWORD)(0xFBF08F00)75#define ARM_MOVW 0xF240000076#define ARM_MOVT 0xF2C000007778#define HASH_KEY 1379//===============================================================================================//80#pragma intrinsic( _rotr )8182__forceinline DWORD ror( DWORD d )83{84return _rotr( d, HASH_KEY );85}8687__forceinline DWORD _hash( char * c )88{89register DWORD h = 0;90do91{92h = ror( h );93h += *c;94} while( *++c );9596return h;97}98//===============================================================================================//99typedef struct _UNICODE_STR100{101USHORT Length;102USHORT MaximumLength;103PWSTR pBuffer;104} UNICODE_STR, *PUNICODE_STR;105106// WinDbg> dt -v ntdll!_LDR_DATA_TABLE_ENTRY107//__declspec( align(8) )108typedef struct _LDR_DATA_TABLE_ENTRY109{110//LIST_ENTRY InLoadOrderLinks; // As we search from PPEB_LDR_DATA->InMemoryOrderModuleList we dont use the first entry.111LIST_ENTRY InMemoryOrderModuleList;112LIST_ENTRY InInitializationOrderModuleList;113PVOID DllBase;114PVOID EntryPoint;115ULONG SizeOfImage;116UNICODE_STR FullDllName;117UNICODE_STR BaseDllName;118ULONG Flags;119SHORT LoadCount;120SHORT TlsIndex;121LIST_ENTRY HashTableEntry;122ULONG TimeDateStamp;123} LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;124125// WinDbg> dt -v ntdll!_PEB_LDR_DATA126typedef struct _PEB_LDR_DATA //, 7 elements, 0x28 bytes127{128DWORD dwLength;129DWORD dwInitialized;130LPVOID lpSsHandle;131LIST_ENTRY InLoadOrderModuleList;132LIST_ENTRY InMemoryOrderModuleList;133LIST_ENTRY InInitializationOrderModuleList;134LPVOID lpEntryInProgress;135} PEB_LDR_DATA, * PPEB_LDR_DATA;136137// WinDbg> dt -v ntdll!_PEB_FREE_BLOCK138typedef struct _PEB_FREE_BLOCK // 2 elements, 0x8 bytes139{140struct _PEB_FREE_BLOCK * pNext;141DWORD dwSize;142} PEB_FREE_BLOCK, * PPEB_FREE_BLOCK;143144// struct _PEB is defined in Winternl.h but it is incomplete145// WinDbg> dt -v ntdll!_PEB146typedef struct __PEB // 65 elements, 0x210 bytes147{148BYTE bInheritedAddressSpace;149BYTE bReadImageFileExecOptions;150BYTE bBeingDebugged;151BYTE bSpareBool;152LPVOID lpMutant;153LPVOID lpImageBaseAddress;154PPEB_LDR_DATA pLdr;155LPVOID lpProcessParameters;156LPVOID lpSubSystemData;157LPVOID lpProcessHeap;158PRTL_CRITICAL_SECTION pFastPebLock;159LPVOID lpFastPebLockRoutine;160LPVOID lpFastPebUnlockRoutine;161DWORD dwEnvironmentUpdateCount;162LPVOID lpKernelCallbackTable;163DWORD dwSystemReserved;164DWORD dwAtlThunkSListPtr32;165PPEB_FREE_BLOCK pFreeList;166DWORD dwTlsExpansionCounter;167LPVOID lpTlsBitmap;168DWORD dwTlsBitmapBits[2];169LPVOID lpReadOnlySharedMemoryBase;170LPVOID lpReadOnlySharedMemoryHeap;171LPVOID lpReadOnlyStaticServerData;172LPVOID lpAnsiCodePageData;173LPVOID lpOemCodePageData;174LPVOID lpUnicodeCaseTableData;175DWORD dwNumberOfProcessors;176DWORD dwNtGlobalFlag;177LARGE_INTEGER liCriticalSectionTimeout;178DWORD dwHeapSegmentReserve;179DWORD dwHeapSegmentCommit;180DWORD dwHeapDeCommitTotalFreeThreshold;181DWORD dwHeapDeCommitFreeBlockThreshold;182DWORD dwNumberOfHeaps;183DWORD dwMaximumNumberOfHeaps;184LPVOID lpProcessHeaps;185LPVOID lpGdiSharedHandleTable;186LPVOID lpProcessStarterHelper;187DWORD dwGdiDCAttributeList;188LPVOID lpLoaderLock;189DWORD dwOSMajorVersion;190DWORD dwOSMinorVersion;191WORD wOSBuildNumber;192WORD wOSCSDVersion;193DWORD dwOSPlatformId;194DWORD dwImageSubsystem;195DWORD dwImageSubsystemMajorVersion;196DWORD dwImageSubsystemMinorVersion;197DWORD dwImageProcessAffinityMask;198DWORD dwGdiHandleBuffer[34];199LPVOID lpPostProcessInitRoutine;200LPVOID lpTlsExpansionBitmap;201DWORD dwTlsExpansionBitmapBits[32];202DWORD dwSessionId;203ULARGE_INTEGER liAppCompatFlags;204ULARGE_INTEGER liAppCompatFlagsUser;205LPVOID lppShimData;206LPVOID lpAppCompatInfo;207UNICODE_STR usCSDVersion;208LPVOID lpActivationContextData;209LPVOID lpProcessAssemblyStorageMap;210LPVOID lpSystemDefaultActivationContextData;211LPVOID lpSystemAssemblyStorageMap;212DWORD dwMinimumStackCommit;213} _PEB, * _PPEB;214215typedef struct216{217WORD offset:12;218WORD type:4;219} IMAGE_RELOC, *PIMAGE_RELOC;220//===============================================================================================//221#endif222//===============================================================================================//223224225