Multiple SQL injection vulnerabilities in the Leo Custom Ajax (leocustomajax) module from LeoTheme for PrestaShop, in version 1.0, allow remote attackers to execute arbitrary SQL commands via the cat_list, pro_info, pro_add, pro_cdown or pro_color parameter in leoajax.php.

Summary

  • CVE ID: CVE-2023-30150
  • Published at: none
  • Advisory source: Friends-Of-Presta
  • Platform: PrestaShop
  • Product: leocustomajax
  • Impacted release: = 1.0 (May also be identified as 1.0.0)
  • Product author: LeoTheme
  • Weakness: CWE-89
  • Severity: critical (9.8)

Description

In the Leo Custom Ajax (leocustomajax) module for PrestaShop, in version 1.0 and 1.0.0 (no other versions have been published since), an HTTP request can be manipulated using multiple GET parameters (cat_list, pro_info, pro_add, pro_cdown and pro_color), in the /modules/leocustomajax/leoajax.php endpoint, enabling a remote attacker to perform an SQL injection.

WARNING : This vulnerability can be exploited even if the module is disabled or uninstalled, and is actively used to deploy webskimmer to massively steal credit cards.

CVSS base metrics

  • Attack vector: network
  • Attack complexity: low
  • Privilege required: none
  • User interaction: none
  • Scope: unchanged
  • Confidentiality: high
  • Integrity: high
  • Availability: high

Vector string: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Possible malicious usage

  • Obtain admin access
  • Remove data from the associated PrestaShop
  • Copy/paste data from sensitive tables to FRONT to exposed tokens and unlock admins’ ajax scripts
  • Rewrite SMTP settings to hijack emails

Proof of concept

https://example.test/modules/leocustomajax/leoajax.php?cat_list=10%29;select+0x73656C65637420736C656570283432293B+into+@a;prepare+b+from+@a;execute+b;--

Patch

Disabling or uninstalling the module is not enough. The module needs to be fully removed from the file system or patched.

--- a/modules/leocustomajax/leoajax.php
+++ b/modules/leocustomajax/leoajax.php
@@ -25,6 +25,7 @@ $leoProductInfo = new Leocustomajax();
 if ($listCat) {
     $listCat = explode(',', $listCat);
     $listCat = array_unique($listCat);
+    $listCat = array_map('intval', $listCat);
     $listCat = implode(',', $listCat);
 
     $sql = 'SELECT COUNT(cp.`id_product`) AS total, cp.`id_category`
@@ -44,6 +45,7 @@ if ($listCat) {
 if ($leoProCdown) {
     $leoProCdown = explode(',', $leoProCdown);
     $leoProCdown = array_unique($leoProCdown);
+    $leoProCdown = array_map('intval', $leoProCdown);
     $leoProCdown = implode(',', $leoProCdown);
     $result['pro_cdown'] = $leoProductInfo->hookProductCdown($leoProCdown);
 }
@@ -51,6 +53,7 @@ if ($leoProCdown) {
 if ($leoProColor) {
     $leoProColor = explode(',', $leoProColor);
     $leoProColor = array_unique($leoProColor);
+    $leoProColor = array_map('intval', $leoProColor);
     $leoProColor = implode(',', $leoProColor);
     $result['pro_color'] = $leoProductInfo->hookProductColor($leoProColor);
 }
@@ -59,6 +62,7 @@ if ($leoProColor) {
 if ($leoProInfo) {
     $leoProInfo = explode(',', $leoProInfo);
     $leoProInfo = array_unique($leoProInfo);
+    $leoProInfo = array_map('intval', $leoProInfo);
     $leoProInfo = implode(',', $leoProInfo);
 
     # $leocustomajax = new Leocustomajax();
@@ -67,6 +71,7 @@ if ($leoProInfo) {
 if ($leoProAdd) {
     $leoProAdd = explode(',', $leoProAdd);
     $leoProAdd = array_unique($leoProAdd);
+    $leoProAdd = array_map('intval', $leoProAdd);
     $leoProAdd = implode(',', $leoProAdd);
 
     $result['pro_add'] = $leoProductInfo->hookProductOneImg($leoProAdd);

Other recommendations

  • To help improve the security of your PrestaShop installation, we recommend upgrading to the latest version. One of the benefits of upgrading is that it will disable the use of multiquery executions (separated by semicolons). However, please be aware that this will not protect your shop against SQL injection attacks that use the UNION clause to steal data. Additionally, it’s important to note that PrestaShop includes a function called pSQL, which includes a strip_tags function. This helps protect your shop against Stored XSS (also known as XSS T2) of Category 1. If a pSQL function is missing, it could potentially expose your project to critical Stored XSS vulnerabilities due to edge cases. Therefore, it’s crucial to ensure that all relevant functions are properly implemented and used consistently throughout your project.
  • Change the default database prefix ps_ by a new longer arbitrary prefix. Nevertheless, be warned that this is useless against blackhats with DBA senior skills because of a design vulnerability in DBMS
  • Activate OWASP 942’s rules on your WAF (Web application firewall), be warned that you will probably break your backoffice and you will need to pre-configure some bypasses against these set of rules.

Timeline

Date Action
2022-09-18 Discovery of the vulnerability by Profileo
2022-09-19 Security issue reported to the author
2022-09-20 Issue confirmed by the author
2023-03-25 Request for additional details concerning impacted versions
2023-03-28 Author replied confirming versions impacted
2023-06-06 Publication of the security advisory