Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anti-VM: in instruction (VMWare) #228

Open
recvfrom opened this issue Mar 5, 2021 · 2 comments
Open

Anti-VM: in instruction (VMWare) #228

recvfrom opened this issue Mar 5, 2021 · 2 comments

Comments

@recvfrom
Copy link
Contributor

recvfrom commented Mar 5, 2021

@gsuberland
Copy link
Collaborator

Can you please try this on a VMWare VM and confirm that it works? The x86 IN instruction is privileged, so either VMWare overrides the IOPL check to allow its use from unprivileged ring3 code, or this check only works when performed from a kernel driver. I suspect from the source code you linked that it may well be performing the override, but I'd like to see it confirmed before including an implementation here.

@recvfrom
Copy link
Contributor Author

recvfrom commented Mar 6, 2021

@gsuberland I confirmed that this works, using isVMWare from the github link above and VMWare Fusion 12.1.0:

#include <iostream>
#include <windows.h>

bool IsVMWare()
{
	bool res = true;

	__try {
		__asm
		{
			push   edx
			push   ecx
			push   ebx

			mov    eax, 'VMXh'
			mov    ebx, 0      // any value but not the MAGIC VALUE
			mov    ecx, 10     // get VMWare version
			mov    edx, 'VX'   // port number

			in     eax, dx     // read port
						 // on return EAX returns the VERSION
			cmp    ebx, 'VMXh' // is it a reply from VMWare?
			setz[res]       // set return value

			pop    ebx
			pop    ecx
			pop    edx
		}
	}
	__except (EXCEPTION_EXECUTE_HANDLER) {
		res = false;
	}

	return res;
}

int main()
{
	if (IsVMWare()) {
		std::cout << "VMWare detected\n";
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants