local stdnse = require "stdnse" local smb = require "smb" local smb2 = require "smb2" local msrpc = require "msrpc" local bin = require "bin" local shortport = require "shortport" description = [[ Return free and total size in octets of each SMB shares ]] --- -- @args See the documentation for the smbauth library. -- -- @usage nmap -p445 --script smb-shares-size.nse -- -- @output -- Host script results: -- | smb-shares-size: -- | data: -- | FreeSize: 38495883264 -- | TotalSize: 500961574912 -- |_ IPC$: NT_STATUS_ACCESS_DENIED --- categories = {"discovery", "intrusive"} author = "Adrien Malingrey" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" portrule = shortport.service({"microsoft-ds", "netbios-ssn"}) action = function(host) local status, shares, extra local response = stdnse.output_table() -- Try and do this the good way, make a MSRPC call to get the shares stdnse.debug1("SMB: Attempting to log into the system to enumerate shares") status, shares = msrpc.enum_shares(host) if(status == false) then return stdnse.format_output(false, string.format("Couldn't enumerate shares: %s", shares)) end -- Get more information on each share for i = 1, #shares, 1 do local share = shares[i] if (share ~= nil) then local status, result = get_share_info(host, share) if (status) then response[share] = result end end end return response end TRANS2_QUERY_FS_INFORMATION = 0x0003 SMB_QUERY_FS_SIZE_INFO = 0x0103 ---Attempts to retrieve additional information about a share. Will fail unless we have -- administrative access. -- --@param host The host object. --@return Status (true or false). --@return A table of information about the share (if status is true) or an an error string (if -- status is false). function get_share_info(host, share) local status, smbstate, err local hostaddress = (host.name ~= '' and host.name) or host.ip local path = "\\\\" .. hostaddress .. "\\" .. share status, smbstate = smb.start(host) status, err = smb.negotiate_protocol(smbstate, {}) status, err = smb.start_session(smbstate, {}) status, err = smb.tree_connect(smbstate, path, {}) stdnse.debug1("SMB: Getting information for share: %s", path) local status, err = send_transaction2(smbstate, TRANS2_QUERY_FS_INFORMATION, bin.pack("