SQL and command injection testing
On this page
- Check first
- How do I find SQL injection from a database error?
- How do I confirm it with a true and a false condition?
- What is the least-impact proof for SQL injection?
- How do I find command injection from output and errors?
- What is the least-impact proof for command injection?
- The defender sees
- Done when
- Not covered
- Tools
- Related research
- Reviewed
- Situation
- The input list from the first hour, a test account on an application named in the scope letter, and a row we planted on the far side of any boundary we test, such as a test product in a second test organization. Every probe on this page is a read: nothing writes, deletes, dumps a table or connects out, and only the applications the scope letter names are tested.
- Goal
- One finding per injectable input, each with the error or true and false pair that showed it and a single least-impact proof.
- Outputs
- Captured on 4 Nov 2026 against the Atarus Bench Web and API lab fixture, edition
web-api-0.2, running on loopback, with one origin playing every host, renamed to the example domains and printed ashttps(the lab ran plainhttp). The capture host's user name, the one linewhoamiprinted, is renamed tobench; nothing else in that output is changed.
Check first
- The first hour input list, marked where a value may reach a database or a command: search, filter, sort and id parameters, report and file names, host fields in admin tools.
- Whether errors are verbose here, because the first probe reads the error.
- A planted row on the far side of the boundary, so the proof reads only our own data.
- The client's agreement that one
whoamiis the whole proof of a command injection, and when we stop and call. - Whether a web application firewall is in the path, since a block and a fix look alike from outside.
Steps
How do I find SQL injection from a database error?
curl -s -w '\n%{http_code}\n' -H "Authorization: Bearer $TESTER_A_TOKEN" \
"https://app.example.com/api/products?sku=SKU-0001"
curl -s -w '\n%{http_code}\n' -H "Authorization: Bearer $TESTER_A_TOKEN" \
"https://app.example.com/api/products?sku=SKU-0001%27"
Expected output
{"items":[{"id":1,"sku":"SKU-0001","name":"Lab Widget","price":"24.00"}]}
200
{"error":"database error","detail":"unrecognized token: \"'SKU-0001''\""} # <- the database's own parser rejected our quote
500
The first request is the baseline: one product, our own. The second adds a single quote (%27). A 500 carrying the database's own wording, here SQLite's unrecognized token, means the quote reached the SQL parser as code: the value was pasted into the query text. A generic error proves less, since any input check can produce one, so such a candidate goes straight to the pair in the next step.
Negative result. The quote is treated as part of a product name: a 200 with an empty list, the same answer as any other unknown sku.
Fix. Bind every value as a parameter (WHERE org = ? AND sku = ? with the values passed separately) in every query, including the ones in reports and admin tools. Return a generic error to the client and keep the database message in the server log.
How do I confirm it with a true and a false condition?
for c in "1'='1" "1'='2"; do
curl -s -G -H "Authorization: Bearer $TESTER_A_TOKEN" https://app.example.com/api/products \
--data-urlencode "sku=SKU-0001' AND '$c" | jq -c '[.items[].sku]'
done
Expected output
["SKU-0001"] # <- the true condition returns our product
[] # <- the false one returns nothing
Two requests that differ only in a condition that is always true or always false. Our product for the first and nothing for the second means the input is evaluated as SQL, and nothing but our own row was read to show it.
Negative result. Both requests return the same empty list, since neither value exists as a sku.
Why this works
The application wraps our value in quotes, so a value that closes the quote and adds AND '1'='1 leaves a valid query whose result depends on our condition.
Fix. The bound parameters above. An allowlist of the characters a sku may hold is a useful second layer, never the first.
What is the least-impact proof for SQL injection?
curl -s -G -H "Authorization: Bearer $TESTER_A_TOKEN" https://app.example.com/api/products \
--data-urlencode "sku=none' OR sku = 'SKU-0003" | jq -c '.items'
Expected output
[{"id":3,"sku":"SKU-0003","name":"Lab Sprocket","price":"12.00"}] # <- one planted row from the other test organization
SKU-0003 is the test product we planted in the second test organization. The query filters by the caller's organization and then by sku; AND binds tighter than OR, so our OR sku = 'SKU-0003' escapes the organization filter and returns one row tester-a must never see, which shows the injection and the boundary it crosses at once. We do not add UNION SELECT, list tables or count rows. The report says the query reaches every table the application's database account can read, and the client confirms that from the account's grants, not from a dump. The LiteLLM gateway flaw had this shape: a header value pasted into a SELECT.
Negative result. An empty list: the organization filter held for the planted row.
Fix. Bound parameters, and a database account that can read only the tables the application serves, so an injection that slips through reaches less. Row-level security keyed on the organization adds a check that the query text cannot remove.
How do I find command injection from output and errors?
for n in weekly.csv "weekly.csv'"; do
curl -s -G -w '%{http_code}\n' -H "Authorization: Bearer $TESTER_A_TOKEN" \
https://app.example.com/api/reports/preview --data-urlencode "name=$n"
done
Expected output
week,orders,total
2026-W43,118,4210.00
2026-W44,131,4655.00
200
/bin/sh: -c: line 0: unexpected EOF while looking for matching `'' # <- the shell parsed the file name
/bin/sh: -c: line 1: syntax error: unexpected end of file
500
The preview endpoint takes a report file name. The baseline returns the first lines of the report; the same name with one quote returns the shell's complaint about an unmatched quote and a 500, so the name was pasted into a command line that /bin/sh parsed. That error is enough, and the next step is the one proof. The two error lines are bash 3.2's wording, the capture host's /bin/sh; dash, the bench's /bin/sh, prints Syntax error: Unterminated quoted string instead.
Negative result. The quote gets the same not-found answer as any other missing file, with no shell wording.
Fix. Do not start a shell. Read the file in the application's own language, or run the program with an argument list (subprocess.run(["head", "-n", "3", "--", path]) in Python, execFile in Node) so no shell ever parses the value; the -- keeps a name that starts with - from being read as an option. Check the name against the list of reports the caller may open.
What is the least-impact proof for command injection?
curl -s -G -H "Authorization: Bearer $TESTER_A_TOKEN" https://app.example.com/api/reports/preview \
--data-urlencode 'name=weekly.csv;whoami'
Expected output
week,orders,total
2026-W43,118,4210.00
2026-W44,131,4655.00
bench # <- one harmless command, run as the application's account
One separator and one command that changes nothing: whoami prints the name of the account the application runs as, the fact the report needs. We send it once, and never a command that writes, reads another file, lists a directory, opens a connection or starts a shell. The finding names the account the shell runs as. If that account can use sudo without a password, the injection is a route to root; we ask the client rather than test it.
Negative result. The report lines and nothing after them, or the request refused because the name is not on the list of reports.
Fix. No shell, an argument list and an allowlisted name, as above. Run the application as an account with no sudo and no write access outside its own data directory, so a command that does get through reaches as little as possible.
The defender sees
The quote probes leave a database error and a shell syntax error in the application log beside the requests that caused them. A firewall running the OWASP Core Rule Set flags the true and false pair in its 942 SQL injection group and the ;whoami in its 932 command injection group. The whoami shows in process auditing (an auditd execve record, or an endpoint agent's process tree) as a child of the application server, which is worth an alert every time. If nothing logged the errors or the child process, that goes in the report beside the finding.
Done when
Every input that may reach a query or a command has had the quote probe, each candidate has a true and false pair or a shell error, and each confirmed one has one planted row or one whoami with its request saved.
Not covered
Blind time-based techniques, second-order and NoSQL injection, injection through GraphQL arguments, reading anything beyond one planted row, and any step after the proof such as a shell.