VMware Cloud Community
fixitchris
Hot Shot
Hot Shot
Jump to solution

RedPill: Am I a VM?

Is there any quick way to test if the machine running the posh script is a VM?

0 Kudos
1 Solution

Accepted Solutions
halr9000
Commander
Commander
Jump to solution

It's not perfect, but you could easily use Get-Service to check for presence of the tools service.




[vExpert|http://www.vmware.com/communities/vexpert/], PowerShell MVP, VI Toolkit forum moderator

Author of the book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000

View solution in original post

0 Kudos
16 Replies
halr9000
Commander
Commander
Jump to solution

It's not perfect, but you could easily use Get-Service to check for presence of the tools service.




[vExpert|http://www.vmware.com/communities/vexpert/], PowerShell MVP, VI Toolkit forum moderator

Author of the book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

That will do Hal.

function myIsLocalhostVM()
	{
		$VMTools = Get-Service VMTools -EA 0
		if ( -not $VMTools ) 
			{ return $false }
		else
			{ return $true };
	}

0 Kudos
halr9000
Commander
Commander
Jump to solution

Or,

function myIsLocalhostVM { if ( Get-Service VMTools ) { return $true } }

Smiley Happy






[vExpert|http://www.vmware.com/communities/vexpert/], PowerShell MVP, VI Toolkit forum moderator

Author of the book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
LucD
Leadership
Leadership
Jump to solution

If you can't run the VMware Tools service, for whatever reason, on your Windows guest, you could use the BIOS SerialNumber.

function myIslocalhostVM{
  if ((Get-WmiObject Win32_BIOS).SerialNumber -match "VMware"){return $true}
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

halr9000
Commander
Commander
Jump to solution

Nice one, Luc.

--

Hal Rottenberg / hal@halr9000.com<mailto:hal@halr9000.com> / halr9000.com<http://halr9000.com>

Microsoft MVP (PowerShell) / VMware vExpert

Co-Host, PowerScripting Podcast / Director, PowerShellCommunity.org

"Managing VMware Infrastructure with PowerShell: TFM", due in April!

Follow me on Twitter: http://twitter.com/halr9000

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

Good find.

0 Kudos
TomHowarth
Leadership
Leadership
Jump to solution

If I know LucD he did not just find it :smileygrin: he most likely knew it already LOL

If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points

Tom Howarth VCP / vExpert

VMware Communities User Moderator

Blog: www.planetvm.net

Contributing author for the upcoming book "VMware Virtual Infrastructure Security: Securing ESX and the Virtual Environment”.

Tom Howarth VCP / VCAP / vExpert
VMware Communities User Moderator
Blog: http://www.planetvm.net
Contributing author on VMware vSphere and Virtual Infrastructure Security: Securing ESX and the Virtual Environment
Contributing author on VCP VMware Certified Professional on VSphere 4 Study Guide: Exam VCP-410
0 Kudos
MattG
Expert
Expert
Jump to solution

You could also try by MAC address so long as the guest hasn't been manually set with a MAC address.

ESX server VMs begin with 00:0C:29

VirtualCenter created ESX Server VMs begin with 00:50:56

If you ping the server in question and then run an Arp -a from your workstation you should be able to look at the MAC address and know if it is a VMWare VM.

-MattG

-MattG If you find this information useful, please award points for "correct" or "helpful".
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Chris, you are asking to re-write the Red Pill exploit in PS.

That is in fact not a big problem since one can easily use any .Net language with the CompileAssemblyFromSource method.

But is there really a point in doing this ?

I can only see the Red Pill being used in honeypots, not in 'regular' guests. For me there is no real value in accepting your challenge (albeit it an interesting exercise).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fixitchris
Hot Shot
Hot Shot
Jump to solution

I might need the exercise in ps pinvoke...

0 Kudos
Horinius
Enthusiast
Enthusiast
Jump to solution

I think checking against the existence of VMWare Tools service might raise a false positive in at least one situation:

converting a VM to a real computer and the service isn't uninstalled.

OTOH, I had just tried to install VMWare Tools (using ISO image provided by WorkStation 6.5.2) in a real PC and I noticed that the setup.exe refused to go on, saying that the computer isn't virtual. So that means there's an official way to detect if one's inside a VMWare VM. The question is: is VMWare going to release an official tool to check if one is within a VM.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you have a chance to test this theory also against a *nix client ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Horinius
Enthusiast
Enthusiast
Jump to solution

What theory? What do you mean by client? Guest Linux?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I meant if you tried to install the VMware Tools on a physical *nix client (Linux guest indeed).

Did it also say that it wasn't a virtual client ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Horinius
Enthusiast
Enthusiast
Jump to solution

Oh, that, my friend, I'm afraid I couldn't fulfill your wish, as I don't have any real and spare PC having Linux. All my Linux are within VM.

Hope somebody else could do this test and tell you the answer.

0 Kudos