Nmap smb-enum-sessions NSE Script


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

Script Description


The smb-enum-sessions.nse script enumerates the users logged into a system either locally or through an SMB share. The local users can be logged on either physically on the machine, or through a terminal services session. Connections to a SMB share are, for example, people connected to fileshares or making RPC calls. Nmap's connection will also show up, and is generally identified by the one that connected "0 seconds ago".

From the perspective of a penetration tester, the SMB Sessions is probably the most useful part of this program, especially because it doesn't require a high level of access. On, for example, a file server, there might be a dozen or more users connected at the same time. Based on the usernames, it might tell the tester what types of files are stored on the share.

Since the IP they're connected from and the account is revealed, the information here can also provide extra targets to test, as well as a username that's likely valid on that target. Additionally, since a strong username to ip correlation is given, it can be a boost to a social engineering attack.

Enumerating the logged in users is done by reading the remote registry (and therefore won't work against Vista, which disables it by default). Keys stored under HKEY_USERS are SIDs that represent the connected users, and those SIDs can be converted to proper names by using the lsar.LsaLookupSids function. Doing this requires any access higher than anonymous; guests, users, or administrators are all able to perform this request on Windows 2000, XP, 2003, and Vista.

Enumerating SMB connections is done using the srvsvc.netsessenum function, which returns the usernames that are logged in, when they logged in, and how long they've been idle for. The level of access required for this varies between Windows versions, but in Windows 2000 anybody (including the anonymous account) can access this, and in Windows 2003 a user or administrator account is required.

I learned the idea and technique for this from Sysinternals' tool, PsLoggedOn.exe. I (Ron Bowes) use similar function calls to what they use (although I didn't use their source), so thanks go out to them. Thanks also to Matt Gardenghi, for requesting this script.

WARNING: I have experienced crashes in regsvc.exe while making registry calls against a fully patched Windows 2000 system; I've fixed the issue that caused it, but there's no guarantee that it (or a similar vuln in the same code) won't show up again. Since the process automatically restarts, it doesn't negatively impact the system, besides showing a message box to the user.

Smb-enum-sessions NSE Script Arguments


This is a full list of arguments supported by the smb-enum-sessions.nse script:

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.

- - -
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-enum-sessions --script-args smbdomain=value,smbhash=value <target>

Smb-enum-sessions NSE Script Example Usage


Here's an example of how to use the smb-enum-sessions.nse script:

nmap --script smb-enum-sessions.nse -p445 <host>

sudo nmap -sU -sS --script smb-enum-sessions.nse -p U:137,T:139 <host>

Smb-enum-sessions NSE Script Example Output


Here's a sample output from the smb-enum-sessions.nse script:

Host script results:
|  smb-enum-sessions:
|  Users logged in:
|  |  TESTBOX\Administrator since 2008-10-21 08:17:14
|  |_ DOMAIN\rbowes since 2008-10-20 09:03:23
|  Active SMB Sessions:
|_ |_ ADMINISTRATOR is connected from 10.100.254.138 for [just logged in, it's probably you], idle for [not idle]

Smb-enum-sessions 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


  • Ron Bowes

References


See Also


Related NSE scripts to the smb-enum-sessions.nse script:

Visit Nmap NSE Library for more scripts.

The smb-enum-sessions.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.

MSRPC: Lookup failed


Here is a relevant code snippet related to the "MSRPC: Lookup failed" error message:

223:	
224:	        local status, lookupsids2_result = msrpc.lsa_lookupsids2(smbstate, openpolicy2_result['policy_handle'], {elements[i]['name']})
225:	
226:	        if(status == false) then
227:	          -- It may not succeed, if it doesn't that's ok
228:	          stdnse.debug3("MSRPC: Lookup failed")
229:	        else
230:	          -- Create the result array
231:	          local result = {}
232:	          result['changed_date'] = elements[i]['changed_date']
233:	          result['rid'] = rid

warning'] = "Couldn


Here is a relevant code snippet related to the "warning'] = "Couldn" error message:

274:	
275:	  -- Enumerate the logged in users
276:	  local logged_in = {}
277:	  local status1, users = winreg_enum_rids(host)
278:	  if(status1 == false) then
279:	    logged_in['warning'] = "Couldn't enumerate login sessions: " .. users
280:	  else
281:	    logged_in['name'] = "Users logged in"
282:	    if(#users == 0) then
283:	      table.insert(response, "<nobody>")
284:	    else

warning'] = "Couldn


Here is a relevant code snippet related to the "warning'] = "Couldn" error message:

293:	
294:	  -- Get the connected sessions
295:	  local sessions_output = {}
296:	  local status2, sessions = srvsvc_enum_sessions(host)
297:	  if(status2 == false) then
298:	    sessions_output['warning'] = "Couldn't enumerate SMB sessions: " .. sessions
299:	  else
300:	    sessions_output['name'] = "Active SMB sessions"
301:	    if(#sessions == 0) then
302:	      table.insert(sessions_output, "<none>")
303:	    else

Version


This page has been created based on Nmap version 7.92.

Go back to menu.