PrestaShop is an open source e-commerce web application. Versions prior to 1.7.8.10, 8.0.5, and 8.1.1 are vulnerable to remote code execution through SQL injection and arbitrary file write in the back office. Versions 1.7.8.10, 8.0.5, and 8.1.1 contain a patch. There are no known workarounds.

Summary

  • CVE ID: CVE-2023-39526
  • Published at: 2023-08-07
  • Advisory source: PrestaShop
  • Platform: PrestaShop
  • Product: PrestaShop
  • Impacted release: >= 8.0.0 < 8.0.3 and < 1.7.8.8 (Patched versions 8.0.4 and 1.7.8.9)
  • Weakness: CWE-22
  • Severity: medium (7.2)

Description

Remote code execution through SQL injection and arbitrary file write in back office

CVSS base metrics

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

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

Possible malicious usage

  • Elevate privileges to super admin
  • Extract sensitive data, such as tokens or private keys stored in config files
  • Extract other private data, such as log files or exports

Patch

--- a/classes/RequestSql.php
+++ b/classes/RequestSql.php
@@ -65,6 +65,7 @@ class RequestSqlCore extends ObjectModel
             'RESET', 'START', 'STOP', 'PURGE', 'EXECUTE', 'PREPARE', 'DEALLOCATE', 'LOCK', 'USING', 'DROP', 'FOR', 'UPDATE', 'BEGIN', 'BY', 'ALL', 'SHARE',
             'MODE', 'TO', 'KEY', 'DISTINCTROW', 'DISTINCT',  'HIGH_PRIORITY', 'LOW_PRIORITY', 'DELAYED', 'IGNORE', 'FORCE', 'STRAIGHT_JOIN',
             'SQL_SMALL_RESULT', 'SQL_BIG_RESULT', 'QUICK', 'SQL_BUFFER_RESULT', 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS', 'WITH',
+            'OUTFILE', 'DUMPFILE',
         ],
     ];
 
diff --git a/classes/db/Db.php b/classes/db/Db.php
index 9d44e5e0fe1e..6223b6a1d03f 100644
--- a/classes/db/Db.php
+++ b/classes/db/Db.php
@@ -603,7 +603,11 @@ public function executeS($sql, $array = true, $use_cache = true)
         }
 
         // This method must be used only with queries which display results
-        if (!preg_match('#^\s*\(?\s*(select|show|explain|describe|desc|checksum)\s#i', $sql)) {
+        if (
+            !preg_match('#^\s*\(?\s*(select|show|explain|describe|desc|checksum)\s#i', $sql)
+            || stripos($sql, 'outfile') !== false
+            || stripos($sql, 'dumpfile') !== false
+        ) {
             throw new PrestaShopDatabaseException('Db->executeS() must be used only with select, show, explain or describe queries');
         }

Other recommendations

  • It’s recommended to upgrade to the latest version of the PrestaShop
  • Disable local_infile MySQL options if not usefull