From fd86015cde070f3e6a767deaf957940b0758c987 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 30 Aug 2018 03:25:14 +0000 Subject: [PATCH] Remove bin.lua from smb.lua --- nselib/smb.lua | 365 ++++++++++++++++++++++++------------------------- 1 file changed, 180 insertions(+), 185 deletions(-) diff --git a/nselib/smb.lua b/nselib/smb.lua index 50d4710c3..c6f1bf2af 100644 --- a/nselib/smb.lua +++ b/nselib/smb.lua @@ -122,7 +122,6 @@ -- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html ----------------------------------------------------------------------- local asn1 = require "asn1" -local bin = require "bin" local coroutine = require "coroutine" local datetime = require "datetime" local io = require "io" @@ -551,7 +550,7 @@ function start_netbios(host, port, name) -- Some debug information stdnse.debug1("SMB: Trying to start NetBIOS session with name = '%s'", name) -- Request a NetBIOS session - local session_request = bin.pack(">CCSzz", + local session_request = string.pack(">BBI2zz", 0x81, -- session request 0x00, -- flags 0x44, -- length @@ -583,7 +582,7 @@ function start_netbios(host, port, name) socket:close() return false, "SMB: Failed to close socket: " .. result end - pos, result, flags, length = bin.unpack(">CCS", result) + result, flags, length, pos = string.unpack(">BBI2", result) if(result == nil or length == nil) then return false, "SMB: ERROR: Server returned less data than it was supposed to (one or more fields are missing); aborting [1]" end @@ -670,7 +669,7 @@ function smb_encode_header(smb, command, overrides) return false, string.format("SMB: ERROR: TreeID value was set to nil on host %s", smb['ip']) end - local header = bin.pack("Is4", body) repeat @@ -870,7 +869,7 @@ function smb_read(smb, read_data) -- The length of the packet is 4 bytes of big endian (for our purposes). -- The NetBIOS header is 24 bits, big endian - pos, netbios_length = bin.unpack(">I", netbios_data) + netbios_length, pos = string.unpack(">I4", netbios_data) if(netbios_length == nil) then return false, "SMB: ERROR: Server returned less data than it was supposed to (one or more fields are missing); aborting [2]" end @@ -904,33 +903,23 @@ function smb_read(smb, read_data) return false, "SMB: ERROR: Server returned invalid signature" end - -- The header is 32 bytes. - pos, header = bin.unpack(" 0 ) then - pos, smb['security_blob'] = bin.unpack(" 11 ) then - local pos, oid = bin.unpack(">A6", smb['security_blob'], 5) + local oid, pos = string.unpack(">c6", smb['security_blob'], 5) sp_nego = ( oid == "\x2b\x06\x01\x05\x05\x02" or oid == "\x06\x06\x2b\x06\x01\x05" ) -- check for SPNEGO OID 1.3.6.1.5.5.2 end @@ -1387,8 +1369,8 @@ local function start_session_extended(smb, log_errors, overrides) if ( sp_nego ) then local enc = asn1.ASN1Encoder:new() - local mechtype = enc:encode( { type = 'A0', value = enc:encode( { type = '30', value = enc:encode( { type = '06', value = bin.pack("H", "2b06010401823702020a") } ) } ) } ) - local oid = enc:encode( { type = '06', value = bin.pack("H", "2b0601050502") } ) + local mechtype = enc:encode( { type = 'A0', value = enc:encode( { type = '30', value = enc:encode( { type = '06', value = stdnse.fromhex("2b06010401823702020a") } ) } ) } ) + local oid = enc:encode( { type = '06', value = stdnse.fromhex("2b0601050502") } ) security_blob = enc:encode(security_blob) security_blob = enc:encode( { type = 'A2', value = security_blob } ) @@ -1426,15 +1408,15 @@ local function start_session_extended(smb, log_errors, overrides) header = smb_encode_header(smb, command_codes['SMB_COM_SESSION_SETUP_ANDX'], overrides) -- Data is a list of strings, terminated by a blank one. - data = bin.pack(" 10) then @@ -1868,7 +1855,7 @@ function create_file(smb, path, overrides) end -- Parse the parameters - pos, andx_command, andx_reserved, andx_offset, oplock_level, fid, create_action, created, last_access, last_write, last_change, attributes, allocation_size, end_of_file, filetype, ipc_state, is_directory = bin.unpack("S", response.parameters, 3)) ~= 0 ) + stop_loop = ( string.unpack(">I2", response.parameters, 3) ~= 0 ) end -- parse response, based on LOI == 260 repeat local fe, last_pos, ne, f_len, ea_len, sf_len, _ = {}, pos - pos, ne, fe.fi, fe.created, fe.accessed, fe.write, fe.change, - fe.eof, fe.alloc_size, fe.attrs, f_len, ea_len, sf_len, _ = bin.unpack("