SQLmap Basics: Test Your Own Web App for SQL Injection (Free)


We have already explained how SQL injection works. Now let us use the tool professionals reach for when they test for it: SQLmap. It is free, open-source, and preinstalled on Kali Linux. It automates finding and exploiting SQL injection — which is exactly why you must only ever point it at systems you own or have written permission to test.

What SQLmap does

Manually testing every input field for SQL injection is slow. SQLmap automates it: you give it a URL with a parameter, and it probes that parameter with hundreds of payloads, figures out which injection technique works (boolean-based, time-based, error-based, UNION-based, and more), and then lets you extract data from the database — if the bug is real.

Setting up a legal target

Never run SQLmap against a live website you do not own. Set up a deliberately vulnerable app in your own lab instead. OWASP Juice Shop and DVWA (Damn Vulnerable Web Application) both run locally in a virtual machine or container and exist for exactly this purpose. That is your target. Everything below assumes a local lab URL.

Your first scan

Start with a simple detection scan against one parameter.

sqlmap -u "http://localhost:3000/product?id=1" --batch

SQLmap will ask a few questions unless you pass –batch, which accepts the defaults. Watch the output: it tests the id parameter, reports whether it looks injectable, and names the database type it detected (for example, MySQL or SQLite).

Going deeper — carefully

Once SQLmap confirms a parameter is injectable, you can explore the database structure.

sqlmap -u "http://localhost:3000/product?id=1" --dbs --batch
sqlmap -u "http://localhost:3000/product?id=1" -D shopdb --tables --batch
sqlmap -u "http://localhost:3000/product?id=1" -D shopdb -T users --columns --batch

Each flag narrows the target: –dbs lists databases, -D picks one, –tables lists its tables, -T picks a table, –columns lists its columns. Dumping actual rows with –dump is possible, but in your own lab keep it to a table you created — the point is learning the technique, not hoarding data.

Reading the results like a defender

  • If a parameter is injectable, the application is building SQL queries by gluing user input into the query string. The fix is parameterized queries (prepared statements) — never string concatenation.
  • If SQLmap identifies the database version, that is information leakage the app should not reveal.
  • If –dbs works, the database user has far more privilege than a web app needs. Apply least privilege: the app’s database account should only touch its own database.

Common beginner mistakes

  • Scanning the wrong target. Double-check the URL. One typo can send SQLmap at a real site, which is unauthorized testing.
  • Running with –risk=3 –level=5 on day one. Higher risk and level settings send aggressive payloads that can corrupt or slow a database. Keep defaults while learning.
  • Forgetting –batch in scripts. Without it, SQLmap stops to ask questions and your automated run hangs.

Why learn this at all

SQL injection has topped vulnerability lists for decades because developers keep building queries the unsafe way. Knowing how SQLmap finds the bug makes you the person who can explain the fix in a bug report or a code review — and that is a skill companies pay for. Only test systems you own or have written permission to test.

Comments

Popular Posts