{"id":1097,"date":"2015-02-16T21:21:12","date_gmt":"2015-02-16T21:21:12","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=1097"},"modified":"2015-02-16T21:21:12","modified_gmt":"2015-02-16T21:21:12","slug":"vmware-detection","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2015\/02\/vmware-detection\/","title":{"rendered":"Vmware Detection"},"content":{"rendered":"<p>Ladies and gentleman &#8211; I give you yet another case of VMware detection. Unfortunately, this only works for VMware. A friend of mine, one <a href=\"https:\/\/github.com\/aaronryool\">Aaron Yool<\/a> told of me a way to detect VMware via the use of privileged instructions. Specifically the &#8220;IN&#8221; instruction. This instruction is used for reading values from I\/O ports. What the heck is that? According to the IA32 manual, I\/O ports are created in system hardware by circuity that decodes the control, data, and address pins on the processor. These I\/O ports are then configured to communicate with peripheral devices. An I\/O port can be an input port, an output port, or a bidirectional port. Some I\/O ports are used for transmitting data, such as to and from the transmit and receive registers, respectively, of a serial interface device. Other I\/O ports are used to control peripheral devices, such as the control registers of a disk controller.<\/p>\n<p>Dry material huh? That&#8217;s the Intel manual for you. <\/p>\n<p>Normally you can&#8217;t execute this instruction on Windows in user mode &#8211; its a SYSTEM instruction like HLT which are reserved for ring 0. On VMware however, you can call it from ring 3. <\/p>\n<p>What can be done if a user mode program and run system level instructions? The sky is the limit, but think rootkit without admin. Pretty wicked stuff. Is this the case here? No, not yet anyways. For now though, we have here a simple way of checking to see if we&#8217;re inside VMWare, POC included. We&#8217;re using SEH (Structured Exception Handling) here in case Windows complains about the instruction being privileged.<br \/>\nWho here likes code? I do!<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-style: italic\">\/\/ ------------------------------------------------------------------------------<\/span>\r\n<span style=\"color: #008800; font-style: italic\">\/\/ THE BEER-WARE LICENSE (Revision 43):<\/span>\r\n<span style=\"color: #008800; font-style: italic\">\/\/ &lt;aaronryool@gmail.com&gt; wrote this file. As long as you retain this notice you<\/span>\r\n<span style=\"color: #008800; font-style: italic\">\/\/ can do whatever you want with this stuff. If we meet some day, and you think<\/span>\r\n<span style=\"color: #008800; font-style: italic\">\/\/ this stuff is worth it, you can buy me a beer in return<\/span>\r\n<span style=\"color: #008800; font-style: italic\">\/\/ ------------------------------------------------------------------------------<\/span>\r\n\r\n<span style=\"color: #008080\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #008080\">#include &lt;windows.h&gt;<\/span>\r\n\r\n<span style=\"color: #000080; font-weight: bold\">unsigned<\/span> vmware(<span style=\"color: #000080; font-weight: bold\">void<\/span>)\r\n{\r\n<span style=\"color: #000080; font-weight: bold\">__asm<\/span>{\r\n\tmov eax, <span style=\"color: #0000FF\">0x564d5868<\/span>\r\n\tmov cl, <span style=\"color: #0000FF\">0xa<\/span>\r\n\tmov dx, <span style=\"color: #0000FF\">0x5658<\/span>\r\n\tin eax, dx\r\n\tcmp ebx, <span style=\"color: #0000FF\">0<\/span>\r\n\tjne matrix\r\n\txor eax, eax\r\n\tret\r\n\tmatrix:\r\n\tmov eax, <span style=\"color: #0000FF\">1<\/span>};\r\n}\r\n\r\n<span style=\"color: #000080; font-weight: bold\">int<\/span> seh_filter(<span style=\"color: #000080; font-weight: bold\">unsigned<\/span> code, <span style=\"color: #000080; font-weight: bold\">struct<\/span> _EXCEPTION_POINTERS* ep)\r\n{\r\n\t<span style=\"color: #000080; font-weight: bold\">return<\/span> EXCEPTION_EXECUTE_HANDLER;\r\n}\r\n\r\n<span style=\"color: #000080; font-weight: bold\">int<\/span> _tmain(<span style=\"color: #000080; font-weight: bold\">int<\/span> a, _TCHAR* argv[])\r\n{\r\n    <span style=\"color: #000080; font-weight: bold\">__try<\/span>\r\n\t{\r\n\t\t<span style=\"color: #000080; font-weight: bold\">if<\/span>(vmware()) <span style=\"color: #000080; font-weight: bold\">goto<\/span> matrix;\r\n    }\r\n    <span style=\"color: #000080; font-weight: bold\">__except<\/span>(seh_filter(GetExceptionCode(), GetExceptionInformation()))\r\n    {\r\n            <span style=\"color: #000080; font-weight: bold\">goto<\/span> stage2;\r\n    }\r\n\r\nstage2:\r\n\tstd::cout &lt;&lt; <span style=\"color: #0000FF\">&quot;Isn&#39;t real life boring?&quot;<\/span>&lt;&lt;std::endl;\r\n\texit(<span style=\"color: #0000FF\">0<\/span>);\r\n\r\nmatrix:\r\n\tstd::cout &lt;&lt; <span style=\"color: #0000FF\">&quot;The Matrix haz you Neo...&quot;<\/span>&lt;&lt;std::endl;\r\n\texit(<span style=\"color: #0000FF\">1<\/span>);\r\n}\r\n<\/pre>\n<\/div>\n<p>PoC pic:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/30kcmzf.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/30kcmzf-300x223.png\" alt=\"30kcmzf\" width=\"300\" height=\"223\" class=\"alignnone size-medium wp-image-1098\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/30kcmzf-300x223.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/30kcmzf-1024x760.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/30kcmzf.png 1280w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Happy hacking!<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1258259648622.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1258259648622.jpg\" alt=\"1258259648622\" width=\"366\" height=\"367\" class=\"alignnone size-full wp-image-1100\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1258259648622.jpg 366w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1258259648622-150x150.jpg 150w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1258259648622-300x300.jpg 300w\" sizes=\"(max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ladies and gentleman &#8211; I give you yet another case of VMware detection. Unfortunately, this only works for VMware. A friend of mine, one Aaron Yool told of me a way to detect VMware via the use of privileged instructions. Specifically the &#8220;IN&#8221; instruction. This instruction is used for reading values from I\/O ports. What [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[103],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1097"}],"collection":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/comments?post=1097"}],"version-history":[{"count":4,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1097\/revisions"}],"predecessor-version":[{"id":1104,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1097\/revisions\/1104"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=1097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=1097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=1097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}