Nmap smb-vuln-cve-2017-7494 NSE Script


This page contains detailed information about how to use the smb-vuln-cve-2017-7494 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/smb-vuln-cve-2017-7494.nse
Script categories: vuln, intrusive
Target service / protocol: smb, netbios, tcp, udp
Target network port(s): 137, 139, 445
List of CVEs: CVE-2017-7494

Script Description


The smb-vuln-cve-2017-7494.nse script checks if target machines are vulnerable to the arbitrary shared library load vulnerability CVE-2017-7494.

Unpatched versions of Samba from 3.5.0 to 4.4.13, and versions prior to 4.5.10 and 4.6.4 are affected by a vulnerability that allows remote code execution, allowing a malicious client to upload a shared library to a writable share, and then cause the server to load and execute it.

The script does not scan the version numbers by default as the patches released for the mainstream Linux distributions do not change the version numbers.

The script checks the preconditions for the exploit to happen:

1) If the argument check-version is applied, the script will ONLY check services running potentially vulnerable versions of Samba, and run the exploit against those services. This is useful if you wish to scan a group of hosts quickly for the vulnerability based on the version number. However, because of their version number, some patched versions may still show up as likely vulnerable. Here, we use smb.get_os(host) to do versioning of the Samba version and compare it to see if it is a known vulnerable version of Samba. Note that this check is not conclusive: See 2,3,4

2) Whether there exists writable shares for the execution of the script. We must be able to write to a file to the share for the exploit to take place. We hence enumerate the shares using smb.share_find_writable(host) which returns the main_name, main_path and a list of writable shares.

3) Whether the workaround (disabling of named pipes) was applied. When "nt pipe support = no" is configured on the host, the service would not be exploitable. Hence, we check whether this is configured on the host using smb.share_get_details(host, 'IPC$'). The error returned would be "NT_STATUS_ACCESS_DENIED" if the workaround is applied.

4) Whether we can invoke the payloads from the shares. Using payloads from Metasploit, we upload the library files to the writable share obtained from 2). We then make a named pipe request using NT_CREATE_ANDX_REQUEST to the actual local filepath and if the payload executes, the status return will be false. Note that only Linux_x86 and Linux_x64 payloads are tested in this script.

This script is based on the metasploit module written by hdm.

References:

Smb-vuln-cve-2017-7494 NSE Script Arguments


This is a full list of arguments supported by the smb-vuln-cve-2017-7494.nse script:

smb-vuln-cve-2017-7494.check-version

Check only the version numbers the target's Samba service. Default: false

smbdomain

The domain to log in with. If you aren't in a domain environment, then anything will (should?) be accepted by the server.

smbhash

A 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.

smbnoguest

Use to disable usage of the 'guest' account.

smbpassword

The 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.

smbtype

The 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 use v2 or lmv2 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 to v1 or lm, which are less secure but more compatible. For information, see smbauth.lua.

smbusername

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.

randomseed

Set to a value to change the filenames/service names that are randomly generated.

smbbasic

Forces 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.

smbsign

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 in smbauth.lua.

vulns.short

If set, vulnerabilities will be output in short format, a single line consisting of the host's target name or IP, the state, and either the CVE ID or the title of the vulnerability. Does not affect XML output.

vulns.showall

If set, the library will show and report all the registered vulnerabilities which includes the NOT VULNERABLE ones. By default the library will only report the VULNERABLE entries: VULNERABLE, LIKELY VULNERABLE, VULNERABLE (DoS) and VULNERABLE (Exploitable). This argument affects the following functions: vulns.Report.make_output(): the default output function for portule/hostrule scripts. vulns.make_output(): the default output function for postrule scripts. vulns.format_vuln() and vulns.format_vuln_table() functions.

- - -
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=smb-vuln-cve-2017-7494 --script-args smb-vuln-cve-2017-7494.check-version=value,smbdomain=value <target>

Smb-vuln-cve-2017-7494 NSE Script Example Usage


Here's an example of how to use the smb-vuln-cve-2017-7494.nse script:

nmap --script smb-vuln-cve-2017-7494 -p 445 <target>

nmap --script smb-vuln-cve-2017-7494 --script-args smb-vuln-cve-2017-7494.check-version -p445 <target>

Smb-vuln-cve-2017-7494 NSE Script Example Output


Here's a sample output from the smb-vuln-cve-2017-7494.nse script:

PORT    STATE SERVICE
445/tcp open  microsoft-ds
MAC Address: 00:0C:29:16:04:53 (VMware)

