Amit Klein's security corner - windows performance counter http://securitygalore.com/site3/taxonomy/term/18 en Web-based virtual machine detection using the HTML5 Performance object http://securitygalore.com/site3/vmd1-advisory <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p align="center">Multiple browsers (Microsoft Edge, Microsoft Internet Explorer, Mozilla Firefox) Performance object leaks the Windows performance counter frequency (equivalent to physical CPU clock speed or virtual machine detection)</p> <p align="center"> </p> <p align="center">Advisory</p> <p align="center">Amit Klein</p> <p align="center"> </p> <p>In three browser families researched (Edge, Internet Explorer and Firefox), it is possible to extract the frequency of the Windows performance counter frequency, using standard HTML and Javascript. In all 3 browsers, window.performance.now() yields a time measurement in milliseconds (not necessarily an integral number), which is actually an integral number of the Windows performance counter ticks (i.e. 1/<em>f</em> where <em>f</em> is the Windows performance counter frequency). With multiple samples of window.performance.now() it is possible to extract this underlying time unit (e.g. using the real number version of the GCD algorithm).</p> <p>With the Windows performance counter frequency, it is possible to (see details at the author’s “Detecting virtualization over the web with IE9 (platform preview) and Semi-permanent computer fingerprinting and user tracking in IE9 (platform preview)” sections 5 and 6 - <a href="http://landing2.trusteer.com/sites/default/files/VM_Detection_and_Temporary_User_Tracking_in_IE9_Platform_Preview.pdf">http://landing2.trusteer.com/sites/default/files/VM_Detection_and_Temporary_User_Tracking_in_IE9_Platform_Preview.pdf</a>, mirror: <a href="http://dl.packetstormsecurity.net/1012-advisories/ie9-tracking.pdf">http://dl.packetstormsecurity.net/1012-advisories/ie9-tracking.pdf</a>)</p> <ul><li>Remotely detect some virtual machines – by detecting two specific frequencies typically used in VM implementations, but rarely in physical machines – 10000000 Hz (synthetic HPET-based counter) and 3579545 Hz (ACPI-based counter). Physical machines typically use TSC-based counter, whose frequency is proportional to the nominal clock frequency. <strong>This strongly depends on the host OS, guest OS and VM implementation</strong>. Results on Windows host OS are summarized <a href="wpc-frequency-vm-os-matrix" target="_blank">here</a>. Results on non-Windows host OS may be drastically different.</li> <li>Coarse-grain fingerprint the machine – when the performance counter is TSC-based, the CPU frequency is roughly 1024 times the Windows performance counter frequency. But it also seems that different machines with the same CPU clock frequency may exhibit slightly different performance counter frequencies, thus extending the fingerprint beyond simply the CPU clock speed. For example, one machine with Intel i7-3770 CPU (3.40GHz) yielded performance counter values around 3323580Hz, while another machine with Intel i7-2600 CPU (3.40GHz) yielded values around 3312805Hz (over 10000Hz apart, way beyond the measurement fluctuations). Another important feature of this fingerprinting method is that it works across the three browsers (Edge, Internet Explorer and Firefox), i.e. all 3 browsers will produce the same fingerprint for the same machine.</li> </ul><p> </p> <p><strong>Visit the <a href="/files/vmd1.html" target="_blank">demo page</a> to see the data extracted from your browser.</strong></p> <p> </p> <p>The windows.performance object is supported starting Internet Explorer 10 (<a href="https://msdn.microsoft.com/en-us/library/ie/hh973355(v=vs.85).aspx">https://msdn.microsoft.com/en-us/library/ie/hh973355(v=vs.85).aspx</a>) and Firefox 34 (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance">https://developer.mozilla.org/en-US/docs/Web/API/Performance</a>).</p> <p> </p> <p>Proof of concept code (extracting the performance counter frequency):</p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">&lt;html&gt;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">&lt;script&gt;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">function gcd(a,b)</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">{</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        if (a&lt;0.00000001)</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        {</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">                return b;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        }</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        if (a&lt;b)</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        {</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">                return gcd(b-Math.floor(b/a)*a,a);</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        }</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        else if (a==b)</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        {</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">                return a;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        }</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        else</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        {</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">                return gcd(b,a);</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        }</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">}</span></p> <p style="margin-left:.5in;"> </p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">var x_init=performance.now()/1000;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">var g=performance.now()/1000-x_init;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">for (var i=0;i&lt;10;i++)</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">{</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">        g=gcd(g,performance.now()/1000-x_init);</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">}</span></p> <p style="margin-left:.5in;"> </p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">alert("Performance Counter Frequency: "+Math.round(1/g)+" Hz");&lt;/script&gt;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">&lt;/body&gt;</span></p> <p style="margin-left:.5in;"><span style="font-family:verdana,geneva,sans-serif;">&lt;/html&gt;</span></p> <p> </p> <p><strong>Notes about the code:</strong></p> <ul><li>The GCD algorithm yields stable results when the initial numbers fed to it are “small”. Therefore, a baseline measurement is taken and subtracted from further measurements before being fed to the GCD algorithm.</li> <li>The counter frequency seems to be a bit unstable right after restart, and after CPU idleness. A deviation of up to 5ppm (few dozen Hz) was observed.</li> <li>Affected browsers: Microsfot Edge, Microsoft Internet Explorer 10 - 11, Mozilla Firefox 34.0 (probably) - 40.0.3. The attack code was successfully tested with Edge (v20.10240.16384.0), Internet Explorer 11 (11.0.9600.18036, update version 11.0.23 - latest at the time this advisory is written), Internet Explorer 10, Firefox 40.0.3 (ditto) and Firefox 39.0 and 38.0.x and 34.0, on Windows 10 64 bit, Windows 8.1 64 bit (two machines) and Windows 7 SP1 64 bit (one machine). The attack succeeded for both Desktop and Metro styles of Internet Explorer (11).</li> </ul><p><strong>Vendor/fix status</strong></p> <ul><li>Mozilla Firefox – fixed in Firefox version 41.0 (released September 22<sup>nd</sup>, 2015). See <a href="https://www.mozilla.org/en-US/security/advisories/mfsa2015-114/" target="_blank">Mozilla Foundation Security Advisory 2015-114</a>. This is documented as part of <a href="http://www.securityfocus.com/bid/76815" target="_blank">Bugtraq BID 76815</a>.</li> <li>Microsoft Internet Explorer and Edge – MSRC tracks this issue as [21897mp] and informed me that they do not plan to fix this issue.</li> </ul></div></div></div><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above clearfix"><h3 class="field-label">Tags: </h3><ul class="links"><li class="taxonomy-term-reference-0" rel="dc:subject"><a href="/site3/taxonomy/term/4" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">VM</a></li><li class="taxonomy-term-reference-1" rel="dc:subject"><a href="/site3/taxonomy/term/5" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">HTML5</a></li><li class="taxonomy-term-reference-2" rel="dc:subject"><a href="/site3/taxonomy/term/20" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Performance</a></li><li class="taxonomy-term-reference-3" rel="dc:subject"><a href="/site3/taxonomy/term/18" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">windows performance counter</a></li></ul></div> Mon, 05 Oct 2015 20:37:33 +0000 amit 19 at http://securitygalore.com/site3 http://securitygalore.com/site3/vmd1-advisory#comments On Windows Performance Counter Frequency, VMs and guest OSes http://securitygalore.com/site3/wpc-frequency-vm-os-matrix <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>The following table summarizes the values of Windows Performance Counter Frequency in various Windows guest OS and VM implementations. In all cases, Windows (8.x/10) was the host OS - do note that very different results may be obtained on non-Windows host OS. Data was gathered in Q3 2015 with current versions at that time.</p> <table align="left" border="3" cellpadding="1" cellspacing="1" height="193" width="1113"><thead><tr><th scope="row"> </th> <th scope="col">VMware player 7.0.0 build-2305329</th> <th scope="col">Oracle VirtualBox 4.3.28 r100309</th> <th scope="col">Microsoft Hyper-V 6.3.9600.16384</th> </tr></thead><caption>Guest OS and VM implementation (with Windows 8.x/10 as host OS)</caption> <tbody><tr><th scope="row">Win 10 64-bit</th> <td><span style="color:#008000;">3579545 (PMtimer)</span></td> <td><span style="color:#ff0000;">Nominal speed / 1024 (TSC)</span></td> <td><span style="color:#008000;">10000000 (synthetic  HPET)</span></td> </tr><tr><th scope="row">Win 8.1/8.0 Ent. 32-bit</th> <td><span style="color:#ff0000;">Turbo speed / 1024 (TSC-like)</span></td> <td><span style="color:#ff0000;">Nominal speed / 1024 (TSC)</span></td> <td><span style="color:#008000;">10000000 (synthetic  HPET)</span></td> </tr><tr><th scope="row">Win 7 Ent. SP1 32-bit</th> <td><span style="color:#008000;">10000000 (synthetic HPET)</span></td> <td><span style="color:#008000;">3579545 (PMtimer)</span></td> <td><span style="color:#008000;">10000000 (synthetic HPET)</span></td> </tr></tbody></table><p>In <span style="color:#008000;">green </span>- entries (combinations) that are detectable (as VM) using Windows Performance Counter Frequency.</p> <p>In <span style="color:#ff0000;">red </span>- entries (combinations) that are undetectable (as VM) using Windows Performance Counter Frequency.</p> <p><strong>ADDITION </strong>(January 2016): tested with Microsoft Azure hypervisor (host), guest operating system Windows Server 2012 R2 Datacenter, IE11 browser - the performance counter frequenct is close to 10000000 (synthetic HPET) - the observed deviation was few dozen Hz. So Microsoft Azure is detectable. Not a big surprise since Microsoft Azure hypervisor is said to be a customized version of Microsoft Hyper-V.</p> <p> </p> <p> </p> </div></div></div><div class="field field-name-field-tags field-type-taxonomy-term-reference field-label-above clearfix"><h3 class="field-label">Tags: </h3><ul class="links"><li class="taxonomy-term-reference-0" rel="dc:subject"><a href="/site3/taxonomy/term/18" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">windows performance counter</a></li><li class="taxonomy-term-reference-1" rel="dc:subject"><a href="/site3/taxonomy/term/4" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">VM</a></li><li class="taxonomy-term-reference-2" rel="dc:subject"><a href="/site3/taxonomy/term/19" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">guest</a></li></ul></div> Mon, 05 Oct 2015 19:59:23 +0000 amit 18 at http://securitygalore.com/site3 http://securitygalore.com/site3/wpc-frequency-vm-os-matrix#comments