Evasions: Generic OS queries
Contents
Generic OS queries
1. Check if the username is specific
2. Check if the computer name is specific
3. Check if the host name is specific
4. Check if the total RAM is low
5. Check if the screen resolution is non-usual for host OS
6. Check if the number of processors is low
7. Check if the quantity of monitors is small
8. Check if the hard disk drive size and free space are small
9. Check if the system uptime is small
10. Check if the OS was boot from virtual hard disk (Win8+)
Countermeasures
Credits
Signature recommendations are general
Signature recommendations are general for each technique: hook the function used and track if it is called. It’s pretty hard to tell why application wants to get user name, for example. It doesn’t necessarily mean applying evasion technique. So the best what can be done in this situation is intercepting target functions and tracking their calls.
Detection via generic OS checks
Usual hosts have meaningful and non-standard usernames/computer names. Particular virtual environments assign some predefined names to default users as well as computer names. Other differences between host OS and VMs include RAM size, HDD size, quantity of monitors - and so on. While these may be not the most reliable ways to detect virtual environments, they are still commonly used in malware samples.
1. Check if the username is specific
Please note that checks are not case-sensitive.
Function used:
- GetUserNameA/W
Code sample
Code sample is taken from InviZzzible tool
Countermeasures
Change user name to non-suspicious one.
Detections table
Check if username is one of the following: | |
Detect | String |
---|---|
[general] | admin |
andy | |
honey | |
john | |
john doe | |
malnetvm | |
maltest | |
malware | |
roo | |
sandbox | |
snort | |
tequilaboomboom | |
test | |
virus | |
virusclone | |
wilbert | |
Nepenthes | nepenthes |
Norman | currentuser |
ThreatExpert | username |
Sandboxie | user |
VMware | vmware |
2. Check if the computer name is specific
Please note that checks are not case-sensitive.
Function used:
- GetComputerNameA/W
Code sample
Code sample is taken from InviZzzible tool
Countermeasures
Change computer name to non-suspicious one.
Detections table
Check if computer name is one of the following: | |
Detect | String |
---|---|
[generic] | klone_x64-pc |
tequilaboomboom | |
Anubis | TU-4NH09SMCG1HC |
InsideTm |
3. Check if the host name is specific
Please note that checks are not case-sensitive.
Function used:
- GetComputerNameExA/W
Code sample
Code sample is taken from InviZzzible tool
Countermeasures
Change host name to non-suspicious one.
Detections table
Check if host name is one of the following: | |
Detect | String |
---|---|
[generic] | SystemIT |
4. Check if the total RAM is low
Functions used to get executable path:
- GetMemoryStatusEx
Code sample
Credits for this code sample: al-khaser project
Countermeasures
Patch/hook NtQuerySystemInformation to return new number of PhysicalPages in SystemBasicInformation.
Tip: in this case its 1st argument is equal to 2 - SystemPerformanceInformation enum value.
Alternatively, patch NumberOfPhysicalPages in KUSER_SHARED_DATA.
5. Check if the screen resolution is non-usual for host OS
The following set of functions is used:
- GetDesktopWindow
- GetWindowRect
Alternatively:
- GetSystemMetrics
- SystemParametersInfo
- GetMonitorInfo
Code sample
Take a look at this StackOverflow thread.
Countermeasures
Change screen resolution for it to match the resolution of usual host (1600x900, for example).
6. Check if the number of processors is low
Function used:
- GetSystemInfo
Besides this function numbers of processors can be obtained from PEB, via either asm inline or intrinsic function, see code samples below. It can be also obtained (ActiveProcessorCount flag) from the KUSER_SHARED_DATA structure.
Code sample (variant 1, al-khaser project)
Credits for this code sample: al-khaser project
Code sample (variant 2, al-khaser project, asm inline)
Credits for this code sample: al-khaser project
Code sample (variant 3, pafish project)
Credits for this code sample: pafish project
Code sample (variant 4)
Countermeasures
Assign two or more cores for Virtual Machine.
As an alternative solution, patch/hook NtCreateThread to assign specific core for each new thread.
7. Check if the quantity of monitors is small
Functions used:
- EnumDisplayMonitors
- GetSystemMetrics (SM_MONITOR)
Code sample
Credits for this code sample: StackOverflow forum
Countermeasures
Add at least one monitor to virtual environment.
8. Check if the hard disk drive size and free space are small
Functions used:
- DeviceIoControl(..., IOCTL_DISK_GET_LENGTH_INFO, ...)
- GetDiskFreeSpaceExA/W
Code sample (checking drive total size)
Credits for this code sample: al-khaser project
Code sample (checking drive free space)
Credits for this code sample: al-khaser project
Countermeasures
Against checking disk size: filter IRP device control requests to \\Device\\HarddiskN with specific CTL-codes:
- DRIVE_GEOMETRY_EX
- DRIVE_LAYOUT_EX
- PARTITION_INFO_EX
Against checking free space: patch/hook NtQueryVolumeInformationFile to process these classes:
- FileFsSizeInformation
- FileFsFullSizeInformation
in case if handle points to \\Device\\HarddiskVolumeN.
9. Check if the system uptime is small
Function used:
- GetTickCount
- GetTickCount64
- NtQuerySystemInformation
Code sample
Code sample is taken from InviZzzible tool
Code sample
Code sample
Countermeasures
- Adjust KeBootTime value
- Adjust SharedUserData->TickCount, SharedUserData->TickCoundLowDeprecated values
10. Check if the OS was boot from virtual hard disk (Win8+)
Function used:
- IsNativeVhdBoot // false on host OS, true within VM
Code sample (excerpt from malware)
Take a look at the excerpt from malware here.
Code sample (pafish project)
Credits for this code sample: pafish project
Countermeasures
Hook IsNativeVhdBoot and change its result to the one required.
Countermeasures
Countermeasures are present in appropriate sub-sections, see above.
Credits
Credits go to open-source projects from where code samples were taken:
Though Check Point tool InviZzzible has them all implemented, due to modular structure of the code it would require more space to show a code sample from this tool for the same purposes. That’s why we’ve decided to use other great open-source projects for examples throughout the encyclopedia.