Web security

sqlmap for Beginners: Testing SQL Injection in a Lab

sqlmap automates the checking and exploitation of SQL injection. It saves time, but it does not replace understanding, so learn the flaw first with SQL injection explained. Run it only against your own lab or systems you have written permission to test. Pointing it at a live site without permission is illegal and can damage data.

Set Up a Target

Use DVWA in a virtual machine and set its security level to low. In the examples, 192.168.56.20 is the lab server. DVWA needs a login, so copy your session cookie from your browser (or from Burp Suite).

Test One Parameter

  • sqlmap -u "http://192.168.56.20/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit" --cookie="PHPSESSID=YOURSESSION; security=low" --batch

--batch accepts the default answers. sqlmap reports whether the id parameter is injectable and which technique worked, such as boolean-based or time-based.

Look Around, Then Stop

  • Add --dbs to list databases.
  • Add -D dvwa --tables to list tables in one database.
  • Add -D dvwa -T users --columns to list columns.
  • Dump data only from lab databases you created.

In a real engagement you stop as soon as you prove the flaw, and the report says what could be reached. You do not copy customer data.

Settings That Matter

  • --level and --risk make tests broader and riskier. Keep the defaults until you know why you need more.
  • --delay 1 slows requests.
  • --random-agent changes the user agent, which helps in a lab where you study detection.
  • Save the output directory; it holds a log of every request.

Then Fix It

The fix is parameterized queries, not a filter. Read the defense side in SQL injection explained and the report advice in how to write a penetration testing report. The skill is taught in our Application Security course.

Sources and Further Reading

Want to test and report on a vulnerable web app with a trainer? Book free trial classes. Contact us or call +91 86868 92922.

Start Your Cyber Security Career

Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.

Book Free Trial Classes

By submitting, you agree that Hacking Trainer Academy may contact you about courses by phone, WhatsApp or email. See our privacy notice and refund policy.

WhatsApp