| smb-vuln-cve-2017-7494:
|   VULNERABLE:
|   SAMBA Remote Code Execution from Writable Share
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-7494
|     Risk factor: HIGH  CVSSv3: 7.5 (HIGH) (CVSS:3.0/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H)
|       All versions of Samba from 3.5.0 onwards are vulnerable to a remote
|       code execution vulnerability, allowing a malicious client to upload a
|       shared library to a writable share, and then cause the server to load
|       and execute it.
|
|     Disclosure date: 2017-05-24
|     Check results:
|       Samba Version: 4.3.9-Ubuntu
|       Writable share found.
|        Name: \\192.168.15.131\test
|       Exploitation of CVE-2017-7494 succeeded!
|     Extra information:
|       All writable shares:
|        Name: \\192.168.15.131\test
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7494
|_      https://www.samba.org/samba/security/CVE-2017-7494.html

Smb-vuln-cve-2017-7494 NSE Script Example XML Output


Here's a sample XML output from the smb-vuln-cve-2017-7494.nse script produced by providing the -oX <file> Nmap option:

 <table key="CVE-2017-7494">
 <elem key="title">SAMBA Remote Code Execution from Writable Share</elem>
 <elem key="state">VULNERABLE</elem>
 <table key="ids">
 <elem>CVE:CVE-2017-7494</elem>
 </table>
 <table key="scores">
 <elem key="CVSSv3">7.5 (HIGH) (CVSS:3.0/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H)</elem>
 </table>
 <table key="description">
 <elem>All versions of Samba from 3.5.0 onwards are vulnerable to a remote&#xa;code execution vulnerability, allowing a malicious client to upload a&#xa;shared library to a writable share, and then cause the server to load&#xa;and execute it.&#xa;</elem>
 </table>
 <table key="dates">
 <table key="disclosure">
 <elem key="year">2017</elem>
 <elem key="day">24</elem>
 <elem key="month">05</elem>
 </table>
 </table>
 <elem key="disclosure">2017-05-24</elem>
 <table key="check_results">
 <elem>Samba Version: 4.3.9-Ubuntu</elem>
 <elem>Writable share found. &#xa; Name: \\192.168.15.131\test</elem>
 <elem>Exploitation of CVE-2017-7494 succeeded!</elem>
 </table>
 <table key="extra_info">
 <elem>All writable shares:</elem>
 <elem> Name: \\192.168.15.131\test</elem>
 </table>
 <table key="refs">
 <elem>https://www.samba.org/samba/security/CVE-2017-7494.html</elem>
 <elem>https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7494</elem>
 </table>
 </table>

Author


  • Wong Wai Tuck

References


See Also


Related NSE scripts to the smb-vuln-cve-2017-7494.nse script:

Visit Nmap NSE Library for more scripts.

The smb-vuln-cve-2017-7494.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 connect to IPC$


Here is a relevant code snippet related to the "Could not connect to IPC$" error message:

385:	        local curr_path = pipe_formats[j]
386:	        -- make an simple SMB connection to IPC$
387:	        local status, smbstate = smb.start_ex(host, true, true, "\\\" ..
388:	          host.ip .. "\\IPC$", nil, nil, nil)
389:	        if not status then
390:	          stdnse.debug1("Could not connect to IPC$")
391:	        else
392:	          local overrides = {}
393:	          -- perform NT Create NX Request on candidate file paths
394:	          overrides['file_create_disposition'] = 0x1    -- FILE_OPEN
395:	          overrides['file_create_security_flags'] = 0x0 -- No dynamic tracking, no security context

File written to remote share, but unable to execute payload either due to unknown actual path, or the system may be patched.


Here is a relevant code snippet related to the "File written to remote share, but unable to execute payload either due to unknown actual path, or the system may be patched." error message:

409:	    end
410:	  end
411:	  if samba_cve.state ~= vulns.STATE.VULN and not path then
412:	    samba_cve.state = vulns.STATE.LIKELY_VULN
413:	    table.insert(samba_cve.check_results,
414:	      'File written to remote share, but unable to execute payload either due to unknown actual path, or the system may be patched.')
415:	  end
416:	end
417:	
418:	action = function(host,port)
419:	  local port = nmap.get_port_state(host,{number=smb.get_port(host),protocol='tcp'})

Either versioning failed or samba does not exist on the port!


Here is a relevant code snippet related to the "Either versioning failed or samba does not exist on the port!" error message:

468:	    -- we only want 4.3.9-Ubuntu
469:	    if string.match(result.lanmanager,"^Samba ") then
470:	      version = string.match(result.lanmanager,"^Samba (.*)")
471:	    else
472:	      return stdnse.format_output(false,
473:	        "Either versioning failed or samba does not exist on the port!")
474:	    end
475:	  end
476:	
477:	  table.insert(samba_cve.check_results,
478:	    string.format("Samba Version: %s",version))

Version


This page has been created based on Nmap version 7.92.

Go back to menu.