-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathexobj.py
371 lines (306 loc) · 12.1 KB
/
exobj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#
# Copyright (c) 2020 Bitdefender
# SPDX-License-Identifier: Apache-2.0
#
import json
from enum import Enum, auto
class SignatureJson:
def __init__(self):
self.Type = None
self.Signatures = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class ExceptionJson:
def __init__(self):
self.Type = None
self.Exceptions = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class ExportHash:
def __init__(self, n, d):
self.name = n
self.delta = d
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class ExportSignature:
def __init__(self):
self.sig_id = None
self.sig_type = "export"
self.flags = None
self.library = None
self.hashes = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class IdtSignature:
def __init__(self):
self.sig_id = None
self.sig_type = "idt"
self.flags = None
self.entry = None
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class CodeBlocksSignature:
def __init__(self):
self.sig_type = "codeblocks"
self.sig_id = None
self.flags = None
self.score = None
self.hashes = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class DpiSignature:
def __init__(self):
self.sig_type = "process-creation"
self.sig_id = None
self.flags = None
self.create_mask = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class UserModeException:
def __init__(self):
self.process = None
self.originator = None
self.victim = None
self.flags = None
self.object_type = None
self.signature = list()
def __repr__(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class KernelModeException:
def __init__(self):
self.originator = None
self.victim = None
self.object_type = None
self.flags = None
self.signature = list()
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
class KernelUserModeException:
def __init__(self):
self.process = None
self.originator = None
self.victim = None
self.object_type = None
self.flags = None
self.signature = list()
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=4)
EPT_HOOK_NONE = 0
EPT_HOOK_READ = 1
EPT_HOOK_WRITE = 2
EPT_HOOK_EXECUTE = 4
class ProcessCreationFlagsEnum(Enum):
processCreationDebug = 0x00000001,
processCreationPivotedStack = 0x00000002,
processCreationStolenToken = 0x00000004,
processCreationHeapSpray = 0x00000008,
processCreationSecDesc = 0x00000040,
processCreationAclEdit = 0x00000080
class IntroEventEnum(Enum):
introEventEptViolation = 1
introEventMsrViolation = 2
introEventCrViolation = 3
introEventIntegrityViolation = 5
introEventInjectionViolation = 7
introEventDtrViolation = 8
introEventProcessCreationViolation = 16
introEventModuleLoadViolation = 17
class KmObjectType(Enum):
kmObjNone = 0
kmObjAny = auto()
kmObjDriver = auto()
kmObjDriverImports = auto()
kmObjDriverCode = auto()
kmObjDriverData = auto()
kmObjDriverResource = auto()
kmObjSsdt = auto()
kmObjDrvObj = auto()
kmObjFastIo = auto()
kmObjMsr = auto()
kmObjCr4 = auto()
kmObjHalHeap = auto()
kmObjSelfMapEntry = auto()
kmObjIdt = auto()
kmObjIdtr = auto()
kmObjGdtr = auto()
kmObjLoggerCtx = auto()
kmObjDriverExports = auto()
kmObjSecDesc = auto()
kmObjAclEdit = auto()
class UmObjectType(Enum):
umObjNone = 0
umObjAny = auto()
umObjProcess = auto()
umObjModule = auto()
umObjModuleImports = auto()
umObjNxZone = auto()
umObjModuleExports = auto()
umObjProcessThreadContext = auto()
umObjProcessPeb32 = auto()
umObjProcessPeb64 = auto()
umObjProcessApcThread = auto()
umObjProcessCreation = auto()
umObjModuleLoad = auto()
umObjProcessCreationDpi = auto()
class KmUmObjectType(Enum):
kmUmObjNone = 0
kmUmObjAny = auto()
kmUmObjModule = auto()
kmUmObjModuleImports = auto()
kmUmObjModuleExports = auto()
class UmExcNameEnum(Enum):
umExcNameAny = 0
umExcNameOwn = auto()
umExcNameVdso = auto()
umExcNameVsyscall = auto()
umExcNameNone = auto()
class KmExecNameEnum(Enum):
kmExcNameAny = 0
kmExcNameOwn = auto()
kmExcNameKernel = auto()
kmExcNameHal = auto()
kmExcNameNone = auto()
kmExcNameVdso = auto()
kmExcNameVsyscall = auto()
kmExcNameVeAgent = auto()
class ExecFlagEnum(Enum):
execFlagFeedback = 0x00000001,
execFlag32 = 0x00000002,
execFlag64 = 0x00000004,
execFlagInit = 0x00000008,
execFlagReturn = 0x00000010,
execFlagLinux = 0x00000080,
execFlagRead = 0x10000000,
execFlagWrite = 0x20000000,
execFlagExecute = 0x40000000,
execFlagIgnore = 0x80000000,
execKmFlagNonDriver = 0x00000100,
execKmFlagReturnDrv = 0x00000200,
execKmFlagSmap = 0x00000400,
execKmFlagSmep = 0x00000800,
execKmFlagIntegrity = 0x00001000,
execUmFlagSysProc = 0x00000100,
execUmFlagChildProc = 0x00000200,
execUmFlagOnetime = 0x10000800,
execUmFlagLikeApphelp = 0x10001000,
execUmFlagModuleLoad = 0x00004000,
class GuestTypeEnum(Enum):
guestTypeUnknown = 0
guestTypeWindows = 1
guestTypeLinux = 2
um_obj_type = {
UmObjectType.umObjNone : "none",
UmObjectType.umObjAny : "any",
UmObjectType.umObjProcess : "process",
UmObjectType.umObjModule : "module",
UmObjectType.umObjModuleImports : "module imports",
UmObjectType.umObjNxZone : "nx_zone",
UmObjectType.umObjModuleExports : "module exports",
UmObjectType.umObjProcessThreadContext : "thread-context",
UmObjectType.umObjProcessPeb32 : "peb32",
UmObjectType.umObjProcessPeb64 : "peb64",
UmObjectType.umObjProcessApcThread : "apc-thread",
UmObjectType.umObjProcessCreation : "process-creation",
UmObjectType.umObjModuleLoad : "double-agent",
UmObjectType.umObjProcessCreationDpi : "process-creation-dpi",
}
km_um_obj_type = {
KmUmObjectType.kmUmObjNone : "none",
KmUmObjectType.kmUmObjAny : "any",
KmUmObjectType.kmUmObjModule : "module",
KmUmObjectType.kmUmObjModuleImports : "module imports",
KmUmObjectType.kmUmObjModuleExports : "module exports",
}
km_obj_type = {
KmObjectType.kmObjNone : "none",
KmObjectType.kmObjAny : "any",
KmObjectType.kmObjDriver : "driver",
KmObjectType.kmObjDriverImports : "driver imports",
KmObjectType.kmObjDriverCode : "driver code",
KmObjectType.kmObjDriverData : "driver data",
KmObjectType.kmObjDriverResource : "driver resources",
KmObjectType.kmObjSsdt : "ssdt",
KmObjectType.kmObjDrvObj : "drvobj",
KmObjectType.kmObjFastIo : "fastio",
KmObjectType.kmObjMsr : "msr",
KmObjectType.kmObjCr4 : "cr4",
KmObjectType.kmObjHalHeap : "hal-heap",
KmObjectType.kmObjSelfMapEntry : "self-map",
KmObjectType.kmObjIdt : "idt",
KmObjectType.kmObjIdtr : "idt-reg",
KmObjectType.kmObjGdtr : "gdt-reg",
KmObjectType.kmObjLoggerCtx : "infinity-hook",
KmObjectType.kmObjDriverExports : "driver exports",
KmObjectType.kmObjSecDesc : "security-descriptor",
KmObjectType.kmObjAclEdit : "acl-edit"
}
um_exc_name = {
UmExcNameEnum.umExcNameAny : "*",
UmExcNameEnum.umExcNameOwn : "[own]",
UmExcNameEnum.umExcNameVdso : "[vdso]",
UmExcNameEnum.umExcNameVsyscall : "[vsyscall]",
UmExcNameEnum.umExcNameNone : "-"
}
km_exec_name = {
KmExecNameEnum.kmExcNameAny : "*",
KmExecNameEnum.kmExcNameOwn : "[own]",
KmExecNameEnum.kmExcNameKernel : "[kernel]",
KmExecNameEnum.kmExcNameHal : "[hal]",
KmExecNameEnum.kmExcNameNone : "-",
KmExecNameEnum.kmExcNameVdso : "[vdso]",
KmExecNameEnum.kmExcNameVsyscall : "[vsyscall]",
KmExecNameEnum.kmExcNameVeAgent : "",
}
exec_flags = {
ExecFlagEnum.execFlagFeedback : "feedback",
ExecFlagEnum.execFlag32 : "32",
ExecFlagEnum.execFlag64 : "64",
ExecFlagEnum.execFlagInit : "init",
ExecFlagEnum.execFlagReturn : "return",
ExecFlagEnum.execFlagLinux : "linux",
ExecFlagEnum.execFlagRead : "read",
ExecFlagEnum.execFlagWrite : "write",
ExecFlagEnum.execFlagExecute : "exec",
ExecFlagEnum.execFlagIgnore : "ignore",
ExecFlagEnum.execKmFlagNonDriver : "non-driver",
ExecFlagEnum.execKmFlagReturnDrv : "return-drv",
ExecFlagEnum.execKmFlagSmap : "smap",
ExecFlagEnum.execKmFlagSmep : "smep",
ExecFlagEnum.execKmFlagIntegrity : "integrity",
ExecFlagEnum.execUmFlagSysProc : "system-process",
ExecFlagEnum.execUmFlagChildProc : "child",
ExecFlagEnum.execUmFlagOnetime : "one-time",
ExecFlagEnum.execUmFlagLikeApphelp : "like-apphelp",
ExecFlagEnum.execUmFlagModuleLoad : "module-load",
}
um_process_creation_flags = {
ProcessCreationFlagsEnum.processCreationDebug : "debug",
ProcessCreationFlagsEnum.processCreationPivotedStack : "pivoted-stack",
ProcessCreationFlagsEnum.processCreationStolenToken : "stolen-token",
ProcessCreationFlagsEnum.processCreationHeapSpray : "heap-spray",
ProcessCreationFlagsEnum.processCreationSecDesc : "security-descriptor",
ProcessCreationFlagsEnum.processCreationAclEdit : "acl-edit"
}
ZONE_LIB_IMPORTS = 0x000000001
ZONE_LIB_EXPORTS = 0x000000002
ZONE_LIB_CODE = 0x000000004
ZONE_LIB_DATA = 0x000000008
ZONE_LIB_RESOURCES = 0x000000010
ZONE_PROC_THREAD_CTX = 0x000000020
ZONE_PROC_THREAD_APC = 0x000000040
ZONE_DEP_EXECUTION = 0x000000080
ZONE_MODULE_LOAD = 0x000000100
ZONE_WRITE = 0x010000000
ZONE_READ = 0x020000000
ZONE_EXECUTE = 0x040000000
ZONE_INTEGRITY = 0x100000000