Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
inject.h
Go to the documentation of this file.
1#pragma once
2typedef unsigned long DWORD;
3typedef int BOOL;
4typedef unsigned char BYTE;
5typedef unsigned short WORD;
6
7#define TAG 'inje'
8#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
9#define IMAGE_DIRECTORY_ENTRY_EXPORT 0
10
12 struct _LIST_ENTRY InLoadOrderLinks; //0x0
13 struct _LIST_ENTRY InMemoryOrderLinks; //0x10
14 union
15 {
16 struct _LIST_ENTRY InInitializationOrderLinks; //0x20
17 struct _LIST_ENTRY InProgressLinks; //0x20
18 };
19 VOID* DllBase; //0x30
20 VOID* EntryPoint; //0x38
21 ULONG SizeOfImage; //0x40
22 struct _UNICODE_STRING FullDllName; //0x48
23 struct _UNICODE_STRING BaseDllName; //0x58
24 union
25 {
26 UCHAR FlagGroup[4]; //0x68
27 ULONG Flags; //0x68
28 struct
29 {
30 ULONG PackagedBinary : 1; //0x68
31 ULONG MarkedForRemoval : 1; //0x68
32 ULONG ImageDll : 1; //0x68
33 ULONG LoadNotificationsSent : 1; //0x68
34 ULONG TelemetryEntryProcessed : 1; //0x68
35 ULONG ProcessStaticImport : 1; //0x68
36 ULONG InLegacyLists : 1; //0x68
37 ULONG InIndexes : 1; //0x68
38 ULONG ShimDll : 1; //0x68
39 ULONG InExceptionTable : 1; //0x68
40 ULONG ReservedFlags1 : 2; //0x68
41 ULONG LoadInProgress : 1; //0x68
42 ULONG ReservedFlags2 : 1; //0x68
43 ULONG EntryProcessed : 1; //0x68
44 ULONG ReservedFlags3 : 3; //0x68
45 ULONG DontCallForThreads : 1; //0x68
46 ULONG ProcessAttachCalled : 1; //0x68
47 ULONG ProcessAttachFailed : 1; //0x68
48 ULONG CorDeferredValidate : 1; //0x68
49 ULONG CorImage : 1; //0x68
50 ULONG DontRelocate : 1; //0x68
51 ULONG CorILOnly : 1; //0x68
52 ULONG ReservedFlags5 : 3; //0x68
53 ULONG Redirected : 1; //0x68
54 ULONG ReservedFlags6 : 2; //0x68
55 ULONG CompatDatabaseProcessed : 1; //0x68
56 }A;
57 };
58 USHORT ObsoleteLoadCount; //0x6c
59 USHORT TlsIndex; //0x6e
60 struct _LIST_ENTRY HashLinks; //0x70
61 ULONG TimeDateStamp; //0x80
62 struct _ACTIVATION_CONTEXT* EntryPointActivationContext; //0x88
63 VOID* PatchInformation; //0x90
64 struct _LDR_DDAG_NODE* DdagNode; //0x98
65 struct _LIST_ENTRY NodeModuleLink; //0xa0
66 struct _LDRP_DLL_SNAP_CONTEXT* SnapContext; //0xb0
67 VOID* ParentDllBase; //0xb8
68 VOID* SwitchBackContext; //0xc0
69 struct _RTL_BALANCED_NODE BaseAddressIndexNode; //0xc8
70 struct _RTL_BALANCED_NODE MappingInfoIndexNode; //0xe0
71 ULONGLONG OriginalBase; //0xf8
72 union _LARGE_INTEGER LoadTime; //0x100
73 ULONG BaseNameHashValue; //0x108
74 enum _LDR_DLL_LOAD_REASON LoadReason; //0x10c
75};
76
85
107
130
140
145
178
184
198
199extern EX_RUNDOWN_REF PendingOperations;
200
207
208typedef VOID(NTAPI* PKNORMAL_ROUTINE)(
209 _In_ PVOID NormalContext,
210 _In_ PVOID SystemArgument1,
211 _In_ PVOID SystemArgument2
212 );
213
214typedef VOID KKERNEL_ROUTINE(
215 _In_ PRKAPC Apc,
216 _Inout_opt_ PKNORMAL_ROUTINE* NormalRoutine,
217 _Inout_opt_ PVOID* NormalContext,
218 _Inout_ PVOID* SystemArgument1,
219 _Inout_ PVOID* SystemArgument2
220);
221
222// Define a structure to pass data to the APC routine
223typedef struct _APC_DATA {
224 PVOID Buffer;
225 SIZE_T Size;
227
228typedef KKERNEL_ROUTINE(NTAPI* PKKERNEL_ROUTINE);
229
230typedef VOID(NTAPI* PKRUNDOWN_ROUTINE)(_In_ PRKAPC Apc);
231
232extern "C" VOID NTAPI KeInitializeApc(
233 _Out_ PRKAPC Apc,
234 _In_ PRKTHREAD Thread,
235 _In_ KAPC_ENVIRONMENT Environment,
236 _In_ PKKERNEL_ROUTINE KernelRoutine,
237 _In_opt_ PKRUNDOWN_ROUTINE RundownRoutine,
238 _In_opt_ PKNORMAL_ROUTINE NormalRoutine,
239 _In_opt_ KPROCESSOR_MODE ProcessorMode,
240 _In_opt_ PVOID NormalContext
241);
242
243extern "C" BOOLEAN NTAPI KeInsertQueueApc(
244 _Inout_ PRKAPC Apc,
245 _In_opt_ PVOID SystemArgument1,
246 _In_opt_ PVOID SystemArgument2,
247 _In_ KPRIORITY Increment
248);
249
250
251
252bool InjectDLL(HANDLE ProcessId, PVOID processInfo);
253NTSTATUS AllocateMemoryInUserProcess(PEPROCESS Process, SIZE_T Size, PVOID* AllocatedAddress);
254NTSTATUS WriteToTargetProcessMemory(PEPROCESS Process, PVOID TargetAddress, SIZE_T Size, PVOID DataToWrite);
void NTAPI KernelRoutine(PKAPC apc, PKNORMAL_ROUTINE *NormalRoutine, PVOID *NormalContext, PVOID *SystemArgument1, PVOID *SystemArgument2)
int BOOL
Definition inject.h:3
struct _IMAGE_OPTIONAL_HEADER64 * PIMAGE_OPTIONAL_HEADER64
unsigned short WORD
Definition inject.h:5
VOID(NTAPI * PKNORMAL_ROUTINE)(_In_ PVOID NormalContext, _In_ PVOID SystemArgument1, _In_ PVOID SystemArgument2)
Definition inject.h:208
struct _IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER64
VOID KKERNEL_ROUTINE(_In_ PRKAPC Apc, _Inout_opt_ PKNORMAL_ROUTINE *NormalRoutine, _Inout_opt_ PVOID *NormalContext, _Inout_ PVOID *SystemArgument1, _Inout_ PVOID *SystemArgument2)
Definition inject.h:214
struct _IMAGE_DATA_DIRECTORY IMAGE_DATA_DIRECTORY
VOID(NTAPI * PKRUNDOWN_ROUTINE)(_In_ PRKAPC Apc)
Definition inject.h:230
enum _KAPC_ENVIRONMENT * PKAPC_ENVIRONMENT
NTSTATUS WriteToTargetProcessMemory(PEPROCESS Process, PVOID TargetAddress, SIZE_T Size, PVOID DataToWrite)
Definition inject.cpp:11
unsigned char BYTE
Definition inject.h:4
NTSTATUS AllocateMemoryInUserProcess(PEPROCESS Process, SIZE_T Size, PVOID *AllocatedAddress)
Definition inject.cpp:69
struct _IMAGE_FILE_HEADER IMAGE_FILE_HEADER
BOOLEAN NTAPI KeInsertQueueApc(_Inout_ PRKAPC Apc, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2, _In_ KPRIORITY Increment)
struct _PEB_LDR_DATA * PPEB_LDR_DATA
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES
Definition inject.h:8
struct _PEB * PPEB
struct _APC_DATA * PAPC_DATA
bool InjectDLL(HANDLE ProcessId, PVOID processInfo)
struct _IMAGE_NT_HEADERS64 * PIMAGE_NT_HEADERS64
_KAPC_ENVIRONMENT
Definition inject.h:201
@ AttachedApcEnvironment
Definition inject.h:203
@ OriginalApcEnvironment
Definition inject.h:202
@ CurrentApcEnvironment
Definition inject.h:204
@ InsertApcEnvironment
Definition inject.h:205
struct _IMAGE_EXPORT_DIRECTORY * PIMAGE_EXPORT_DIRECTORY
struct _IMAGE_DOS_HEADER IMAGE_DOS_HEADER
struct _IMAGE_DATA_DIRECTORY * PIMAGE_DATA_DIRECTORY
struct _IMAGE_EXPORT_DIRECTORY IMAGE_EXPORT_DIRECTORY
struct _IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS64
EX_RUNDOWN_REF PendingOperations
unsigned long DWORD
Definition inject.h:2
VOID NTAPI KeInitializeApc(_Out_ PRKAPC Apc, _In_ PRKTHREAD Thread, _In_ KAPC_ENVIRONMENT Environment, _In_ PKKERNEL_ROUTINE KernelRoutine, _In_opt_ PKRUNDOWN_ROUTINE RundownRoutine, _In_opt_ PKNORMAL_ROUTINE NormalRoutine, _In_opt_ KPROCESSOR_MODE ProcessorMode, _In_opt_ PVOID NormalContext)
struct _IMAGE_DOS_HEADER * PIMAGE_DOS_HEADER
struct _APC_DATA APC_DATA
struct _PEB PEB
struct _PEB_LDR_DATA PEB_LDR_DATA
struct _IMAGE_FILE_HEADER * PIMAGE_FILE_HEADER
enum _KAPC_ENVIRONMENT KAPC_ENVIRONMENT
Definition inject.h:11
struct _UNICODE_STRING FullDllName
Definition inject.h:22
enum _LDR_DLL_LOAD_REASON LoadReason
Definition inject.h:74
ULONG LoadInProgress
Definition inject.h:41
struct _LDRP_DLL_SNAP_CONTEXT * SnapContext
Definition inject.h:66
ULONG DontCallForThreads
Definition inject.h:45
VOID * ParentDllBase
Definition inject.h:67
ULONG ReservedFlags6
Definition inject.h:54
USHORT TlsIndex
Definition inject.h:59
ULONG ShimDll
Definition inject.h:38
ULONG ProcessAttachCalled
Definition inject.h:46
VOID * EntryPoint
Definition inject.h:20
ULONG Flags
Definition inject.h:27
struct _LIST_ENTRY NodeModuleLink
Definition inject.h:65
UCHAR FlagGroup[4]
Definition inject.h:26
ULONG EntryProcessed
Definition inject.h:43
VOID * PatchInformation
Definition inject.h:63
struct _LDR_DDAG_NODE * DdagNode
Definition inject.h:64
struct LDR_DATA_TABLE_ENTRY::@2::@4 A
struct _ACTIVATION_CONTEXT * EntryPointActivationContext
Definition inject.h:62
ULONG CorDeferredValidate
Definition inject.h:48
struct _LIST_ENTRY InMemoryOrderLinks
Definition inject.h:13
ULONG ReservedFlags5
Definition inject.h:52
ULONG CorILOnly
Definition inject.h:51
struct _LIST_ENTRY InProgressLinks
Definition inject.h:17
union _LARGE_INTEGER LoadTime
Definition inject.h:72
struct _LIST_ENTRY InInitializationOrderLinks
Definition inject.h:16
struct _UNICODE_STRING BaseDllName
Definition inject.h:23
ULONG LoadNotificationsSent
Definition inject.h:33
ULONG Redirected
Definition inject.h:53
ULONG DontRelocate
Definition inject.h:50
ULONG TelemetryEntryProcessed
Definition inject.h:34
VOID * DllBase
Definition inject.h:19
struct _RTL_BALANCED_NODE BaseAddressIndexNode
Definition inject.h:69
struct _LIST_ENTRY HashLinks
Definition inject.h:60
ULONG InExceptionTable
Definition inject.h:39
ULONG CorImage
Definition inject.h:49
ULONG CompatDatabaseProcessed
Definition inject.h:55
ULONGLONG OriginalBase
Definition inject.h:71
ULONG BaseNameHashValue
Definition inject.h:73
ULONG PackagedBinary
Definition inject.h:30
ULONG InLegacyLists
Definition inject.h:36
ULONG MarkedForRemoval
Definition inject.h:31
ULONG ReservedFlags3
Definition inject.h:44
struct _RTL_BALANCED_NODE MappingInfoIndexNode
Definition inject.h:70
ULONG SizeOfImage
Definition inject.h:21
ULONG ReservedFlags1
Definition inject.h:40
VOID * SwitchBackContext
Definition inject.h:68
struct _LIST_ENTRY InLoadOrderLinks
Definition inject.h:12
ULONG ImageDll
Definition inject.h:32
ULONG InIndexes
Definition inject.h:37
ULONG ReservedFlags2
Definition inject.h:42
ULONG ProcessAttachFailed
Definition inject.h:47
ULONG ProcessStaticImport
Definition inject.h:35
ULONG TimeDateStamp
Definition inject.h:61
USHORT ObsoleteLoadCount
Definition inject.h:58
SIZE_T Size
Definition inject.h:225
PVOID Buffer
Definition inject.h:224
WORD e_res[4]
Definition inject.h:124
WORD e_res2[10]
Definition inject.h:127
DWORD NumberOfSymbols
Definition inject.h:136
DWORD PointerToSymbolTable
Definition inject.h:135
WORD SizeOfOptionalHeader
Definition inject.h:137
WORD NumberOfSections
Definition inject.h:133
DWORD TimeDateStamp
Definition inject.h:134
IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition inject.h:182
IMAGE_FILE_HEADER FileHeader
Definition inject.h:181
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]
Definition inject.h:176
ULONGLONG SizeOfStackReserve
Definition inject.h:170
ULONGLONG SizeOfHeapCommit
Definition inject.h:173
ULONGLONG SizeOfStackCommit
Definition inject.h:171
ULONGLONG SizeOfHeapReserve
Definition inject.h:172
LIST_ENTRY InInitializationOrderModuleList
Definition inject.h:83
LIST_ENTRY InMemoryOrderModuleList
Definition inject.h:82
PVOID SsHandle
Definition inject.h:80
ULONG Length
Definition inject.h:78
LIST_ENTRY InLoadOrderModuleList
Definition inject.h:81
BOOLEAN Initialized
Definition inject.h:79
Definition inject.h:86
ULONG Reserved8
Definition inject.h:98
ULONG Reserved6
Definition inject.h:96
PPEB_LDR_DATA Ldr
Definition inject.h:91
BYTE Reserved11[128]
Definition inject.h:103
PVOID PostProcessInitRoutine
Definition inject.h:102
BYTE Reserved2[1]
Definition inject.h:89
BYTE BeingDebugged
Definition inject.h:88
ULONG SessionId
Definition inject.h:105
PVOID AtlThunkSListPtr
Definition inject.h:94
PVOID Reserved5
Definition inject.h:95
PVOID Reserved3[2]
Definition inject.h:90
PVOID ProcessParameters
Definition inject.h:92
PVOID Reserved9[45]
Definition inject.h:100
BYTE Reserved10[96]
Definition inject.h:101
ULONG AtlThunkSListPtr32
Definition inject.h:99
PVOID Reserved7
Definition inject.h:97
PVOID Reserved12[1]
Definition inject.h:104
PVOID Reserved4[3]
Definition inject.h:93
BYTE Reserved1[2]
Definition inject.h:87