-
Notifications
You must be signed in to change notification settings - Fork 646
Expand file tree
/
Copy pathvmcheck.py
More file actions
379 lines (327 loc) · 14.9 KB
/
vmcheck.py
File metadata and controls
379 lines (327 loc) · 14.9 KB
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
370
371
372
373
374
375
376
377
378
379
import logging
from typing import List, Dict, Tuple
from collections import defaultdict
from volatility3.framework import interfaces, renderers
from volatility3.framework.configuration import requirements
from volatility3.plugins.windows import pslist, dlllist, registry
vollog = logging.getLogger(__name__)
class SandboxDetect(interfaces.plugins.PluginInterface):
"""Detects sandbox artifacts in Windows memory dumps."""
_required_framework_version = (2, 0, 0)
_version = (1, 0, 0)
# Sandbox indicators
SANDBOX_PROCESSES = {
'vmtoolsd.exe': 'VMware Tools',
'vmwaretray.exe': 'VMware Tray',
'vmwareuser.exe': 'VMware User Process',
'vboxservice.exe': 'VirtualBox Service',
'vboxtray.exe': 'VirtualBox Tray',
'vmsrvc.exe': 'VirtualPC Service',
'vmusrvc.exe': 'VirtualPC User Service',
'prl_cc.exe': 'Parallels Coherence',
'prl_tools.exe': 'Parallels Tools',
'xenservice.exe': 'Xen Service',
'qemu-ga.exe': 'QEMU Guest Agent',
'wireshark.exe': 'Network Analysis Tool',
'procmon.exe': 'Process Monitor',
'procexp.exe': 'Process Explorer',
'ollydbg.exe': 'Debugger',
'x64dbg.exe': 'Debugger',
'idaq.exe': 'IDA Pro Debugger',
'idaq64.exe': 'IDA Pro Debugger',
'windbg.exe': 'Windows Debugger',
'sandboxie.exe': 'Sandboxie',
'cuckoo.exe': 'Cuckoo Sandbox',
'agent.pyw': 'Cuckoo Agent',
'fiddler.exe': 'HTTP Proxy/Debugger',
'regmon.exe': 'Registry Monitor',
'filemon.exe': 'File Monitor',
}
SANDBOX_DLLS = [
'sbiedll.dll', # Sandboxie
'dbghelp.dll', # Debugging
'api_log.dll', # API hooking
'vmGuestLib.dll', # VMware
'vboxmrxnp.dll', # VirtualBox
'VBoxHook.dll', # VirtualBox
'prltools.dll', # Parallels
]
VM_ARTIFACTS = [
'vmware',
'vbox',
'virtualbox',
'qemu',
'xen',
'parallels',
'virtual',
'bochs',
'hyperv',
'kvm',
]
@classmethod
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]:
return [
requirements.ModuleRequirement(
name="kernel",
description="Windows kernel module",
architectures=["Intel32", "Intel64"],
),
requirements.BooleanRequirement(
name="verbose",
description="Show detailed findings",
optional=True,
default=False
),
]
def _check_processes(self, kernel_module_name: str) -> Tuple[int, List[Dict]]:
"""Check for sandbox-related processes."""
detections = []
score = 0
for proc in pslist.PsList.list_processes(self.context, kernel_module_name):
try:
proc_name = proc.ImageFileName.cast(
"string",
max_length=proc.ImageFileName.vol.count,
errors="replace"
).lower()
proc_pid = proc.UniqueProcessId
# Get process path
try:
peb = proc.get_peb()
if peb:
process_params = peb.ProcessParameters
if process_params:
image_path = process_params.ImagePathName.get_string()
proc_path = image_path if image_path else "N/A"
else:
proc_path = "N/A"
else:
proc_path = "N/A"
except Exception:
proc_path = "N/A"
if proc_name in self.SANDBOX_PROCESSES:
score += 10
detections.append({
'type': 'Process',
'indicator': proc_name,
'description': self.SANDBOX_PROCESSES[proc_name],
'severity': 'High',
'info': f'PID: {proc_pid} | Path: {proc_path}'
})
# Check for VM-related keywords in process names
for artifact in self.VM_ARTIFACTS:
if artifact in proc_name and proc_name not in self.SANDBOX_PROCESSES:
score += 5
detections.append({
'type': 'Process',
'indicator': proc_name,
'description': f'VM-related keyword: {artifact}',
'severity': 'Medium',
'info': f'PID: {proc_pid} | Path: {proc_path}'
})
break
except Exception as e:
vollog.debug(f"Error checking process: {e}")
continue
return score, detections
def _check_dlls(self, kernel_module_name: str) -> Tuple[int, List[Dict]]:
"""Check for sandbox-related DLLs."""
detections = []
score = 0
checked_dlls = set()
for proc in pslist.PsList.list_processes(self.context, kernel_module_name):
try:
proc_name = proc.ImageFileName.cast(
"string",
max_length=proc.ImageFileName.vol.count,
errors="replace"
)
for entry in proc.load_order_modules():
try:
dll_name = entry.BaseDllName.get_string().lower()
if dll_name in checked_dlls:
continue
checked_dlls.add(dll_name)
if dll_name in self.SANDBOX_DLLS:
score += 8
detections.append({
'type': 'DLL',
'indicator': dll_name,
'description': 'Sandbox/Analysis DLL',
'severity': 'High',
'process': proc_name
})
# Check for VM-related DLL names
for artifact in self.VM_ARTIFACTS:
if artifact in dll_name and dll_name not in self.SANDBOX_DLLS:
score += 3
detections.append({
'type': 'DLL',
'indicator': dll_name,
'description': f'VM-related DLL: {artifact}',
'severity': 'Low',
'process': proc_name
})
break
except Exception:
continuenue
except Exception as e:
vollog.debug(f"Error checking DLLs: {e}")
continue
return score, detections
def _check_system_info(self, kernel_module_name: str) -> Tuple[int, List[Dict]]:
"""Check system information for sandbox indicators."""
detections = []
score = 0
# Count total processes - sandboxes often have fewer processes
process_count = 0
process_names = []
for proc in pslist.PsList.list_processes(self.context, kernel_module_name):
process_count += 1
try:
proc_name = proc.ImageFileName.cast(
"string",
max_length=proc.ImageFileName.vol.count,
errors="replace"
).lower()
process_names.append(proc_name)
except Exception:
continue
# Check for very low process count
if process_count < 20:
score += 10
detections.append({
'type': 'System',
'indicator': f'Very low process count: {process_count}',
'description': 'Critical: Typical systems run 40+ processes',
'severity': 'High',
'info': 'Minimal process environment detected'
})
elif process_count < 30:
score += 5
detections.append({
'type': 'System',
'indicator': f'Low process count: {process_count}',
'description': 'Sandboxes typically run fewer processes',
'severity': 'Medium',
'info': 'Limited process environment'
})
# Check for missing common Windows processes
common_processes = ['explorer.exe', 'svchost.exe', 'lsass.exe', 'services.exe', 'winlogon.exe']
missing_processes = [p for p in common_processes if p not in process_names]
if len(missing_processes) >= 2:
score += 8
detections.append({
'type': 'System',
'indicator': f'Missing critical processes: {", ".join(missing_processes)}',
'description': 'Essential Windows processes not running',
'severity': 'High',
'info': f'Found processes: {", ".join(process_names[:10])}...'
})
# Check for suspicious timing (all processes started around same time)
# This would require creation time analysis
return score, detections
def _check_drivers(self, kernel_module_name: str) -> Tuple[int, List[Dict]]:
"""Check for VM/sandbox drivers in loaded modules."""
detections = []
score = 0
vm_drivers = [
'vmmouse.sys', 'vmhgfs.sys', 'vmci.sys', 'vboxguest.sys',
'vboxsf.sys', 'vboxvideo.sys', 'prl_fs.sys', 'prl_tg.sys'
]
# This would require kernel module enumeration
# Simplified version checking process loaded modules
checked_modules = set()
for proc in pslist.PsList.list_processes(self.context, kernel_module_name):
try:
proc_name = proc.ImageFileName.cast(
"string",
max_length=proc.ImageFileName.vol.count,
errors="replace"
)
proc_pid = proc.UniqueProcessId
for entry in proc.load_order_modules():
try:
dll_name = entry.BaseDllName.get_string().lower()
dll_path = entry.FullDllName.get_string()
if dll_name in checked_modules:
continue
checked_modules.add(dll_name)
if dll_name in vm_drivers:
score += 15
detections.append({
'type': 'Driver',
'indicator': dll_name,
'description': 'VM/Sandbox driver detected',
'severity': 'Critical',
'info': f'Process: {proc_name} (PID: {proc_pid}) | Path: {dll_path}'
})
except Exception:
continue
except Exception:
continue
return score, detections
def _calculate_verdict(self, total_score: int, detection_count: int) -> Tuple[str, str]:
"""Calculate final verdict based on score and detections."""
if total_score >= 50 or detection_count >= 5:
return "SANDBOX", "High confidence - Multiple sandbox indicators detected"
elif total_score >= 30 or detection_count >= 3:
return "LIKELY SANDBOX", "Medium confidence - Several suspicious indicators"
elif total_score >= 15 or detection_count >= 1:
return "SUSPICIOUS", "Low confidence - Few indicators detected"
else:
return "REAL MACHINE", "No significant sandbox indicators found"
def _generator(self):
kernel_module_name = self.config["kernel"]
verbose = self.config.get("verbose", False)
all_detections = []
total_score = 0
# Run all checks
vollog.info("Checking for sandbox processes...")
proc_score, proc_detections = self._check_processes(kernel_module_name)
all_detections.extend(proc_detections)
total_score += proc_score
vollog.info("Checking for sandbox DLLs...")
dll_score, dll_detections = self._check_dlls(kernel_module_name)
all_detections.extend(dll_detections)
total_score += dll_score
vollog.info("Checking system information...")
sys_score, sys_detections = self._check_system_info(kernel_module_name)
all_detections.extend(sys_detections)
total_score += sys_score
vollog.info("Checking for VM drivers...")
drv_score, drv_detections = self._check_drivers(kernel_module_name)
all_detections.extend(drv_detections)
total_score += drv_score
# Calculate verdict
verdict, confidence = self._calculate_verdict(total_score, len(all_detections))
# Yield summary
yield (0, (
"SUMMARY",
verdict,
f"Score: {total_score} | Detections: {len(all_detections)}",
confidence,
""
))
yield (0, ("", "", "", "", ""))
# Yield detailed detections if verbose or if detections found
if verbose or all_detections:
for detection in all_detections:
yield (0, (
detection.get('type', 'N/A'),
detection.get('indicator', 'N/A'),
detection.get('description', 'N/A'),
detection.get('severity', 'N/A'),
detection.get('info', 'N/A')
))
def run(self):
return renderers.TreeGrid(
[
("Detection Type", str),
("Indicator", str),
("Description", str),
("Severity", str),
("Additional Info", str)
],
self._generator(),
)