Web Server and SQL Injection Scanning with Nikto and sqlmap

6 min read188 courses on OnlySecurity

Scanners do the repetitive part of web testing: they ask a server thousands of questions and report the answers that look wrong. Nikto does that for web servers, and sqlmap for one class of bug, SQL injection. Both are loud, and neither replaces understanding the application. Test only networks and systems you own or are authorised to assess.

What a scanner can and cannot find

A scanner finds what it has a rule for. Nikto’s test database is a long list of fixed requests, each paired with a string or status it expects back, such as a known default file, an admin console or a version banner. It suits stale software, forgotten files and weak configuration. It cannot notice that one user can read another user’s invoice, or judge whether a “found” file matters. MITRE tracks this activity as T1595.002, Vulnerability Scanning, which harvests software and version information from banners and ports, and the exploitation that follows as T1190, Exploit Public-Facing Application.

sqlmap is narrower and deeper. It takes one request, changes one parameter at a time, compares the responses and tries to prove a SQL injection. Unless told to crawl (--crawl) or parse forms (--forms), it tests only the requests you give it, so a form behind a login stays invisible until you hand over a logged-in request.

Lab setup

OWASP Juice Shop is an intentionally insecure shop. Run your own copy, not the public demo; its README gives a container command that binds to the loopback interface only: docker run --rm -p 127.0.0.1:3000:3000 bkimminich/juice-shop. In the v20.4.0 source, routes/search.ts puts the q parameter straight into its SQL string, and routes/login.ts does the same with the email field, so both are injectable by design.

Nikto: broad and noisy

Nikto, maintained by Chris Sullo, runs from the program/ folder of its repository. You give it a host with -h (short for -host), a port with -p and -ssl to force TLS. -output writes a report in the -Format you set: csv, json, htm, txt or xml.

Do not call it stealthy: its own documentation says it is obvious in log files. A full run sends thousands of requests for paths that do not exist, from one address. In 2.6.1 the default User-Agent is a fixed Chrome string, not a Nikto name, and -evasion R picks a random one per request, so do not rely on the agent string to spot it. -Tuning narrows the database tests by category (2 misconfiguration and default files, 3 information disclosure, b software identification, 9 SQL injection; x excludes the categories after it), and -Pause waits between tests.

Reading Nikto output and false positives

Each finding is a line beginning with +. Treat it as a lead. Common noise:

  1. A server that answers 200 OK for pages that do not exist makes Nikto’s “not found” guess unreliable. Juice Shop does this, returning its index.html for paths outside /api and /rest. -404code and -404string tell Nikto which status codes or body text mean a miss, so expect false findings from the command below unless you add -404string with text from your own index page. -no404, still in the 2.6.1 help, is no longer accepted.
  2. A version string in a Server header gives an “outdated” finding that may be wrong, because distributions patch software without changing the number.
  3. A matched file name does not mean the file holds anything sensitive.

Verify each line by hand.

sqlmap: depth and the cost of risk

sqlmap takes a URL with -u, a POST body with --data and a parameter to test with -p. For anything with cookies, headers or JSON, save the raw request from Burp or ZAP to a file and load it with -r. That keeps authentication and content type as the browser sent them; --force-ssl covers HTTPS. --batch answers every prompt with the default, --technique picks injection types from the letters BEUSTQ (boolean, error, union, stacked, time, inline queries), and --proxy sends traffic through your intercepting proxy so you can watch it.

--level (1 to 5, default 1) controls how many payloads and injection points are tried: level 2 adds the Cookie header, level 3 User-Agent and Referer. --risk (1 to 3, default 1) controls how dangerous they may be. The sqlmap wiki says risk 2 adds heavy time-based queries and risk 3 OR-based tests, and that against an UPDATE statement an OR-based payload can change every row in a table. So keep --risk at 1 on anything that holds real data and never raise it on production.

--dbs lists the databases the account can see. On SQLite, which Juice Shop uses, sqlmap’s own plugin says this is not possible and to use --tables, a lab-only step. Stop once the issue is proved.

Commands

Checked against Nikto 2.6.1 (source at tag 2.6.1, and its wiki) and sqlmap 1.10.11 (source at tag 1.10.11). Run ./nikto.pl -Help and python3 sqlmap.py -hh on your own copy.

cd nikto/program
./nikto.pl -h 127.0.0.1 -p 3000 -Tuning 23b -Format json -output nikto-lab.json
./nikto.pl -h 127.0.0.1 -p 3000 -useproxy http://127.0.0.1:8080

cd sqlmap
python3 sqlmap.py -u "http://127.0.0.1:3000/rest/products/search?q=apple" -p q --batch --tables
python3 sqlmap.py -r login.req --batch --level 2 --risk 1 --technique BE --proxy http://127.0.0.1:8080
  1. -useproxy uses the proxy set in nikto.conf or the address given as its argument.
  2. login.req is a request saved from your proxy for POST /rest/user/login. sqlmap tests the JSON fields in it.

Detection and defence

On the server, a scanner shows as a burst of requests from one address, many for paths that return 404 or have unusual names. Apache’s standard combined log format records the request line, status and User-Agent, but not the POST body, so a POST injection needs application or WAF logging to be visible (mod_log_config). sqlmap’s default agent in 1.10.11 is sqlmap/1.10.11#stable (https://sqlmap.org), but --random-agent replaces it and a request loaded with -r keeps the browser’s own, so treat the string as a hint. Time-based tests show as responses about five seconds slower than their neighbours, and error-based tests as repeated database errors in the application log.

A web application firewall can block many known payloads and rate-limit a noisy client. MITRE lists it under M1050, Exploit Protection for T1190, but it does not fix the flaw: sqlmap ships --tamper scripts that rewrite payloads, and a patient tester can slow down. Treat a WAF as a second layer.

The real fix is in the code. The OWASP SQL Injection Prevention Cheat Sheet names parameterised queries as the preferred pattern, with a strict allow-list for table names, column names and sort direction, which cannot be bound, and says manual escaping is strongly discouraged. Validation complements binding and does not replace it. Give the application’s database account only the rights it needs, never DBA or admin rights, and run the DBMS under a restricted operating system account. Even a missed injection then reads and changes less.

Reduce what scanners learn: Apache’s ServerTokens Prod limits the Server header to the product name (core), nginx’s server_tokens off removes the version (ngx_http_core_module), and removing default and sample files leaves Nikto less to find. Apache’s documentation warns this alone does not make a server more secure. The Mastering Offensive SQL Injection: Exploitation and Advanced Attack Techniques course covers exploitation, WAF evasion and the defences that stop it, and the ZAP with OWASP Juice Shop: Web Application Security Testing course covers testing with an intercepting proxy.

Where to go next

Take the Mastering Offensive SQL Injection: Exploitation and Advanced Attack Techniques course for manual injection, filter bypass and data extraction beyond what sqlmap automates. Related: XSS and CSP and Burp extensions. For the wider workflow from first scan to report, see Penetration Testing Field Notes.

This article replaces the KSEC ARK notes first published in 2015.

More from this author