Interesting VMM Detection Technique

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Interesting VMM Detection Technique

Post by SpooK »

-----> http://invisiblethings.org/tools/redpill.c <-----

Thought it was pretty neat, although I have not tested it myself. I'll get around to testing it, eventually :P
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

Hi Spook,
is there some kind of competition going on about who can post the most obscure program ? After all this is alredy the second thread this week that presents some barely readable code-fragment..

It took me some time to get the hang of the snippet and I can't say that I was rewarded. All it seems to do is to check if the idt base-address is located in some special area (namely, base &0xff00 > 0xd000). This is however nonsense in my opinion as the IDT may be located pretty much anywhere in memory. The only restriction I'm aware of is that the table should (must?) be aligned to a 8 byte boundary.

Here's my interpretation of the snippet:

Code: Select all

struct idt_register
{
   unsigned short limit;
   unsigned long  address;
	 
}__attribute__((__packed__));

int main()
{
   idt_register idtr;

   // Get the IDT's base-address using the SIDT instruction
   asm("sidt (%%eax)\n" : : "a"(&idtr));
	
   // If the IDT is stored in the last 16k of a 64k block
   // we're running on a virtual machine ?!
   if((idtr.address &0xff00) > 0xd000)
      cout << "Running on a virtual machine" << endl;

   cout << "IDT location: " << setbase(16) << idtr.address; 
}
Is there anything I missed ?

regards,
gaf
Pelz
Posts: 2
Joined: Wed Jun 21, 2006 3:13 pm

Post by Pelz »

Items marked with a * are required unless stated otherwise.
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Post by SpooK »

Learning is not about conforming to your assumptions and expectations.
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

Hello,
I've noted a small bug in the code that I provided in my last post. As the data in the array (m) is stored in the little-endian covention it would actually be if(idtr.address > 0xd0000000). Along with the article Pelz pointed out this at least explains how it's supposed to work.
Learning is not about conforming to your assumptions and expectations.
That's the very reason why I asked whether I missed anything. I still don't think that there's really much to learn from the snipped: It's just some utterly hacky piece of code based an a number of assumtions about the internal workings of VMWare.

regards,
gaf
User avatar
chase
Site Admin
Posts: 715
Joined: Wed Oct 20, 2004 10:46 pm
Libera.chat IRC: chase_osdev
Location: Texas
Discord: chase/matt.heimer
Contact:

Post by chase »

gaf wrote:Hello,
It's just some utterly hacky piece of code based an a number of assumtions about the internal workings of VMWare.
Kinda of reminds me of some of the old techniques to determine cpu models. You'd do things like see if segements rapped around in memory and other stuff. Ugly yes, but possibly useful under the right situation. Thank God for cpuid :)

I haven't looked at(used but not hacked at) a lot of the VM type software but I thought I remember reading something about the VMs providing extra BIOS services to interact the host OS. Is this a known/typical type thing?
User avatar
carbonBased
Member
Member
Posts: 389
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Post by carbonBased »

chase wrote: I haven't looked at(used but not hacked at) a lot of the VM type software but I thought I remember reading something about the VMs providing extra BIOS services to interact the host OS. Is this a known/typical type thing?
I guess that'd kind-of be like dpmi, but to the potentially-different host OS? Sounds feasible, but I don't understand why this is. Is there a breed of software designed to run in a VM? Or is this just an interface to allow them to run better in a VM, if they happen to be in one?

This also reminds me of Xen, which requires the guest OS to be built against a set of APIs that allow it to be better virtualized (that's what a gather the basic concept is... admitantely, I haven't looked at it much, so this may not be entirely accurate).

--Jeff
Post Reply