PT-2012-30: Administrator Privilege Gaining in OpenCart

Vulnerable software

OpenCart
Version: 1.5.3.1 and earlier

Application link:
http://www.opencart.com/

Severity level

Severity level: High
Impact: Administrator Privilege Gaining
Access Vector: Remote  

CVSS v2:
Base Score: 9.3
Vector: (AV:N/AC:M/Au:N/C:C/I:C/A:C)

CVE: not assign

Software description

OpenCart is a powerful open source shopping cart system that is designed feature rich and user friendly.

Vulnerability description

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 admin@host.com 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
Host: host
host 0
Connection: keep-alive

 

HTTP/1.1 302
...
Location: http://host/admin/index.php?route=common/home&token=2ead018af57862dda59cb67b77f19075

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

Advisory status

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

Credits

The vulnerabilities has discovered by Arseny Reutov, Positive Research Center (Positive Technologies Company)

References

http://en.securitylab.ru/lab/PT-2012-30

Reports on the vulnerabilities previously discovered by Positive Research:

http://ptsecurity.com/research/advisory/
http://en.securitylab.ru/lab/