Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:23611
HistoryApr 14, 2010 - 12:00 a.m.

Advisory 02/2010: MyBB Password Reset Weak Random Numbers Vulnerability

2010-04-1400:00:00
vulners.com
15
                     SektionEins GmbH
                    www.sektioneins.de

                 -= Security  Advisory =-

 Advisory: MyBB Password Reset Weak Random Numbers Vulnerability

Release Date: 2010/04/13
Last Modified: 2010/04/13
Author: Stefan Esser [stefan.esser[at]sektioneins.de]

Application: MyBB <= 1.4.11
Severity: Usage of weak random number generation in password reset
functionality allows predicting the password reset token
and the randomly generated password, which results in
account takeover.
Risk: Critical
Vendor Status: MyBB 1.4.12 was released which partly fixes this
vulnerability
Reference:
http://www.sektioneins.com/en/advisories/advisory-022010-mybb-password-reset-weak-random-numbers-vulnerability/

http://www.suspekt.org/2008/08/17/mt_srand-and-not-so-random-numbers/

Overview:

Quote from http://www.mybboard.net
"MyBB is a discussion board that has been around for a while; it has
evolved from other bulletin boards into the forum package it is
today. Therefore, it is a professional and efficient discussion
board, developed by an active team of developers. The MyBB history
has been recorded and is available for the interested to read.
You can also read more about the MyBB team and why they develop
MyBB in their spare time. We also like to highlight the most
active and contributing fansites of the MyBB community."

During evaluation of various password reset implementations it was
discovered that MyBB uses weak random numbers when generating the
password reset token and randomly generated passwords.

A malicious user can takeover arbitrary accounts if PHP processes
are reused by the webserver. The most common PHP installation:
mod_php with activated keep-alive request is therefore vulnerable.

Details:

In various places MyBB seeds the random number generator with the
mt_srand() function.

// Setup a unique posthash for attachment management
if&#40;!$mybb-&gt;input[&#39;posthash&#39;] &amp;&amp; $mybb-&gt;input[&#39;action&#39;] != &quot;editdraft&quot;&#41;
{
   mt_srand&#40;&#40;double&#41; microtime&#40;&#41; * 1000000&#41;;
   $posthash = md5&#40;$mybb-&gt;user[&#39;uid&#39;].mt_rand&#40;&#41;&#41;;
}

Code like this will seed the random number generator with only
one million different seed values. In addition to that the first
generated random number will be leaked to the user in form of the
post hash. Because the user knows his 'uid' it is easy to find the
seed used by just bruteforcing the one million possibilities.
A normal desktop PC is able to perform this attack in less than a
second.

Because the state of the random number generator is shared by
requests handled by the same PHP process a password reset triggered
afterwards will therefore use a state known by the attacker.

The password reset will first create a random password reset token
that is sent to the user. If this token is used the second step of
the password reset will generate a new random password. Both random
strings are generated by the following function.

 function random_str&#40;$length=&quot;8&quot;&#41;
 {
    $set =array&#40;&quot;a&quot;,&quot;A&quot;,&quot;b&quot;,&quot;B&quot;,&quot;c&quot;,&quot;C&quot;,&quot;d&quot;,&quot;D&quot;,&quot;e&quot;,&quot;E&quot;,&quot;f&quot;,&quot;F&quot;,
                &quot;g&quot;,&quot;G&quot;,&quot;h&quot;,&quot;H&quot;,&quot;i&quot;,&quot;I&quot;,&quot;j&quot;,&quot;J&quot;,&quot;k&quot;,&quot;K&quot;,&quot;l&quot;,&quot;L&quot;,
                &quot;m&quot;,&quot;M&quot;,&quot;n&quot;,&quot;N&quot;,&quot;o&quot;,&quot;O&quot;,&quot;p&quot;,&quot;P&quot;,&quot;q&quot;,&quot;Q&quot;,&quot;r&quot;,&quot;R&quot;,
                &quot;s&quot;,&quot;S&quot;,&quot;t&quot;,&quot;T&quot;,&quot;u&quot;,&quot;U&quot;,&quot;v&quot;,&quot;V&quot;,&quot;w&quot;,&quot;W&quot;,&quot;x&quot;,&quot;X&quot;,
            &quot;y&quot;,&quot;Y&quot;,&quot;z&quot;,&quot;Z&quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;&#41;;
    $str = &#39;&#39;;

    for&#40;$i = 1; $i &lt;= $length; ++$i&#41;
    {
       $ch = mt_rand&#40;0, count&#40;$set&#41;-1&#41;;
       $str .= $set[$ch];
    }

    return $str;
 }

The problem with this code is that is uses mt_rand() to generate
the random strings and the state of the mt_rand() number generator
is known to the remote attacker. He is therefore able to predict
both the genersted password reset token and also the new password.
This allows taking over arbitrary accounts.

This vulnerability was fixed by the vendor by reseeding the random
number generator on every request with a securely generated seed.
This renders the discovered attack infeasible but might be vulnerable
to future attacks. We therefore recommended an additional safeguard
that might make it into the next release version.

Furthermore it should be noted that users of the Suhosin Extension
version 0.9.26 or newer are safe from this class of attacks because
random numbers generated by rand() and mt_rand() are more secure by
default.

Proof of Concept:

SektionEins GmbH is not going to release a proof of concept
exploit for this vulnerability.

Disclosure Timeline:

  1. March 2010 - Notified the MyBB devs via security contact form
  2. April 2010 - MyBB developers released MyBB 1.4.12
  3. April 2010 - Public Disclosure

Recommendation:

It is recommended to upgrade to the latest version of MyBB.
However we hope that our late recommendations for more secure
random number generation will make it into the next release.

Grab your copy at:
http://mybboard.net/downloads

CVE Information:

The Common Vulnerabilities and Exposures project (cve.mitre.org) has
not assigned a name to this vulnerability.

Month of PHP Security:

If you have a non-public vulnerability like this don't hesitate to
submit it to the Month of PHP Security. Further information at

http://php-security.org

GPG-Key:

pub 1024D/15ABDA78 2004-10-17 Stefan Esser
Key fingerprint = 7806 58C8 CFA8 CE4A 1C2C 57DD 4AE1 795E 15AB DA78

Copyright 2010 SektionEins GmbH. All rights reserved.