Skip to content

Red-team your own database agent

Español: es/REDTEAM.md

Experimental: not covered by the 1.x stability guarantee (see STABILITY.md); it may change in a minor release.

Responsible use, first

  • Defensive use only, against systems you own. Do not point this at a server or a database that belongs to someone else.
  • Use a disposable database. The attacks include DROP TABLE, DELETE, COPY ... TO and pg_read_file. Against a server with no guard they work.
  • It refuses to send anything unless the database has the marker table made by redteam setup, and setup refuses to touch a database that already has tables with its names. This keeps the attacks off real data.
  • redteam mcp starts the command you put after -- with your own privileges. Only pass commands you trust.
  • If it finds a weakness in someone else's project, report it to them privately. Do not publish it.

What it does

It takes the benchmark attacks and the legitimate queries that match your database's dialect, and sends them to the SQL tool of your MCP server.

export URL="postgresql+psycopg://user:pass@localhost/disposable"
sqlguardllm redteam setup --db "$URL"
sqlguardllm redteam mcp --db "$URL" --json report.json --badge badge.json \
  -- npx -y @bytebase/dbhub --transport stdio --dsn "$URL"
sqlguardllm redteam report report.json

Needs pip install "sqlguardllm[mcp]". Supported databases: PostgreSQL and SQLite.

How a verdict is reached

Step What happens
Control run Each case runs directly on the database inside a transaction that is rolled back. A legitimate query the database itself rejects is left out of the false-positive count. An attack the database would not run (a missing privilege, a disabled extension) is left out of the bypass count. So "blocked" only means the guard stopped something that would have worked. The excluded ids are listed in the report.
Verdict A tool call that does not come back as an error accepted the SQL.
Evidence A canary value in the output, or a fixture table that changed after an attack. The database is restored before the next case, so one attack cannot hide another.

The numbers are per dialect. The corpus has 69 attacks across many dialects, so a PostgreSQL run uses the PostgreSQL ones, not all 69. The report says how many ran.

Reading the result

bypass 0/17 · FP 0/19

bypass 0/17 means none of 17 effective attacks was accepted. FP 0/19 means no legitimate query was refused. The exit code is 0 when nothing got through and 1 when an attack was accepted, changed a fixture table or leaked a canary. It is 2 for usage errors, including a server that does not start, which is never read as a verdict.

The JSON follows the benchmark report schema and adds a redteam block with the dialect, the tool, the canary leaks, the attacks that changed the database and the excluded cases. The command you passed after -- is never written to the report: use --name to label the server.

Measured on dbhub

Checked on 2026-12-03 against dbhub (npx -y @bytebase/dbhub --transport stdio) on PostgreSQL, 14 effective attacks and 18 legitimate queries:

Setup Attacks accepted Legitimate refused Left a trace
dbhub alone 13/14 0/18 4 attacks changed the database (DROP, DELETE, a stacked DELETE, a DELETE in a CTE), 5 leaked a canary
dbhub behind sqlguardllm proxy 0/14 0/18 none

This is a test of the setup above, not a statement about dbhub: it ran with default settings and a database user that could write. The test is tests/engines/test_redteam_dbhub.py. It is not part of the default CI: the active red-team modules are excluded from default collection (#308). Run it by naming the file, with SQLGUARD_PROXY_UPSTREAMS=1 and SQLGUARD_PG_URL set.

Limits

  • It judges the tool's reply. A server that reports a failure as a normal reply (not as an error) looks like it accepted the query.
  • A tool that is not found automatically needs --tool NAME. Tools that only explain or validate SQL are skipped.
  • Only the SQL tool is tested. Prompt-injection through query results is not in this first slice.
  • HTTP endpoints and an agent mode that tries to make your own agent write the attacks are follow-ups of #219.