Nmap ms-sql-info NSE Script
This page contains detailed information about how to use the ms-sql-info NSE script. For list of all NSE scripts, visit the Nmap NSE Library.
Select: |
---|
Script Overview
Script source code: https://github.com/nmap/nmap/tree/master/scripts/ms-sql-info.nse
Script categories: default, discovery, safe
Target service / protocol: ms-sql-s, smb, tcp, udp
Target network port(s): 445, 1433, 1434
List of CVEs: -
Script Description
The ms-sql-info.nse script attempts to determine configuration and version information for Microsoft SQL Server instances.
SQL Server credentials required: No (will not benefit from
mssql.username
& mssql.password
).
Run criteria:
- Host script: Will always run.
- Port script: N/A
NOTE: Unlike previous versions, this script will NOT attempt to log in to SQL
Server instances. Blank passwords can be checked using the
ms-sql-empty-password
script. E.g.:
nmap -sn --script ms-sql-empty-password --script-args mssql.instance-all <host>
The script uses two means of getting version information for SQL Server instances:
- Querying the SQL Server Browser service, which runs by default on UDP port 1434 on servers that have SQL Server 2000 or later installed. However, this service may be disabled without affecting the functionality of the instances. Additionally, it provides imprecise version information.
- Sending a probe to the instance, causing the instance to respond with information including the exact version number. This is the same method that Nmap uses for service versioning; however, this script can also do the same for instances accessible via Windows named pipes, and can target all of the instances listed by the SQL Server Browser service.
In the event that the script can connect to the SQL Server Browser service
(UDP 1434) but is unable to connect directly to the instance to obtain more
accurate version information (because ports are blocked or the mssql.scanned-ports-only
argument has been used), the script will rely only upon the version number
provided by the SQL Server Browser/Monitor, which has the following limitations:
- For SQL Server 2000 and SQL Server 7.0 instances, the RTM version number is always given, regardless of any service packs or patches installed.
- For SQL Server 2005 and later, the version number will reflect the service pack installed, but the script will not be able to tell whether patches have been installed.
Where possible, the script will determine major version numbers, service pack levels and whether patches have been installed. However, in cases where particular determinations can not be made, the script will report only what can be confirmed.
NOTE: Communication with instances via named pipes depends on the smb
library. To communicate with (and possibly to discover) instances via named pipes,
the host must have at least one SMB port (e.g. TCP 445) that was scanned and
found to be open. Additionally, named pipe connections may require Windows
authentication to connect to the Windows host (via SMB) in addition to the
authentication required to connect to the SQL Server instances itself. See the
documentation and arguments for the smb
library for more information.
NOTE: By default, the ms-sql-* scripts may attempt to connect to and communicate
with ports that were not included in the port list for the Nmap scan. This can
be disabled using the mssql.scanned-ports-only
script argument.
Ms-sql-info NSE Script Arguments
This is a full list of arguments supported by the ms-sql-info.nse script:
smbdomainThe domain to log in with. If you aren't in a domain environment, then anything will (should?) be accepted by the server.
smbhashA password hash to use when logging in. This is given as a single hex string (32 characters) or a pair of hex strings (both 32 characters, optionally separated by a single character). These hashes are the LanMan or NTLM hash of the user's password, and are stored on disk or in memory. They can be retrieved from memory using the fgdump or pwdump tools.
smbnoguestUse to disable usage of the 'guest' account.
smbpasswordThe password to connect with. Be cautious with this, since some servers will lock accounts if the incorrect password is given. Although it's rare that the Administrator account can be locked out, in the off chance that it can, you could get yourself in trouble. To use a blank password, leave this parameter off altogether.
smbtypeThe type of SMB authentication to use. These are the possible options:
v1
: Sends LMv1 and NTLMv1.LMv1
: Sends LMv1 only.NTLMv1
: Sends NTLMv1 only (default).v2
: Sends LMv2 and NTLMv2.LMv2
: Sends LMv2 only.NTLMv2
: Doesn't exist; the protocol doesn't support NTLMv2 alone. The default,NTLMv1
, is a pretty decent compromise between security and compatibility. If you are paranoid, you might want to usev2
orlmv2
for this. (Actually, if you're paranoid, you should be avoiding this protocol altogether!). If you're using an extremely old system, you might need to set this tov1
orlm
, which are less secure but more compatible. For information, seesmbauth.lua
.
The SMB username to log in with. The forms "DOMAIN\username" and "username@DOMAIN" are not understood. To set a domain, use the smbdomain
argument.
Set to a value to change the filenames/service names that are randomly generated.
smbbasicForces the authentication to use basic security, as opposed to "extended security". Against most modern systems, extended security should work, but there may be cases where you want to force basic. There's a chance that you'll get better results for enumerating users if you turn on basic authentication.
smbport
Override the default port choice. If smbport
is open, it's used. It's assumed to be the same protocol as port 445, not port 139. Since it probably isn't possible to change Windows' ports normally, this is mostly useful if you're bouncing through a relay or something.
Controls whether or not server signatures are checked in SMB packets. By default, on Windows, server signatures aren't enabled or required. By default, this library will always sign packets if it knows how, and will check signatures if the server says to. Possible values are:
force
: Always check server signatures, even if server says it doesn't support them (will Probably fail, but is technically more secure).negotiate
: [default] Use signatures if server supports them.ignore
: Never check server signatures. Not recommended.disable
: Don't send signatures, at all, and don't check the server's. not recommended. More information on signatures can be found insmbauth.lua
.
The domain against which to perform integrated authentication. When set, the scripts assume integrated authentication should be performed, rather than the default sql login.
mssql.instance-allTargets all SQL server instances discovered through the browser service.
mssql.instance-nameThe name of the instance to connect to.
mssql.instance-portThe port of the instance to connect to.
mssql.password
The password for mssql.username
. If this argument is not given but mssql.username
, a blank password is used.
The protocol to use to connect to the instance. The protocol may be either NP
,Named Pipes
or TCP
.
If set, the script will only connect to ports that were included in the Nmap scan. This may result in instances not being discovered, particularly if UDP port 1434 is not included. Additionally, instances that are found to be running on ports that were not scanned (e.g. if 1434/udp is in the scan and the SQL Server Browser service on that port reports an instance listening on 43210/tcp, which was not scanned) will be reported but will not be stored for use by other ms-sql-* scripts.
mssql.timeout
How long to wait for SQL responses. This is a number followed by ms
for milliseconds, s
for seconds, m
for minutes, or h
for hours. Default: 30s
.
The username to use to connect to SQL Server instances. This username is used by scripts taking actions that require authentication (e.g. ms-sql-query
) This username (and its associated password) takes precedence over any credentials discovered by the ms-sql-brute
and ms-sql-empty-password
scripts.
- - -
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=ms-sql-info --script-args smbdomain=value,smbhash=value <target>
Ms-sql-info NSE Script Example Usage
Here's an example of how to use the ms-sql-info.nse script:
nmap -p 445 --script ms-sql-info <host>
nmap -p 1433 --script ms-sql-info --script-args mssql.instance-port=1433 <host>
Ms-sql-info NSE Script Example Output
Here's a sample output from the ms-sql-info.nse script:
| ms-sql-info:
| Windows server name: WINXP
| 192.168.100.128\PROD:
| Instance name: PROD
| Version:
| name: Microsoft SQL Server 2000 SP3
| number: 8.00.760
| Product: Microsoft SQL Server 2000
| Service pack level: SP3
| Post-SP patches applied: No
| TCP port: 1278
| Named pipe: \\192.168.100.128\pipe\MSSQL$PROD\sql\query
| Clustered: No
| 192.168.100.128\SQLFIREWALLED:
| Instance name: SQLFIREWALLED
| Version:
| name: Microsoft SQL Server 2008 RTM
| Product: Microsoft SQL Server 2008
| Service pack level: RTM
| TCP port: 4343
| Clustered: No
| \\192.168.100.128\pipe\sql\query:
| Version:
| name: Microsoft SQL Server 2005 SP3+
| number: 9.00.4053
| Product: Microsoft SQL Server 2005
| Service pack level: SP3
| Post-SP patches applied: Yes
|_ Named pipe: \\192.168.100.128\pipe\sql\query
Ms-sql-info NSE Script Example XML Output
Here's a sample XML output from the ms-sql-info.nse script produced by providing the -oX <file>
Nmap option:
<elem key="Windows server name">WINXP</elem>
<table key="192.168.100.128\PROD">
<elem key="Instance name">PROD</elem>
<table key="Version">
<elem key="name">Microsoft SQL Server 2000 SP3</elem>
<elem key="number">8.00.760</elem>
<elem key="Product">Microsoft SQL Server 2000</elem>
<elem key="Service pack level">SP3</elem>
<elem key="Post-SP patches applied">No</elem>
</table>
<elem key="TCP port">1278</elem>
<elem key="Named pipe">\\192.168.100.128\pipe\MSSQL$PROD\sql\query</elem>
<elem key="Clustered">No</elem>
</table>
<table key="192.168.100.128\SQLFIREWALLED">
<elem key="Instance name">SQLFIREWALLED</elem>
<table key="Version">
<elem key="name">Microsoft SQL Server 2008 RTM</elem>
<elem key="Product">Microsoft SQL Server 2008</elem>
<elem key="Service pack level">RTM</elem>
</table>
<elem key="TCP port">4343</elem>
<elem key="Clustered">No</elem>
</table>
<table key="\\192.168.100.128\pipe\sql\query">
<table key="Version">
<elem key="name">Microsoft SQL Server 2005 SP3+</elem>
<elem key="number">9.00.4053</elem>
<elem key="Product">Microsoft SQL Server 2005</elem>
<elem key="Service pack level">SP3</elem>
<elem key="Post-SP patches applied">Yes</elem>
</table>
<elem key="Named pipe">\\192.168.100.128\pipe\sql\query</elem>
</table>
Authors
- Chris Woodbury
- Thomas Buchanan
References
- https://nmap.org/nsedoc/scripts/ms-sql-info.html
- https://github.com/nmap/nmap/tree/master/scripts/ms-sql-info.nse
See Also
Related NSE scripts to the ms-sql-info.nse script:
- msrpc-enum.nse
- ms-sql-brute.nse
- ms-sql-config.nse
- ms-sql-dac.nse
- ms-sql-dump-hashes.nse
- ms-sql-empty-password.nse
- ms-sql-hasdbaccess.nse
- ms-sql-ntlm-info.nse
- ms-sql-query.nse
- ms-sql-tables.nse
- ms-sql-xp-cmdshell.nse
Visit Nmap NSE Library for more scripts.
The ms-sql-info.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.
Could not retrieve SSNetLib version for %s.
Here is a relevant code snippet related to the "Could not retrieve SSNetLib version for %s." error message:
221: foundVersion, ssnetlibVersion = mssql.Helper.GetInstanceVersion( instance )
222: if ( foundVersion ) then
223: instance.version = ssnetlibVersion
224: stdnse.debug1("Retrieved SSNetLib version for %s.", instance:GetName() )
225: else
226: stdnse.debug1("Could not retrieve SSNetLib version for %s.", instance:GetName() )
227: end
228: end
229:
230: -- If we didn't get a version from SSNetLib, give the user some detail as to why
231: if ( not foundVersion ) then
Version info could not be retrieved for %s.
Here is a relevant code snippet related to the "Version info could not be retrieved for %s." error message:
233: stdnse.debug1("%s has no network protocols enabled.", instance:GetName() )
234: end
235: if ( instance.version ) then
236: stdnse.debug1("Using version number from SSRP response for %s.", instance:GetName() )
237: else
238: stdnse.debug1("Version info could not be retrieved for %s.", instance:GetName() )
239: end
240: end
241:
242: -- Give some version info back to Nmap
243: if ( instance.port and instance.version ) then
Version
This page has been created based on Nmap version 7.92.
Go back to menu.