I Forgot My Password!
Both vulnerabilities are exploitable through CubeCarts “I forgot my Password!” functionality. It is implemented in the file
classes/cubecart.class.php, in the method
_recovery(). When a user forgot his password, he can use this feature to enter his email address, a valid password reset token he received via email, and his new password for reset.
At the beginning of this method, these three user controlled parameters are passed to the
passwordReset() method of the
User class located in
classes/user.class.php. The method is responsible for the account retrieval.
passwordReset() method starts to check if the email is a valid email address, if all parameters are non-empty, and if the passwords are equal on line
680-683. If one of those checks fails the password reset progress will fail on line
694. Otherwise, the next check is a database query issued by a
select() call in the lines
685-687. Here, the user supplied
$verification token is used as arguments.
select() method constructs a SQL query which is then sent to the database (line
576). To construct the WHERE clause of the SELECT query, the application uses the vulnerable method
where() in line
In the next two sections we will analyze this
where() method and present two individually detected vulnerabilities.
Unauthenticated Blind SQL Injection
where() method of the
database.class.php sanitizes values provided in the second parameter
$whereArray perfectly fine with the PHP built-in function
mysql_real_escape_string(). However, if the value is an array (line
811), then each value of the array is concatenated unsanitized into the SQL query on line
As an attacker we can now pass an array as our user input. This will allow us to inject SQL syntax into the constructed SQL query and to perform SQL injection attacks to extract sensitive information from the database. A malicious POST request could look like the following:
email@example.com validate=0)+OR+sleep(10 password[password]=secretnewpassword password[passconf]=secretnewpassword token=15f84b621a9982d65f82d6f12764ecdb
Note how the
validate input parameter now is an array not containing a valid password reset token anymore but our SQL payload. The constructed SQL query can be seen below (the injected part is marked red).
SELECT `customer_id`, `email` FROM `cc6111_CubeCart_customer` WHERE cc6111_CubeCart_customer.email = 'firstname.lastname@example.org'
AND `verify` IN (0) OR sleep(10);
As a result, an adversary can modify the SQL query and start to extract the password hashes of all users, or aim for more sophisticated attacks pivotting on the database to the underyling operating system. But there is an even easier way to authenticate than to steal and crack the administrator’s password hash.
Our second vulnerability is only a few lines away from our SQL injection vulnerability showing that we actually do not need to inject SQL syntax to gain access as an administrator. The
where() method of the
database.class.php file also introduces search modifiers.
where() method checks the input values for special characters (< > ~ ! + -) ultimately effecting which comparison operator will be used in the WHERE clause of the SQL query.
For example, a prefixed tilde character (
~) in a value will construct a SQL query with a LIKE syntax (line
817-818). A LIKE operation does not require an exact match in the database but allows wildcard characters (
%). This can be abused to bypass the check for a valid password reset token. All we have to do is to prefix our password reset token with a
~ character and to put as many wildcard characters into the password reset token as the expected token length is. This will result in the following SELECT query:
select * from CubeCart_customer where email = 'email@example.com'
and verify LIKE '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
The WHERE condition that requires a correct verify token will evaluate to true almost all the time with our crafted verification token and is thus bypassed. This allows an adversary to reset the password of an administrator in a matter of seconds and to login as admin. In the administration panel, an attacker can then abuse admin features to execute arbitrary PHP code.
|2017/10/11||Provided vulnerability details and PoC to vendor|
|2017/10/11||Vendor confirmed security issue|
|2017/10/16||Vendor released 6.1.12 version|
|2017/11/23||Vendor informed about additional issues|
|2017/11/29||Vendor released 6.1.13 fixed version|
We detected two critical issues that allow an attacker to bypass CubeCart’s authentication and to login as an administrator. The security issues base on a custom database abstraction layer that compiles SQL queries in an unsafe manner. Due to the absence of prepared statements and custom SQL concatenation features, an attacker can malform the SQL query that is used for authentication in order to bypass it.
We would like to thank the CubeCart team for their very fast and professional handling of these issues. They responded immediately to our report and released a fixed version rapidly. We recommend to update to CubeCart 6.1.13 immediately.