-
Notifications
You must be signed in to change notification settings - Fork 24
ORDER BY SQL Injection Vulnerability in ShopSuite System #3
Description
Vulnerability Title: ORDER BY SQL Injection Vulnerability in ShopSuite System Product Item Listing
Vulnerability Type: SQL Injection (Order By Clause Injection)
Severity: High
Description: The ShopSuite system contains a SQL injection vulnerability in the listItemKey method of the ProductItemDao interface. Attackers can inject malicious SQL code through the sidx and sort parameters in ORDER BY clauses, allowing extraction of sensitive information from the database including product data, user information, system configuration, and potentially administrative credentials.
Vulnerability Location:
File: src/main/resources/mapper/pt/ProductItemXml.xml (line 72)
Method: listItemKey
Parameters: params.sidx and params.sort (direct string interpolation)
Complete URLs:
GET /front/pt/product/listItem(unauthorized access)
Vulnerability Principle: When processing product item listing requests, the system directly interpolates user-controlled sidx and sort parameters into the SQL ORDER BY clause without any filtering, escaping, or whitelist validation. The vulnerability exists in the MyBatis XML mapper where ${params.sidx} ${params.sort} is directly concatenated into the SQL statement.
Code Analysis:
<!-- ProductItemXml.xml line 71-73 -->
<when test="(params.sidx != null and params.sort != null) and (params.sidx != '' and params.sort != '')">
ORDER BY b.product_order ASC, i.${params.sidx} ${params.sort}, b.product_id DESC
</when>Call Chain Analysis:
- Controller Layer (User input entry):
ProductController.listItem()→/front/pt/product/listItem
- Service Layer:
ProductIndexServiceImpl.listItem()(line 551) calls repository method
- Repository Layer:
ProductItemRepositoryImpl.listItemKey()(line 85) calls DAO method
- DAO Layer:
ProductItemDao.listItemKey()interface method
- SQL Layer:
ProductItemXml.xmlexecutes vulnerable SQL with${params.sidx}and${params.sort}interpolation
Impact Scope:
- Extraction of database product information (SKU, pricing, inventory)
- Extraction of user information and administrative accounts
- Extraction of database structure and configuration
- Potential extraction of sensitive business data and financial information
- Possible complete database compromise through UNION-based injection
- Database manipulation (INSERT/UPDATE/DELETE) in certain database configurations
Exploitation Conditions:
- No authentication required for frontend interfaces
- Authentication required for backend management interfaces
- Supports error-based, UNION-based, and time-based blind injection techniques
- MySQL database backend (based on SQL syntax)
Payload Construction Format:
GET /front/pt/product/listItem?sidx=[SQL_INJECTION_PAYLOAD]&sort=[SORT_DIRECTION]
Attack Payload Examples:
Error-based SQL Injection:
GET /front/pt/product/listItem?sidx=item_id,(select updatexml(1,concat(0x7e,@@version_comment,0x7e),1))&sort=desc
Fix Recommendations:
- Use Whitelist Validation: Implement a whitelist of allowed column names for sorting
- Parameterized Queries: Use MyBatis
#{}parameter binding instead of${}string interpolation - Input Validation: Validate
sidxagainst a predefined list of column names - Sort Direction Validation: Ensure
sortparameter is only 'ASC' or 'DESC' - SQL Filtering: Implement a filter to remove SQL keywords from user input
Additional Security Measures:
- Apply the same fix to all similar ORDER BY clauses in the codebase
- Implement centralized input validation for all sorting parameters
- Add security unit tests for SQL injection prevention
- Consider implementing a database abstraction layer with built-in security controls
- Conduct security code review for similar interpolation patterns in other XML mapper files
