PT-2012-30: Administrator Privilege Gaining in OpenCart
Version: 184.108.40.206 and earlier
Severity level: High
Impact: Administrator Privilege Gaining
Access Vector: Remote
Base Score: 9.3
CVE: not assign
OpenCart is a powerful open source shopping cart system that is designed feature rich and user friendly.
The specialists of the Positive Research center have detected "Administrator Privilege Gaining" vulnerability in OpenCart.
An attacker can get administrator password and other forum users' passwords because of insecure random number generator used in password recovery feature.
1. Predictable confirmation code used for administrator password recovery
Vulnerable code: admin/controller/common/forgotten.php
$code = md5(mt_rand());
Administrator email is necessary for password recovery. If an attacker knows administrator email (mostly emails like firstname.lastname@example.org are used), he can easily change its password.
It is possible as OpenCart gets random numbers from PHP function mt_rand that implements Mersenne Twister algorithm and does not initiate random number generator with mt_srand function.
In this case, PHP automatically uses quasi-random 32 bit integer number based on the current process environmental data to initiate the generator.
With mt_rand result an attacker is able to get the source value used to initialize the random generator via brute force (2^32 alternatives).
It is possible to get mt_rand results in MD5 hash form in OpenCart:
POST /admin/index.php?route=user/user HTTP/1.0
Therefore, if an attacker decrypts MD5 and gets the random number, he is able to get the source value used for random number generating. With this value, he is able to predict all further random numbers.
The attacker has to send 2 keep-alive requests to implement the attack. The first request allows the attacker to get MD-5 hash of the random value, the second one is used to call for the page that recovers administrator's password. This allows the attacker to get confirmation code and change the password.
2. Predictable generated password in case user or affiliate password is recovered
Vulnerable code: catalog/controller/account/forgotten.php, catalog/controller/affiliate/forgotten.php
$password = substr(md5(mt_rand()), 0, 10);
User email is necessary for password recovery. If an attacker knows user's email, he is able to change its password without confirmation, new password is just sent to user's email.
An attacker can use the same method as for administrator account to predict user's password.
How to fix
Update your software up to the latest version
23.08.2012 - Vendor is notified
23.08.2012 - Vendor gets vulnerability details
23.08.2012 - Vendor releases fixed version and details
11.09.2012 - Public disclosure
The vulnerabilities has discovered by Arseny Reutov, Positive Research Center (Positive Technologies Company)
Reports on the vulnerabilities previously discovered by Positive Research: