Bitdefender Hypervisor Memory Introspection
lixagent.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _LIX_AGENT_H_
6 #define _LIX_AGENT_H_
7 
8 #include "aghcall.h"
9 #include "agent.h"
10 
11 #define LIX_AGENT_MAX_FUNCTIONS 256
12 
13 #define LIX_AGENT_MAX_NAME_LENGTH 128
14 #define LIX_AGENT_MAX_ARGS_LENGTH 1024
15 
16 
18 
24 
25 typedef INTSTATUS
27  _In_opt_ void *Context
28  );
29 
30 
31 
37 typedef INTSTATUS
39  _In_opt_ void *Context
40  );
41 
46 {
51 
52 
56 typedef enum _LIX_AGENT_TAG
57 {
58  // NOTE: Never change this to anything other than 0
60 
61  // Tags used for agents without threads
65 
66  // Tags used for agents with threads
70 
72 
73 
77 #pragma pack(push)
78 #pragma pack(1)
79 typedef struct _LIX_AGENT_HEADER
80 {
87 #pragma pack(pop)
88 
89 
93 typedef struct _LIX_AGENT_TOKEN
94 {
99 
100 
104 typedef struct _LIX_AGENT_DATA
105 {
108 
112 
114 
115 
119 typedef struct _LIX_AGENT_THREAD
120 {
121  LIX_AGENT_TAG Tag;
122  LIX_AGENT_HYPERCALL HypercallType;
123 
125 
126  struct
127  {
130  } Callback;
131 
132  struct
133  {
136 
139  } Content;
140 
141  void *Context;
142 
144 
145 
149 typedef struct _LIX_AGENT
150 {
152 
153  LIX_AGENT_TAG Tag;
155 
157 
158  LIX_AGENT_HYPERCALL HypercallType;
161 
163 
164  struct
165  {
168  } Callback;
169 
170  struct
171  {
173 
174  BYTE Bytes[16];
176 
177  void *CloakHandle;
178 
180  } Instruction;
181 
183 
184 
189 {
192  char *Name[256];
194 
195 
199 typedef struct _LIX_AGENT_FUNCTINS
200 {
201  struct
202  {
207  } Version;
208 
211 
213 
217 typedef struct _LIX_AGENT_HANDLER
218 {
220  enum _LIX_AGENT_HYPERCALL HypercallType;
221 
222  struct
223  {
225  void *Content;
226  } Args;
227 
228  struct
229  {
230  WORD Length;
231  void *Content;
232  } Code;
233 
234  struct
235  {
238  } Functions;
239 
240  struct
241  {
242  DWORD Count;
244  } Threads;
245 
247 
248 
249 #pragma pack(push)
250 #pragma pack(1)
251 
255 typedef struct _LIX_AGENT_INIT_ARGS
256 {
257  struct
258  {
261  } Allocate;
263 
264 
269 {
270  struct
271  {
274  } Free;
275 
276  struct
277  {
280  } Attr;
282 
283 
288 {
289  struct
290  {
292  } Allocate;
294 
295 
300 {
302 
303  struct
304  {
307  } Allocate;
308 
309  struct
310  {
311  char Root;
313  } FilePath;
314 
315  struct
316  {
319  } Umh;
320 
322 
323 
328 {
331 
332  struct
333  {
336  } Allocate;
337 
338  struct
339  {
340  char Root;
342  } FilePath;
343 
344 
345  struct
346  {
348  } Exec;
349 
350  struct
351  {
354  } Umh;
355 
357 
358 
363 {
364  struct
365  {
367  } Exec;
368 
369  struct
370  {
373  } Umh;
374 
376 #pragma pack(pop)
377 
378 
379 INTSTATUS
381  _In_ LIX_AGENT_TAG Tag,
382  _In_opt_ PFUNC_AgentCallbackHypercall HypercallCallback,
383  _In_opt_ PFUNC_AgentCallbackCompletion CompletionCallback
384  );
385 
386 INTSTATUS
388  _In_ LIX_AGENT_TAG Tag,
389  _In_ DWORD TagEx,
390  _In_ AGENT_TYPE AgentType,
391  _In_opt_ PFUNC_AgentCallbackHypercall HypercallCallback,
392  _In_opt_ PFUNC_AgentCallbackCompletion CompletionCallback,
393  _In_opt_ const char *Name,
394  _In_opt_ BYTE *ContentAddress,
395  _In_ DWORD ContentSize
396  );
397 
398 INTSTATUS
400  void
401  );
402 
403 void
405  void
406  );
407 
408 _Success_(return != agNone)
412  );
413 
414 void
416  void
417  );
418 
419 void
421  _In_ DWORD Agid
422  );
423 
424 DWORD
426  _In_ DWORD Agid
427  );
428 
429 LIX_AGENT_TAG
431  _In_ const char *Name
432  );
433 
434 LIX_AGENT_TAG
436  _In_ const char *Name,
437  _Out_ BOOLEAN *Removed
438  );
439 
440 INTSTATUS
442  _In_ QWORD Rip
443  );
444 
445 INTSTATUS
447  _In_ QWORD Rip
448  );
449 
450 void
452  void
453  );
454 
455 INTSTATUS
457  void
458  );
459 
462  _In_ LIX_AGENT_TAG AgentTag
463  );
464 
467  _In_ LIX_AGENT_TAG AgentTag,
468  _In_ LIX_AGENT_TAG ThreadTag
469  );
470 
471 void
473  _In_ AGENT_EVENT_TYPE Event,
474  _In_ DWORD AgentTag,
475  _In_ DWORD ErrorCode
476  );
477 
478 #endif // !_LIX_AGENT_H_
WORD DataSize
The size (bytes) of the data.
Definition: lixagent.h:82
void IntLixAgentDisablePendingAgents(void)
Disables all pending agents.
Definition: lixagent.c:1844
#define _In_opt_
Definition: intro_sal.h:16
#define _Out_
Definition: intro_sal.h:22
_Bool BOOLEAN
Definition: intro_types.h:58
struct _LIX_AGENT_UNINIT_ARGS * PLIX_AGENT_UNINIT_ARGS
LIX_AGENT_TAG Tag
The internal tag.
Definition: lixagent.h:153
WORD CodeSize
The size (byes) of the code.
Definition: lixagent.h:84
Describes a handlers that contains the data required by the agent.
Definition: lixagent.h:217
QWORD ModuleLength
The module memory allocation size.
Definition: lixagent.h:259
LIX_AGENT_DATA Data
The data used by the agent.
Definition: lixagent.h:124
uint8_t BYTE
Definition: intro_types.h:47
QWORD ModuleAddress
The address of the allocated memory (module).
Definition: lixagent.h:272
QWORD Completion
The token used by completion callback.
Definition: lixagent.h:96
No active/pending agents.
Definition: agent.h:15
struct _LIX_AGENT_TOKEN LIX_AGENT_TOKEN
The tokens used by an agent.
LIX_AGENT_HANDLER * IntLixAgentGetHandlerByTag(LIX_AGENT_TAG AgentTag)
Iterates through all agent handlers and search the entry that has the provided tag.
Definition: lixaghnd.c:408
#define _In_
Definition: intro_sal.h:21
INTSTATUS IntLixAgentHandleVmcall(QWORD Rip)
Handle a VMCALL that was executed inside the guest.
Definition: lixagent.c:1760
_LIX_AGENT_TAG
Tag used to identify an agent with a handler.
Definition: lixagent.h:56
LIX_AGENT_HEADER Header
The header of the agent's data.
Definition: lixagent.h:106
DWORD Count
The number of function names.
Definition: lixagent.h:191
enum _LIX_AGENT_TAG LIX_AGENT_TAG
Tag used to identify an agent with a handler.
uint16_t WORD
Definition: intro_types.h:48
QWORD UhmWaitExec
The value of UMH_WAIT_EXEC of current guest.
Definition: lixagent.h:372
struct _LIX_AGENT_THREAD LIX_AGENT_THREAD
Describes an agent-thread running inside the guest.
DWORD Size
The size (bytes) of the injected agent.
Definition: lixagent.h:111
LIX_AGENT_HYPERCALL HypercallType
The hypercall type used.
Definition: lixagent.h:122
Arguments of the run command-line agent.
Definition: lixagent.h:362
Describes an agent-thread running inside the guest.
Definition: lixagent.h:119
INTSTATUS(* PFUNC_AgentCallbackHypercall)(void *Context)
Hypercall callback prototype.
Definition: lixagent.h:26
#define _Success_(expr)
Definition: intro_sal.h:47
LIST_ENTRY Link
List entry element.
Definition: lixagent.h:151
void IntLixAgentNameRemoveByAgid(DWORD Agid)
Iterates through all agent names and removes the entry that contains the provided ID...
Definition: lixagent.c:285
QWORD UhmWaitProc
The value of UMH_WAIT_PROC of current guest.
Definition: lixagent.h:317
Hypercall using INT3 instruction.
Definition: lixagent.h:49
char Root
The root directory (eg. '/')
Definition: lixagent.h:311
struct _LIX_AGENT_HEADER LIX_AGENT_HEADER
Header with information about running code inside the guest.
LIX_AGENT_TAG IntLixAgentDecProcRef(const char *Name, BOOLEAN *Removed)
Checks if a process is an agent or not, and decrements the ref count of that name.
Definition: lixagent.c:1907
QWORD PerCpuAddress
The address of the allocated memory (per-CPU).
Definition: lixagent.h:273
AGENT_EVENT_TYPE
The state of an agent.
Definition: intro_types.h:2097
DWORD TagEx
The tag provided by the integrator.
Definition: lixagent.h:154
#define IG_MAX_AGENT_NAME_LENGTH
Definition: glueiface.h:1712
QWORD PerCpuLength
The per-CPU memory allocation size.
Definition: lixagent.h:260
Run a custom command.
Definition: lixagent.h:69
Hypercall using VMCALL instruction.
Definition: lixagent.h:48
QWORD Hypercall
The token used by hypercall callback.
Definition: lixagent.h:95
Describe an agent running inside the guest.
Definition: lixagent.h:149
Arguments of the exec agent.
Definition: lixagent.h:327
INTSTATUS(* PFUNC_AgentCallbackCompletion)(void *Context)
Completion callback prototype.
Definition: lixagent.h:38
INTSTATUS IntLixAgentUninit(void)
Uninit the agents state.
Definition: lixagent.c:1997
Arguments of the deploy-file agent.
Definition: lixagent.h:299
QWORD KernelVersion
The current guest kernel version.
Definition: lixagent.h:329
Header with information about running code inside the guest.
Definition: lixagent.h:79
int INTSTATUS
The status data type.
Definition: introstatus.h:24
INTSTATUS IntLixAgentThreadInject(LIX_AGENT_TAG Tag, DWORD TagEx, AGENT_TYPE AgentType, PFUNC_AgentCallbackHypercall HypercallCallback, PFUNC_AgentCallbackCompletion CompletionCallback, const char *Name, BYTE *ContentAddress, DWORD ContentSize)
Schedule an thread-agent injection inside the guest.
Definition: lixagent.c:954
QWORD Length
The memory allocation size to deploy the provided content; to deploy the file, we use chunks...
Definition: lixagent.h:335
struct _LIX_AGENT_CREATE_THREAD_ARGS LIX_AGENT_CREATE_THREAD_ARGS
Arguments of the create-thread agent.
LIX_AGENT_THREAD * Thread
A pointer to a agent-thread, if any.
Definition: lixagent.h:160
Invalid hypercall type.
Definition: lixagent.h:47
QWORD UhmWaitProc
The value of UMH_WAIT_PROC of current guest.
Definition: lixagent.h:371
struct _LIX_AGENT_INIT_ARGS * PLIX_AGENT_INIT_ARGS
struct _LIX_AGENT_THREAD_DEPLOY_FILE_EXEC_ARGS LIX_AGENT_THREAD_DEPLOY_FILE_EXEC_ARGS
Arguments of the exec agent.
struct _LIX_AGENT_HANDLER * Content
An array that contains LIX_AGENT_HANDLER entries.
Definition: lixagent.h:243
INTSTATUS IntLixAgentActivatePendingAgent(void)
Activates a pending agent that waits to be injected.
Definition: lixagent.c:1082
DWORD Count
The number of the functions list.
Definition: lixagent.h:209
LIX_AGENT_FUNCTIONS * Content
An array that contains LIX_AGENT_FUNCTIONS entries.
Definition: lixagent.h:237
struct _LIX_AGENT_THREAD_DEPLOY_FILE_ARGS LIX_AGENT_THREAD_DEPLOY_FILE_ARGS
Arguments of the deploy-file agent.
struct _LIX_AGENT_HANDLER * PLIX_AGENT_HANDLER
struct _LIX_AGENT * PLIX_AGENT
QWORD UhmWaitExec
The value of UMH_WAIT_EXEC of current guest.
Definition: lixagent.h:318
#define _Out_opt_
Definition: intro_sal.h:30
BYTE * Address
A pointer to the content provided by the integrator.
Definition: lixagent.h:134
struct _LIX_AGENT_INIT_ARGS LIX_AGENT_INIT_ARGS
Arguments of the init agent.
BYTE * Code
A buffer that contains the in-guest agent code/data.
Definition: lixagent.h:109
void * CloakHandle
Cloak handle used to hide the detoured instruction.
Definition: lixagent.h:177
struct _LIX_AGENT_THREAD_DEPLOY_FILE_EXEC_ARGS * PLIX_AGENT_THREAD_DEPLOY_FILE_EXEC_ARGS
QWORD Length
The allocation size of the kthread data.
Definition: lixagent.h:291
LIX_AGENT_TAG Tag
The internal tag.
Definition: lixagent.h:121
unsigned long long QWORD
Definition: intro_types.h:53
DWORD Agid
The agent ID.
Definition: lixagent.h:156
enum _LIX_AGENT_HYPERCALL LIX_AGENT_HYPERCALL
Agent hypercall type.
This file contains the private, undocumented hypercalls. They are used only by the loaders and the ag...
struct _LIX_AGENT_HEADER * PLIX_AGENT_HEADER
INTSTATUS IntLixAgentHandleInt3(QWORD Rip)
Called when a INT3 instruction from the current running agent is executed.
Definition: lixagent.c:1573
QWORD MaskSet
The page attributes that must be set.
Definition: lixagent.h:279
void * Context
Unused.
Definition: lixagent.h:141
DWORD IntLixAgentNameGetTagByAgid(DWORD Agid)
Iterates through all agent names and returns the tag of the agent that has the provided agent ID...
Definition: lixagent.c:312
QWORD Context
Context from integrator.
Definition: lixprocess.h:90
Arguments of the uninit agent.
Definition: lixagent.h:268
void IntLixAgentSendEvent(AGENT_EVENT_TYPE Event, DWORD AgentTag, DWORD ErrorCode)
Send an event to the integrator that contains the AGENT_EVENT_TYPE, tag of the agent and the last err...
Definition: lixagent.c:2119
struct _LIX_AGENT_FUNCTIONS_LIST LIX_AGENT_FUNCTIONS_LIST
A list of functions required by agent.
struct _LIX_AGENT_HANDLER LIX_AGENT_HANDLER
Describes a handlers that contains the data required by the agent.
struct _LIX_AGENT LIX_AGENT
Describe an agent running inside the guest.
enum _AGENT_TYPE AGENT_TYPE
struct _LIX_AGENT_THREAD_DEPLOY_FILE_ARGS * PLIX_AGENT_THREAD_DEPLOY_FILE_ARGS
_LIX_AGENT_HYPERCALL
Agent hypercall type.
Definition: lixagent.h:45
QWORD UhmWaitProc
The value of UMH_WAIT_PROC of current guest.
Definition: lixagent.h:352
WORD Length
The size (bytes) of the arguments.
Definition: lixagent.h:224
QWORD Address
The address of the kthread.
Definition: lixagent.h:85
uint32_t DWORD
Definition: intro_types.h:49
Execute a file (process).
Definition: lixagent.h:68
struct _LIX_AGENT_HANDLER::@104 Threads
#define LIX_AGENT_MAX_NAME_LENGTH
Definition: lixagent.h:13
QWORD KernelVersion
The current guest kernel version.
Definition: lixagent.h:301
void IntLixAgentInit(void)
Initialize the agents state.
Definition: lixagent.c:1978
struct _LIX_AGENT_CREATE_THREAD_ARGS * PLIX_AGENT_CREATE_THREAD_ARGS
The tokens used by an agent.
Definition: lixagent.h:93
struct _LIX_AGENT_THREAD_RUN_CLI_ARGS * PLIX_AGENT_THREAD_RUN_CLI_ARGS
INTSTATUS IntLixAgentInject(LIX_AGENT_TAG Tag, PFUNC_AgentCallbackHypercall HypercallCallback, PFUNC_AgentCallbackCompletion CompletionCallback)
Schedule an agent injection inside the guest.
Definition: lixagent.c:896
DWORD CurrentOffset
Used when the HypecallCallback is called as an offset in the content buffer.
Definition: lixagent.h:138
LIX_AGENT_TAG IntLixAgentIncProcRef(const char *Name)
Checks if a process is an agent or not, and increments the ref count of that name.
Definition: lixagent.c:1869
struct _LIX_AGENT_DATA LIX_AGENT_DATA
Describes the data of an agent.
QWORD Address
Address of the detoured instruction.
Definition: lixagent.h:172
char Root
The root directory (eg. '/')
Definition: lixagent.h:340
QWORD MaskClear
The page attributes that must be cleared.
Definition: lixagent.h:278
PFUNC_AgentCallbackCompletion Completion
Completion callback.
Definition: lixagent.h:129
void * Content
The content of the arguments.
Definition: lixagent.h:225
LIX_AGENT_HYPERCALL HypercallType
The hypercall type.
Definition: lixagent.h:158
The functions required by the agent.
Definition: lixagent.h:199
struct _LIX_AGENT_UNINIT_ARGS LIX_AGENT_UNINIT_ARGS
Arguments of the uninit agent.
Arguments of the create-thread agent.
Definition: lixagent.h:287
Describes the data of an agent.
Definition: lixagent.h:104
LIX_AGENT_HANDLER * IntLixAgentThreadGetHandlerByTag(LIX_AGENT_TAG AgentTag, LIX_AGENT_TAG ThreadTag)
Iterates through all thread-agent handlers and search the entry that has the provided tag...
Definition: lixaghnd.c:432
struct _LIX_AGENT_FUNCTIONS_LIST * PLIX_AGENT_FUNCTIONS_LIST
struct _LIX_AGENT_DATA * PLIX_AGENT_DATA
DWORD Count
The number of the functions.
Definition: lixagent.h:236
The create thread agent.
Definition: lixagent.h:64
DWORD Required
The number of required function addresses for the 'Name' array.
Definition: lixagent.h:190
QWORD Error
The token used by error callback.
Definition: lixagent.h:97
A list of functions required by agent.
Definition: lixagent.h:188
QWORD FilePathOffset
The offset of struct file.path.
Definition: lixagent.h:330
The init agent.
Definition: lixagent.h:62
QWORD UhmWaitExec
The value of UMH_WAIT_EXEC of current guest.
Definition: lixagent.h:353
Deploy a file.
Definition: lixagent.h:67
QWORD Address
The guest virtual address of the injected agent.
Definition: lixagent.h:110
AG_WAITSTATE IntLixAgentGetState(DWORD *Tag)
Gets the global agents state.
Definition: lixagent.c:1804
enum _AG_WAITSTATE AG_WAITSTATE
LIX_AGENT_DATA Data
The data used by the agent.
Definition: lixagent.h:159
struct _LIX_AGENT_THREAD_RUN_CLI_ARGS LIX_AGENT_THREAD_RUN_CLI_ARGS
Arguments of the run command-line agent.
struct _LIX_AGENT_FUNCTINS LIX_AGENT_FUNCTIONS
The functions required by the agent.
LIX_AGENT_TOKEN Token
The tokens of the agent.
Definition: lixagent.h:107
PFUNC_AgentCallbackHypercall Hypercall
Hypercall callback.
Definition: lixagent.h:128
char CHAR
Definition: intro_types.h:56
QWORD Length
The memory allocation size to deploy the provided content; to deploy the file, we use chunks...
Definition: lixagent.h:306
BYTE Length
Detoured instruction length.
Definition: lixagent.h:175
PFUNC_AgentCallbackCompletion Completion
Completion callback.
Definition: lixagent.h:167
DWORD Tag
The LIX_AGENT_TAG.
Definition: lixagent.h:81
struct _LIX_AGENT_THREAD * PLIX_AGENT_THREAD
Arguments of the init agent.
Definition: lixagent.h:255
void IntLixAgentEnableInjection(void)
Enables agent injections.
Definition: lixagent.c:1964
PFUNC_AgentCallbackHypercall Hypercall
Hypercall callback.
Definition: lixagent.h:166
struct _LIX_AGENT_FUNCTINS * PLIX_AGENT_FUNCTIONS
The uninit agent.
Definition: lixagent.h:63
DWORD Size
The size of the content provided by the integrator.
Definition: lixagent.h:135
WORD ExitOffset
The offset of the INT3 instruction that represent the exit point.
Definition: lixagent.h:83
#define LIX_AGENT_MAX_ARGS_LENGTH
Definition: lixagent.h:14
BOOLEAN Restored
True if the detours instruction has been restored.
Definition: lixagent.h:179