Nmap mysql-query NSE Script


This page contains detailed information about how to use the mysql-query NSE script. For list of all NSE scripts, visit the Nmap NSE Library.

Select:
Overview
Error Messages

Script Overview


Script source code: https://github.com/nmap/nmap/tree/master/scripts/mysql-query.nse
Script categories: auth, discovery, safe
Target service / protocol: mysql
Target network port(s): 3306
List of CVEs: -

Script Description


The mysql-query.nse script runs a query against a MySQL database and returns the results as a table.

Mysql-query NSE Script Arguments


This is a full list of arguments supported by the mysql-query.nse script:

mysql-query.noheaders

Do not display column headers (default: false)

mysql-query.password

(optional) the password used to authenticate to the database server

mysql-query.query

The query for which to return the results

mysql-query.username

(optional) the username used to authenticate to the database server

- - -
To use these script arguments, add them to the Nmap command line using the --script-args arg1=value,[arg2=value,..] syntax. For example:

nmap --script=mysql-query --script-args mysql-query.noheaders=value,mysql-query.password=value <target>

Mysql-query NSE Script Example Usage


Here's an example of how to use the mysql-query.nse script:

nmap -p 3306 <ip> --script mysql-query --script-args='query="<query>"[,username=<username>,password=<password>]'

Mysql-query NSE Script Example Output


Here's a sample output from the mysql-query.nse script:

PORT     STATE SERVICE
3306/tcp open  mysql
| mysql-query:
|   host       user
|   127.0.0.1  root
|   localhost  debian-sys-maint
|   localhost  root
|   ubu1110    root
|
|   Query: SELECT host, user FROM mysql.user
|_  User: root

Mysql-query NSE Script Example XML Output


There is no sample XML output for this module. However, by providing the -oX <file> option, Nmap will produce a XML output and save it in the file.xml file.

Author


  • Patrik Karlsson

References


See Also


Related NSE scripts to the mysql-query.nse script:

Visit Nmap NSE Library for more scripts.

The mysql-query.nse script may fail with the following error messages. Check for the possible causes by using the code snippets highlighted below found in the script source code. This can often times help in identifying the root cause of the problem.

Failed to connect to server


Here is a relevant code snippet related to the "Failed to connect to server" error message:

94:	  local last_error
95:	
96:	  for username, password in pairs(creds) do
97:	    local socket = nmap.new_socket()
98:	    if ( not(socket:connect(host, port)) ) then
99:	      return fail("Failed to connect to server")
100:	    end
101:	    local status, response = mysqlLogin(socket, username, password)
102:	    if ( status ) then
103:	      local status, rs = mysql.sqlQuery( socket, arg_query )
104:	      socket:close()

Version


This page has been created based on Nmap version 7.92.

Go back to menu.