1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-19 22:19:02 +00:00

Remove last uses of 'H' bin packing format, equivalent to stdnse.tohex/fromhex

This commit is contained in:
dmiller
2018-09-17 15:29:57 +00:00
parent 4824a5a074
commit f540c58e3f
7 changed files with 161 additions and 166 deletions

View File

@@ -111,7 +111,6 @@
-- Revised 04/03/2011 - v0.6 - add support for getting file- sizes, dates and Unix ACLs -- Revised 04/03/2011 - v0.6 - add support for getting file- sizes, dates and Unix ACLs
-- - moved afp.username & afp.password arguments to library -- - moved afp.username & afp.password arguments to library
local bin = require "bin"
local datetime = require "datetime" local datetime = require "datetime"
local ipOps = require "ipOps" local ipOps = require "ipOps"
local nmap = require "nmap" local nmap = require "nmap"
@@ -460,7 +459,7 @@ Proto = {
local reserved = 0 local reserved = 0
local data = data or "" local data = data or ""
local data_len = data:len() local data_len = data:len()
local header = bin.pack("CC>SIII", FLAGS.Request, command, self.RequestId, data_offset, data_len, reserved) local header = string.pack(">BBI2I4I4I4", FLAGS.Request, command, self.RequestId, data_offset, data_len, reserved)
self.RequestId = self.RequestId + 1 self.RequestId = self.RequestId + 1
return header .. data return header .. data
@@ -475,8 +474,8 @@ Proto = {
local header = {} local header = {}
local pos local pos
pos, header.flags, header.command, header.request_id = bin.unpack( "CC>S", packet ) header.flags, header.command, header.request_id, pos = string.unpack( ">BBI2", packet )
pos, header.error_code, header.length, header.reserved = bin.unpack( ">i>II", packet:sub(5) ) header.error_code, header.length, header.reserved, pos = string.unpack( ">i4I4I4", packet, pos )
if header.error_code ~= 0 then if header.error_code ~= 0 then
header.error_msg = ERROR_MSG[header.error_code] or ("Unknown error: %d"):format(header.error_code) header.error_msg = ERROR_MSG[header.error_code] or ("Unknown error: %d"):format(header.error_code)
@@ -542,7 +541,7 @@ Proto = {
local quantum = 1024 local quantum = 1024
local data, packet, status local data, packet, status
data = bin.pack( ">CCI", option, option_len, quantum ) data = string.pack( ">BBI4", option, option_len, quantum )
packet = self:create_fp_packet( REQUEST.OpenSession, data_offset, data ) packet = self:create_fp_packet( REQUEST.OpenSession, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -583,10 +582,10 @@ Proto = {
local src_path = src_path or "" local src_path = src_path or ""
local new_name = new_name or "" local new_name = new_name or ""
data = bin.pack(">CCSISI", COMMAND.FPCopyFile, pad, src_vol, src_did, dst_vol, dst_did ) data = string.pack(">BBI2I4I2I4", COMMAND.FPCopyFile, pad, src_vol, src_did, dst_vol, dst_did )
.. bin.pack(">CIP", unicode_names, unicode_hint, src_path ) .. string.pack(">BI4s2", unicode_names, unicode_hint, src_path )
.. bin.pack(">CIP", unicode_names, unicode_hint, dst_path ) .. string.pack(">BI4s2", unicode_names, unicode_hint, dst_path )
.. bin.pack(">CIP", unicode_names, unicode_hint, new_name ) .. string.pack(">BI4s2", unicode_names, unicode_hint, new_name )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -606,10 +605,9 @@ Proto = {
local response, result = {}, {} local response, result = {}, {}
local offsets = {} local offsets = {}
local pos local pos
local _
local status local status
local data = bin.pack("CC", COMMAND.FPGetSrvrInfo, 0) local data = string.pack("BB", COMMAND.FPGetSrvrInfo, 0)
packet = self:create_fp_packet(REQUEST.GetStatus, data_offset, data) packet = self:create_fp_packet(REQUEST.GetStatus, data_offset, data)
self:send_fp_packet(packet) self:send_fp_packet(packet)
response = self:read_fp_packet() response = self:read_fp_packet()
@@ -621,17 +619,17 @@ Proto = {
packet = response.packet packet = response.packet
-- parse and store the offsets in the 'header' -- parse and store the offsets in the 'header'
pos, offsets.machine_type, offsets.afp_version_count, offsets.machine_type, offsets.afp_version_count,
offsets.uam_count, offsets.volume_icon_and_mask offsets.uam_count, offsets.volume_icon_and_mask, pos
= bin.unpack(">SSSS", packet.data, pos) = string.unpack(">I2I2I2I2", packet.data)
-- the flags are directly in the 'header' -- the flags are directly in the 'header'
result.flags = {} result.flags = {}
pos, result.flags.raw = bin.unpack(">S", packet.data, pos) result.flags.raw, pos = string.unpack(">I2", packet.data, pos)
-- the short server name is stored directly in the 'header' as -- the short server name is stored directly in the 'header' as
-- well -- well
pos, result.server_name = bin.unpack("p", packet.data, pos) result.server_name, pos = string.unpack("s1", packet.data, pos)
-- Server offset should begin at an even boundary see link below -- Server offset should begin at an even boundary see link below
-- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40003548-CH3-CHDIEGED -- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40003548-CH3-CHDIEGED
@@ -640,9 +638,9 @@ Proto = {
end end
-- and some more offsets -- and some more offsets
pos, offsets.server_signature, offsets.network_addresses_count, offsets.server_signature, offsets.network_addresses_count,
offsets.directory_names_count, offsets.utf8_server_name offsets.directory_names_count, offsets.utf8_server_name, pos
= bin.unpack(">SSSS", packet.data, pos) = string.unpack(">I2I2I2I2", packet.data, pos)
-- this sets up all the server flags in the response table as booleans -- this sets up all the server flags in the response table as booleans
result.flags.SuperClient = flag_is_set(result.flags.raw, SERVERFLAGS.SuperClient) result.flags.SuperClient = flag_is_set(result.flags.raw, SERVERFLAGS.SuperClient)
@@ -659,25 +657,27 @@ Proto = {
result.flags.CopyFile = flag_is_set(result.flags.raw, SERVERFLAGS.CopyFile) result.flags.CopyFile = flag_is_set(result.flags.raw, SERVERFLAGS.CopyFile)
-- store the machine type -- store the machine type
_, result.machine_type = bin.unpack("p", packet.data, offsets.machine_type + 1) result.machine_type = string.unpack("s1", packet.data, offsets.machine_type + 1)
-- this tells us the number of afp versions supported -- this tells us the number of afp versions supported
pos, result.afp_version_count = bin.unpack("C", packet.data, offsets.afp_version_count + 1) result.afp_version_count, pos = string.unpack("B", packet.data, offsets.afp_version_count + 1)
-- now we loop through them all, storing for the response -- now we loop through them all, storing for the response
result.afp_versions = {} result.afp_versions = {}
for i = 1,result.afp_version_count do for i = 1,result.afp_version_count do
pos, _ = bin.unpack("p", packet.data, pos) local v
table.insert(result.afp_versions, _) v, pos = string.unpack("s1", packet.data, pos)
table.insert(result.afp_versions, v)
end end
-- same idea as the afp versions here -- same idea as the afp versions here
pos, result.uam_count = bin.unpack("C", packet.data, offsets.uam_count + 1) result.uam_count, pos = string.unpack("B", packet.data, offsets.uam_count + 1)
result.uams = {} result.uams = {}
for i = 1,result.uam_count do for i = 1,result.uam_count do
pos, _ = bin.unpack("p", packet.data, pos) local uam
table.insert(result.uams, _) uam, pos = string.unpack("s1", packet.data, pos)
table.insert(result.uams, uam)
end end
-- volume_icon_and_mask would normally be parsed out here, -- volume_icon_and_mask would normally be parsed out here,
@@ -688,7 +688,7 @@ Proto = {
result.server_signature = string.sub(packet.data, offsets.server_signature + 1, offsets.server_signature + 16) result.server_signature = string.sub(packet.data, offsets.server_signature + 1, offsets.server_signature + 16)
-- this is the same idea as afp_version and uam above -- this is the same idea as afp_version and uam above
pos, result.network_addresses_count = bin.unpack("C", packet.data, offsets.network_addresses_count + 1) result.network_addresses_count, pos = string.unpack("B", packet.data, offsets.network_addresses_count + 1)
result.network_addresses = {} result.network_addresses = {}
@@ -699,8 +699,7 @@ Proto = {
local length local length
local tag local tag
pos, length = bin.unpack("C", packet.data, pos) length, tag, pos = string.unpack("BB", packet.data, pos)
pos, tag = bin.unpack("C", packet.data, pos)
if tag == 0x00 then if tag == 0x00 then
-- reserved, shouldn't ever come up, maybe this should -- reserved, shouldn't ever come up, maybe this should
@@ -719,17 +718,13 @@ Proto = {
-- ddp address (two byte network, one byte -- ddp address (two byte network, one byte
-- node, one byte socket) not tested, anyone -- node, one byte socket) not tested, anyone
-- use ddp anymore? -- use ddp anymore?
local network local network, node, socket
local node network, node, socket, pos = string.unpack(">I2BB", packet.data, pos)
local socket
pos, network = bin.unpack(">S", packet.data, pos)
pos, node = bin.unpack("C", packet.data, pos)
pos, socket = bin.unpack("C", packet.data, pos)
table.insert(result.network_addresses, string.format("ddp %d.%d:%d", network, node, socket)) table.insert(result.network_addresses, string.format("ddp %d.%d:%d", network, node, socket))
elseif tag == 0x04 then elseif tag == 0x04 then
-- dns name (string) -- dns name (string)
local temp local temp
pos, temp = bin.unpack("z", packet.data:sub(1,pos+length-3), pos) temp, pos = string.unpack("z", packet.data:sub(1,pos+length-3), pos)
table.insert(result.network_addresses, temp) table.insert(result.network_addresses, temp)
elseif tag == 0x05 then elseif tag == 0x05 then
-- four byte ip and two byte port, client -- four byte ip and two byte port, client
@@ -757,17 +752,17 @@ Proto = {
end end
-- same idea as the others here -- same idea as the others here
pos, result.directory_names_count = bin.unpack("C", packet.data, offsets.directory_names_count + 1) result.directory_names_count, pos = string.unpack("B", packet.data, offsets.directory_names_count + 1)
result.directory_names = {} result.directory_names = {}
for i = 1, result.directory_names_count do for i = 1, result.directory_names_count do
local dirname local dirname
pos, dirname = bin.unpack("p", packet.data, pos) dirname, pos = string.unpack("s1", packet.data, pos)
table.insert(result.directory_names, dirname) table.insert(result.directory_names, dirname)
end end
-- only one utf8 server name. note this string has a two-byte length. -- only one utf8 server name. note this string has a two-byte length.
_, result.utf8_server_name = bin.unpack(">P", packet.data, offsets.utf8_server_name + 1) result.utf8_server_name = string.unpack(">s2", packet.data, offsets.utf8_server_name + 1)
response.result = result response.result = result
return response return response
@@ -787,7 +782,7 @@ Proto = {
local bitmap = USER_BITMAP.UserId local bitmap = USER_BITMAP.UserId
local result = {} local result = {}
local data = bin.pack( ">CCIS", COMMAND.FPGetUserInfo, flags, uid, bitmap ) local data = string.pack( ">BBI4I2", COMMAND.FPGetUserInfo, flags, uid, bitmap )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -796,7 +791,7 @@ Proto = {
return response return response
end end
pos, response.result.user_bitmap, response.result.uid = bin.unpack(">S>I", packet.data) response.result.user_bitmap, response.result.uid, pos = string.unpack(">I2I4", packet.data)
return response return response
end, end,
@@ -812,7 +807,7 @@ Proto = {
local pos = 0 local pos = 0
local parms = {} local parms = {}
data = bin.pack("CC", COMMAND.FPGetSrvParms, 0) data = string.pack("BB", COMMAND.FPGetSrvParms, 0)
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
response = self:read_fp_packet() response = self:read_fp_packet()
@@ -822,7 +817,7 @@ Proto = {
end end
data = response:getPacketData() data = response:getPacketData()
pos, parms.server_time, parms.vol_count = bin.unpack(">IC", data) parms.server_time, parms.vol_count, pos = string.unpack(">I4B", data)
-- we should now be at the leading zero preceding the first volume name -- we should now be at the leading zero preceding the first volume name
-- next is the length of the volume name, move pos there -- next is the length of the volume name, move pos there
@@ -831,9 +826,9 @@ Proto = {
parms.volumes = {} parms.volumes = {}
for i=1, parms.vol_count do for i=1, parms.vol_count do
local _, vol_len = bin.unpack("C", data:sub(pos)) local volume_name
local volume_name = data:sub(pos + 1, pos + 1 + vol_len) volume_name, pos = string.unpack("s1", data, pos)
pos = pos + vol_len + 2 pos = pos + 1
table.insert(parms.volumes, string.format("%s", volume_name) ) table.insert(parms.volumes, string.format("%s", volume_name) )
end end
@@ -875,7 +870,7 @@ Proto = {
end end
if ( uam == "No User Authent" ) then if ( uam == "No User Authent" ) then
data = bin.pack( "CCACA", COMMAND.FPLogin, afp_version:len(), afp_version, uam:len(), uam ) data = string.pack( "Bs1s1", COMMAND.FPLogin, afp_version, uam )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
return self:read_fp_packet( ) return self:read_fp_packet( )
@@ -883,7 +878,7 @@ Proto = {
local dhx_s2civ, dhx_c2civ = 'CJalbert', 'LWallace' local dhx_s2civ, dhx_c2civ = 'CJalbert', 'LWallace'
local p, g, Ra, Ma, Mb, K, nonce local p, g, Ra, Ma, Mb, K, nonce
local EncData, PlainText, K_bin, auth_response local EncData, PlainText, K_bin, auth_response
local _, Id local Id
local username = username or "" local username = username or ""
local password = password or "" local password = password or ""
@@ -894,7 +889,7 @@ Proto = {
Ra = openssl.bignum_hex2bn("86F6D3C0B0D63E4B11F113A2F9F19E3BBBF803F28D30087A1450536BE979FD42") Ra = openssl.bignum_hex2bn("86F6D3C0B0D63E4B11F113A2F9F19E3BBBF803F28D30087A1450536BE979FD42")
Ma = openssl.bignum_mod_exp(g, Ra, p) Ma = openssl.bignum_mod_exp(g, Ra, p)
data = bin.pack( "CpppA", COMMAND.FPLogin, afp_version, uam, username, openssl.bignum_bn2bin(Ma) ) data = string.pack( "Bs1s1s1", COMMAND.FPLogin, afp_version, uam, username) .. openssl.bignum_bn2bin(Ma)
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
response = self:read_fp_packet( ) response = self:read_fp_packet( )
@@ -907,9 +902,9 @@ Proto = {
return response return response
end end
_, Id, Mb, EncData = bin.unpack(">SH16A32", response.packet.data ) Id, Mb, EncData = string.unpack(">I2c16c32", response.packet.data )
Mb = openssl.bignum_hex2bn( Mb ) Mb = openssl.bignum_bin2bn( Mb )
K = openssl.bignum_mod_exp (Mb, Ra, p) K = openssl.bignum_mod_exp (Mb, Ra, p)
K_bin = openssl.bignum_bn2bin(K) K_bin = openssl.bignum_bn2bin(K)
nonce = openssl.decrypt("cast5-cbc", K_bin, dhx_s2civ, EncData, false ):sub(1,16) nonce = openssl.decrypt("cast5-cbc", K_bin, dhx_s2civ, EncData, false ):sub(1,16)
@@ -917,7 +912,7 @@ Proto = {
PlainText = openssl.bignum_bn2bin(nonce) .. Util.ZeroPad(password, 64) PlainText = openssl.bignum_bn2bin(nonce) .. Util.ZeroPad(password, 64)
auth_response = openssl.encrypt( "cast5-cbc", K_bin, dhx_c2civ, PlainText, true) auth_response = openssl.encrypt( "cast5-cbc", K_bin, dhx_c2civ, PlainText, true)
data = bin.pack( "CC>SA", COMMAND.FPLoginCont, 0, Id, auth_response ) data = string.pack( ">BBI2", COMMAND.FPLoginCont, 0, Id) .. auth_response
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
response = self:read_fp_packet( ) response = self:read_fp_packet( )
@@ -937,7 +932,7 @@ Proto = {
local packet, data, response local packet, data, response
local data_offset, pad = 0, 0 local data_offset, pad = 0, 0
data = bin.pack("CC", COMMAND.FPLogout, pad) data = string.pack("BB", COMMAND.FPLogout, pad)
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
return self:read_fp_packet( ) return self:read_fp_packet( )
@@ -954,7 +949,7 @@ Proto = {
local data_offset, pad = 0, 0 local data_offset, pad = 0, 0
local response, volume = {}, {} local response, volume = {}, {}
data = bin.pack("CC>SCA", COMMAND.FPOpenVol, pad, bitmap, volume_name:len(), volume_name ) data = string.pack(">BBI2s1", COMMAND.FPOpenVol, pad, bitmap, volume_name)
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
response = self:read_fp_packet() response = self:read_fp_packet()
@@ -962,7 +957,7 @@ Proto = {
return response return response
end end
pos, volume.bitmap, volume.volume_id = bin.unpack(">S>S", response.packet.data) volume.bitmap, volume.volume_id, pos = string.unpack(">I2I2", response.packet.data)
response:setResult(volume) response:setResult(volume)
return response return response
end, end,
@@ -998,7 +993,7 @@ Proto = {
return response return response
end end
data = bin.pack("CC>S>I>S>SCCAC", COMMAND.FPGetFileDirParams, pad, volume_id, did, file_bitmap, dir_bitmap, path.type, path.len, path.name, 0) data = string.pack(">BBI2I4I2I2BBz", COMMAND.FPGetFileDirParams, pad, volume_id, did, file_bitmap, dir_bitmap, path.type, path.len, path.name)
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
response = self:read_fp_packet() response = self:read_fp_packet()
@@ -1007,7 +1002,7 @@ Proto = {
return response return response
end end
pos, parms.file_bitmap, parms.dir_bitmap, parms.file_type, pad = bin.unpack( ">S>SCC", response.packet.data ) parms.file_bitmap, parms.dir_bitmap, parms.file_type, pad, pos = string.unpack( ">I2I2BB", response.packet.data )
-- file or dir? -- file or dir?
if ( parms.file_type == 0x80 ) then if ( parms.file_type == 0x80 ) then
@@ -1035,13 +1030,13 @@ Proto = {
-- <code>file_bitmap</code>, <code>dir_bitmap</code>, <code>req_count</code> fields -- <code>file_bitmap</code>, <code>dir_bitmap</code>, <code>req_count</code> fields
fp_enumerate_ext2 = function( self, volume_id, did, file_bitmap, dir_bitmap, req_count, start_index, reply_size, path ) fp_enumerate_ext2 = function( self, volume_id, did, file_bitmap, dir_bitmap, req_count, start_index, reply_size, path )
local packet, pos, _, status local packet, pos, status
local data_offset = 0 local data_offset = 0
local pad = 0 local pad = 0
local response,records = {}, {} local response,records = {}, {}
local data = bin.pack( "CC>S>I>S>S", COMMAND.FPEnumerateExt2, pad, volume_id, did, file_bitmap, dir_bitmap ) local data = string.pack( ">BBI2I4I2I2", COMMAND.FPEnumerateExt2, pad, volume_id, did, file_bitmap, dir_bitmap )
.. bin.pack( ">S>I>ICCA", req_count, start_index, reply_size, path.type, path.len, path.name ) .. string.pack( ">I2I4I4BB", req_count, start_index, reply_size, path.type, path.len) .. path.name
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1051,7 +1046,7 @@ Proto = {
return response return response
end end
pos, file_bitmap, dir_bitmap, req_count = bin.unpack(">S>S>S", response.packet.data) file_bitmap, dir_bitmap, req_count, pos = string.unpack(">I2I2I2", response.packet.data)
records = {} records = {}
@@ -1059,7 +1054,7 @@ Proto = {
local record = {} local record = {}
local len, _, ftype local len, _, ftype
pos, len, ftype, _ = bin.unpack(">SCC", response.packet.data, pos) len, ftype, pos = string.unpack(">I2Bx", response.packet.data, pos)
if ( ftype == 0x80 ) then if ( ftype == 0x80 ) then
_, record = Util.decode_dir_bitmap( dir_bitmap, response.packet.data, pos ) _, record = Util.decode_dir_bitmap( dir_bitmap, response.packet.data, pos )
@@ -1093,20 +1088,20 @@ Proto = {
-- @return response object with the following result contents <code>file_bitmap</code> and <code>fork_id</code> -- @return response object with the following result contents <code>file_bitmap</code> and <code>fork_id</code>
fp_open_fork = function( self, flag, volume_id, did, file_bitmap, access_mode, path ) fp_open_fork = function( self, flag, volume_id, did, file_bitmap, access_mode, path )
local packet, _ local packet
local data_offset = 0 local data_offset = 0
local pad = 0 local pad = 0
local response, fork = {}, {} local response, fork = {}, {}
local data = bin.pack( "CC>S>I>S>S", COMMAND.FPOpenFork, flag, volume_id, did, file_bitmap, access_mode ) local data = string.pack( ">BBI2I4I2I2", COMMAND.FPOpenFork, flag, volume_id, did, file_bitmap, access_mode )
if path.type == PATH_TYPE.LongName then if path.type == PATH_TYPE.LongName then
data = data .. bin.pack( "CCA", path.type, path.len, path.name ) data = data .. string.pack( "BB", path.type, path.len) .. path.name
end end
if path.type == PATH_TYPE.UTF8Name then if path.type == PATH_TYPE.UTF8Name then
local unicode_hint = 0x08000103 local unicode_hint = 0x08000103
data = data .. bin.pack( "C>I>SA", path.type, unicode_hint, path.len, path.name ) data = data .. string.pack( ">BI4I2", path.type, unicode_hint, path.len) .. path.name
end end
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
@@ -1117,7 +1112,7 @@ Proto = {
return response return response
end end
_, fork.file_bitmap, fork.fork_id = bin.unpack(">S>S", response.packet.data) fork.file_bitmap, fork.fork_id = string.unpack(">I2I2", response.packet.data)
response:setResult(fork) response:setResult(fork)
return response return response
end, end,
@@ -1132,7 +1127,7 @@ Proto = {
local pad = 0 local pad = 0
local response = {} local response = {}
local data = bin.pack( "CC>S", COMMAND.FPCloseFork, pad, fork ) local data = string.pack( ">BBI2", COMMAND.FPCloseFork, pad, fork )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1150,7 +1145,7 @@ Proto = {
local data_offset, pad = 0, 0 local data_offset, pad = 0, 0
local response = {} local response = {}
local data = bin.pack( "CC>S>ICp", COMMAND.FPCreateDir, pad, vol_id, dir_id, path.type, path.name ) local data = string.pack( ">BBI2I4Bs1", COMMAND.FPCreateDir, pad, vol_id, dir_id, path.type, path.name )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1166,7 +1161,7 @@ Proto = {
local data_offset, pad = 0, 0 local data_offset, pad = 0, 0
local response = {} local response = {}
local data = bin.pack( "CC>S", COMMAND.FPCloseVol, pad, volume_id ) local data = string.pack( ">BBI2", COMMAND.FPCloseVol, pad, volume_id )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1184,7 +1179,7 @@ Proto = {
local packet, response local packet, response
local data_offset = 0 local data_offset = 0
local block_size = 1024 local block_size = 1024
local data = bin.pack( "CC>S>L>L", COMMAND.FPReadExt, pad, fork, offset, count ) local data = string.pack( ">BBI2I8I8", COMMAND.FPReadExt, pad, fork, offset, count )
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1222,7 +1217,7 @@ Proto = {
return err return err
end end
data = bin.pack( "CC>S>L>LA", COMMAND.FPWriteExt, flag, fork, offset, count, fdata ) data = string.pack( ">BBI2I8I8", COMMAND.FPWriteExt, flag, fork, offset, count) .. fdata
packet = self:create_fp_packet( REQUEST.Write, data_offset, data ) packet = self:create_fp_packet( REQUEST.Write, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
return self:read_fp_packet( ) return self:read_fp_packet( )
@@ -1238,7 +1233,7 @@ Proto = {
fp_create_file = function(self, flag, vol_id, did, path ) fp_create_file = function(self, flag, vol_id, did, path )
local packet local packet
local data_offset = 0 local data_offset = 0
local data = bin.pack( "CC>S>ICCA" , COMMAND.FPCreateFile, flag, vol_id, did, path.type, path.len, path.name ) local data = string.pack(">BBI2I4BB" , COMMAND.FPCreateFile, flag, vol_id, did, path.type, path.len) .. path.name
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
self:send_fp_packet( packet ) self:send_fp_packet( packet )
@@ -1253,13 +1248,12 @@ Proto = {
fp_map_id = function( self, subfunc, id ) fp_map_id = function( self, subfunc, id )
local packet, response local packet, response
local data_offset = 0 local data_offset = 0
local data = bin.pack( "CC", COMMAND.FPMapId, subfunc ) local data = string.pack( "BB", COMMAND.FPMapId, subfunc )
local _, len
if ( subfunc == MAP_ID.UserUUIDToUTF8Name or subfunc == MAP_ID.GroupUUIDToUTF8Name ) then if ( subfunc == MAP_ID.UserUUIDToUTF8Name or subfunc == MAP_ID.GroupUUIDToUTF8Name ) then
data = data .. bin.pack(">L", id) data = data .. string.pack(">I8", id)
else else
data = data .. bin.pack(">I", id) data = data .. string.pack(">I4", id)
end end
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
@@ -1272,13 +1266,13 @@ Proto = {
-- Netatalk returns the name with 1-byte length prefix, -- Netatalk returns the name with 1-byte length prefix,
-- Mac OS has a 2-byte (UTF-8) length prefix -- Mac OS has a 2-byte (UTF-8) length prefix
local _, len = bin.unpack("C", response.packet.data) local len = string.unpack("B", response.packet.data)
-- if length is zero assume 2-byte length (UTF-8 name) -- if length is zero assume 2-byte length (UTF-8 name)
if len == 0 then if len == 0 then
response:setResult( select(2, bin.unpack(">P", response.packet.data )) ) response:setResult(string.unpack(">s2", response.packet.data))
else else
response:setResult( select(2, bin.unpack("p", response.packet.data )) ) response:setResult(string.unpack("s1", response.packet.data ))
end end
return response return response
end, end,
@@ -1291,7 +1285,7 @@ Proto = {
fp_map_name = function( self, subfunc, name ) fp_map_name = function( self, subfunc, name )
local packet local packet
local data_offset = 0 local data_offset = 0
local data = bin.pack( "CC>SA", COMMAND.FPMapName, subfunc, name:len(), name ) local data = string.pack(">BBs2", COMMAND.FPMapName, subfunc, name )
local response local response
packet = self:create_fp_packet( REQUEST.Command, data_offset, data ) packet = self:create_fp_packet( REQUEST.Command, data_offset, data )
@@ -1302,7 +1296,7 @@ Proto = {
return response return response
end end
response:setResult( select(2, bin.unpack(">I", response.packet.data))) response:setResult(string.unpack(">I4", response.packet.data))
return response return response
end, end,
} }
@@ -1940,61 +1934,60 @@ Util =
local file = {} local file = {}
if ( ( bitmap & FILE_BITMAP.Attributes ) == FILE_BITMAP.Attributes ) then if ( ( bitmap & FILE_BITMAP.Attributes ) == FILE_BITMAP.Attributes ) then
pos, file.Attributes = bin.unpack(">S", data, pos ) file.Attributes, pos = string.unpack(">I2", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.ParentDirId ) == FILE_BITMAP.ParentDirId ) then if ( ( bitmap & FILE_BITMAP.ParentDirId ) == FILE_BITMAP.ParentDirId ) then
pos, file.ParentDirId = bin.unpack(">I", data, pos ) file.ParentDirId, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.CreationDate ) == FILE_BITMAP.CreationDate ) then if ( ( bitmap & FILE_BITMAP.CreationDate ) == FILE_BITMAP.CreationDate ) then
pos, file.CreationDate = bin.unpack(">I", data, pos ) file.CreationDate, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.ModificationDate ) == FILE_BITMAP.ModificationDate ) then if ( ( bitmap & FILE_BITMAP.ModificationDate ) == FILE_BITMAP.ModificationDate ) then
pos, file.ModificationDate = bin.unpack(">I", data, pos ) file.ModificationDate, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.BackupDate ) == FILE_BITMAP.BackupDate ) then if ( ( bitmap & FILE_BITMAP.BackupDate ) == FILE_BITMAP.BackupDate ) then
pos, file.BackupDate = bin.unpack(">I", data, pos ) file.BackupDate, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.FinderInfo ) == FILE_BITMAP.FinderInfo ) then if ( ( bitmap & FILE_BITMAP.FinderInfo ) == FILE_BITMAP.FinderInfo ) then
pos, file.FinderInfo = bin.unpack("A32", data, pos ) file.FinderInfo, pos = string.unpack("c32", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.LongName ) == FILE_BITMAP.LongName ) then if ( ( bitmap & FILE_BITMAP.LongName ) == FILE_BITMAP.LongName ) then
local offset, p, name local offset = string.unpack(">I2", data, pos)
pos, offset = bin.unpack(">S", data, pos) file.LongName = string.unpack("s1", data, offset + pos)
p, file.LongName = bin.unpack("p", data, offset + pos - 1) pos = pos + 2
end end
if ( ( bitmap & FILE_BITMAP.ShortName ) == FILE_BITMAP.ShortName ) then if ( ( bitmap & FILE_BITMAP.ShortName ) == FILE_BITMAP.ShortName ) then
local offset, p, name local offset = string.unpack(">I2", data, pos)
pos, offset = bin.unpack(">S", data, pos) file.ShortName = string.unpack("s1", data, offset + pos)
p, file.ShortName = bin.unpack("p", data, offset + pos - 1) pos = pos + 2
end end
if ( ( bitmap & FILE_BITMAP.NodeId ) == FILE_BITMAP.NodeId ) then if ( ( bitmap & FILE_BITMAP.NodeId ) == FILE_BITMAP.NodeId ) then
pos, file.NodeId = bin.unpack(">I", data, pos ) file.NodeId, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.DataForkSize ) == FILE_BITMAP.DataForkSize ) then if ( ( bitmap & FILE_BITMAP.DataForkSize ) == FILE_BITMAP.DataForkSize ) then
pos, file.DataForkSize = bin.unpack(">I", data, pos ) file.DataForkSize, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.ResourceForkSize ) == FILE_BITMAP.ResourceForkSize ) then if ( ( bitmap & FILE_BITMAP.ResourceForkSize ) == FILE_BITMAP.ResourceForkSize ) then
pos, file.ResourceForkSize = bin.unpack(">I", data, pos ) file.ResourceForkSize, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.ExtendedDataForkSize ) == FILE_BITMAP.ExtendedDataForkSize ) then if ( ( bitmap & FILE_BITMAP.ExtendedDataForkSize ) == FILE_BITMAP.ExtendedDataForkSize ) then
pos, file.ExtendedDataForkSize = bin.unpack(">L", data, pos ) file.ExtendedDataForkSize, pos = string.unpack(">I8", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.LaunchLimit ) == FILE_BITMAP.LaunchLimit ) then if ( ( bitmap & FILE_BITMAP.LaunchLimit ) == FILE_BITMAP.LaunchLimit ) then
-- should not be set as it's deprecated according to: -- should not be set as it's deprecated according to:
-- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/c_ref/kFPLaunchLimitBit -- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/c_ref/kFPLaunchLimitBit
end end
if ( ( bitmap & FILE_BITMAP.UTF8Name ) == FILE_BITMAP.UTF8Name ) then if ( ( bitmap & FILE_BITMAP.UTF8Name ) == FILE_BITMAP.UTF8Name ) then
local offset, p, name local offset = string.unpack(">I2", data, pos)
pos, offset = bin.unpack(">S", data, pos) file.UTF8Name = string.unpack("s1", data, offset + pos)
p, file.UTF8Name = bin.unpack("p", data, offset + pos - 1) pos = pos + 2
end end
if ( ( bitmap & FILE_BITMAP.ExtendedResourceForkSize ) == FILE_BITMAP.ExtendedResourceForkSize ) then if ( ( bitmap & FILE_BITMAP.ExtendedResourceForkSize ) == FILE_BITMAP.ExtendedResourceForkSize ) then
pos, file.ExtendedResourceForkSize = bin.unpack(">L", data, pos ) file.ExtendedResourceForkSize, pos = string.unpack(">I8", data, pos )
end end
if ( ( bitmap & FILE_BITMAP.UnixPrivileges ) == FILE_BITMAP.UnixPrivileges ) then if ( ( bitmap & FILE_BITMAP.UnixPrivileges ) == FILE_BITMAP.UnixPrivileges ) then
local unixprivs = {} local unixprivs = {}
pos, unixprivs.uid, unixprivs.gid, unixprivs.uid, unixprivs.gid, unixprivs.permissions, unixprivs.ua_permissions, pos = string.unpack(">I4I4I4I4", data, pos)
unixprivs.permissions, unixprivs.ua_permissions = bin.unpack(">IIII", data, pos )
file.UnixPrivileges = unixprivs file.UnixPrivileges = unixprivs
end end
return pos, file return pos, file
@@ -2011,68 +2004,66 @@ Util =
local dir = {} local dir = {}
if ( ( bitmap & DIR_BITMAP.Attributes ) == DIR_BITMAP.Attributes ) then if ( ( bitmap & DIR_BITMAP.Attributes ) == DIR_BITMAP.Attributes ) then
pos, dir.Attributes = bin.unpack(">S", data, pos ) dir.Attributes, pos = string.unpack(">I2", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.ParentDirId ) == DIR_BITMAP.ParentDirId ) then if ( ( bitmap & DIR_BITMAP.ParentDirId ) == DIR_BITMAP.ParentDirId ) then
pos, dir.ParentDirId = bin.unpack(">I", data, pos ) dir.ParentDirId, pos = string.unpack(">I4", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.CreationDate ) == DIR_BITMAP.CreationDate ) then if ( ( bitmap & DIR_BITMAP.CreationDate ) == DIR_BITMAP.CreationDate ) then
pos, dir.CreationDate = bin.unpack(">I", data, pos ) dir.CreationDate, pos = string.unpack(">I4", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.ModificationDate ) == DIR_BITMAP.ModificationDate ) then if ( ( bitmap & DIR_BITMAP.ModificationDate ) == DIR_BITMAP.ModificationDate ) then
pos, dir.ModificationDate = bin.unpack(">I", data, pos ) dir.ModificationDate, pos = string.unpack(">I4", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.BackupDate ) == DIR_BITMAP.BackupDate ) then if ( ( bitmap & DIR_BITMAP.BackupDate ) == DIR_BITMAP.BackupDate ) then
pos, dir.BackupDate = bin.unpack(">I", data, pos ) dir.BackupDate, pos = string.unpack(">I4", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.FinderInfo ) == DIR_BITMAP.FinderInfo ) then if ( ( bitmap & DIR_BITMAP.FinderInfo ) == DIR_BITMAP.FinderInfo ) then
pos, dir.FinderInfo = bin.unpack("A32", data, pos ) dir.FinderInfo, pos = string.unpack("c32", data, pos)
end end
if ( ( bitmap & DIR_BITMAP.LongName ) == DIR_BITMAP.LongName ) then if ( ( bitmap & DIR_BITMAP.LongName ) == DIR_BITMAP.LongName ) then
local offset, p, name local offset, p, name
pos, offset = bin.unpack(">S", data, pos) offset, pos = string.unpack(">I2", data, pos)
-- TODO: This really needs to be addressed someway -- TODO: This really needs to be addressed someway
-- Barely, never, ever happens, which makes it difficult to pin down -- Barely, never, ever happens, which makes it difficult to pin down
-- http://developer.apple.com/mac/library/documentation/Networking/Reference/ -- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40003548-CH3-CHDBEHBG
-- AFP_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40003548-CH3-CHDBEHBG [URL is wrapped] local justkidding = string.unpack(">I4", data, pos + 4)
local justkidding = select(2, bin.unpack(">I", data, pos + 4))
if ( justkidding ~= 0 ) then if ( justkidding ~= 0 ) then
offset = 5 offset = 5
end end
p, dir.LongName = bin.unpack("p", data, offset + pos - 1) dir.LongName = string.unpack("s1", data, offset + pos - 1)
end end
if ( ( bitmap & DIR_BITMAP.ShortName ) == DIR_BITMAP.ShortName ) then if ( ( bitmap & DIR_BITMAP.ShortName ) == DIR_BITMAP.ShortName ) then
local offset, p, name local offset = string.unpack(">I2", data, pos)
pos, offset = bin.unpack(">S", data, pos) dir.ShortName = string.unpack("s1", data, offset + pos)
p, dir.ShortName = bin.unpack("p", data, offset + pos - 1) pos = pos + 2
end end
if ( ( bitmap & DIR_BITMAP.NodeId ) == DIR_BITMAP.NodeId ) then if ( ( bitmap & DIR_BITMAP.NodeId ) == DIR_BITMAP.NodeId ) then
pos, dir.NodeId = bin.unpack(">I", data, pos ) dir.NodeId, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & DIR_BITMAP.OffspringCount ) == DIR_BITMAP.OffspringCount ) then if ( ( bitmap & DIR_BITMAP.OffspringCount ) == DIR_BITMAP.OffspringCount ) then
pos, dir.OffspringCount = bin.unpack(">S", data, pos ) dir.OffspringCount, pos = string.unpack(">I2", data, pos )
end end
if ( ( bitmap & DIR_BITMAP.OwnerId ) == DIR_BITMAP.OwnerId ) then if ( ( bitmap & DIR_BITMAP.OwnerId ) == DIR_BITMAP.OwnerId ) then
pos, dir.OwnerId = bin.unpack(">I", data, pos ) dir.OwnerId, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & DIR_BITMAP.GroupId ) == DIR_BITMAP.GroupId ) then if ( ( bitmap & DIR_BITMAP.GroupId ) == DIR_BITMAP.GroupId ) then
pos, dir.GroupId = bin.unpack(">I", data, pos ) dir.GroupId, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & DIR_BITMAP.AccessRights ) == DIR_BITMAP.AccessRights ) then if ( ( bitmap & DIR_BITMAP.AccessRights ) == DIR_BITMAP.AccessRights ) then
pos, dir.AccessRights = bin.unpack(">I", data, pos ) dir.AccessRights, pos = string.unpack(">I4", data, pos )
end end
if ( ( bitmap & DIR_BITMAP.UTF8Name ) == DIR_BITMAP.UTF8Name ) then if ( ( bitmap & DIR_BITMAP.UTF8Name ) == DIR_BITMAP.UTF8Name ) then
local offset, p, name local offset = string.unpack(">I2", data, pos)
pos, offset = bin.unpack(">S", data, pos) dir.UTF8Name = string.unpack("s1", data, offset + pos)
p, dir.UTF8Name = bin.unpack("p", data, offset + pos - 1) pos = pos + 2
end end
if ( ( bitmap & DIR_BITMAP.UnixPrivileges ) == DIR_BITMAP.UnixPrivileges ) then if ( ( bitmap & DIR_BITMAP.UnixPrivileges ) == DIR_BITMAP.UnixPrivileges ) then
local unixprivs = {} local unixprivs = {}
pos, unixprivs.uid, unixprivs.gid, unixprivs.uid, unixprivs.gid, unixprivs.permissions, unixprivs.ua_permissions, pos = string.unpack(">I4I4I4I4", data, pos)
unixprivs.permissions, unixprivs.ua_permissions = bin.unpack(">I>I>I>I", data, pos )
dir.UnixPrivileges = unixprivs dir.UnixPrivileges = unixprivs
end end
return pos, dir return pos, dir

View File

@@ -546,7 +546,7 @@ Helper = {
-- @return table containing <code>extname</code>, <code>srvclass</code>, -- @return table containing <code>extname</code>, <code>srvclass</code>,
-- <code>srvname</code> and <code>prodrel</code> -- <code>srvname</code> and <code>prodrel</code>
getServerInfo = function( self ) getServerInfo = function( self )
local mgrlvlls = bin.pack("H", "1403000724070008240f00081440000814740008") local mgrlvlls = stdnse.fromhex("1403000724070008240f00081440000814740008")
local drda_excsat = Command.EXCSAT( "", "", "", mgrlvlls, "" ) local drda_excsat = Command.EXCSAT( "", "", "", mgrlvlls, "" )
local response, param, err local response, param, err
@@ -587,10 +587,10 @@ Helper = {
-- @return Status (true or false) -- @return Status (true or false)
-- @return err message (if status if false) -- @return err message (if status if false)
login = function( self, database, username, password ) login = function( self, database, username, password )
local mgrlvlls = bin.pack("H", "1403000724070008240f00081440000814740008") local mgrlvlls = stdnse.fromhex("1403000724070008240f00081440000814740008")
local secmec, prdid = "\00\03", "JCC03010" local secmec, prdid = "\00\03", "JCC03010"
local tdovr = bin.pack("H", "0006119c04b80006119d04b00006119e04b8") local tdovr = stdnse.fromhex("0006119c04b80006119d04b00006119e04b8")
local crrtkn= bin.pack("H", "d5c6f0f0f0f0f0f14bc3c6f4c4012a11168414") local crrtkn= stdnse.fromhex("d5c6f0f0f0f0f0f14bc3c6f4c4012a11168414")
local drda_excsat = Command.EXCSAT( "", "", "", mgrlvlls, "" ) local drda_excsat = Command.EXCSAT( "", "", "", mgrlvlls, "" )
local drda_accsec = Command.ACCSEC( secmec, database ) local drda_accsec = Command.ACCSEC( secmec, database )
@@ -735,8 +735,8 @@ D17E737475767778797AD2D3D45BD6D7D8D9DADBDCDDDEDFE0E1E2E3E45DE6E7\z
5C9F535455565758595AF4F5F6F7F8F930313233343536373839FAFBFCFDFEFF" 5C9F535455565758595AF4F5F6F7F8F930313233343536373839FAFBFCFDFEFF"
-- Creates the lookup tables needed for conversion -- Creates the lookup tables needed for conversion
a2e_tbl = bin.pack("H", a2e_hex) a2e_tbl = stdnse.fromhex(a2e_hex)
e2a_tbl = bin.pack("H", e2a_hex) e2a_tbl = stdnse.fromhex(e2a_hex)
-- Handle EBCDIC/ASCII conversion -- Handle EBCDIC/ASCII conversion
StringUtil = StringUtil =

View File

@@ -57,6 +57,7 @@ local bin = require "bin"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string"
local table = require "table" local table = require "table"
_ENV = stdnse.module("giop", stdnse.seeall) _ENV = stdnse.module("giop", stdnse.seeall)
@@ -184,12 +185,15 @@ SendingContextRuntime =
local o = {} local o = {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
o.data = bin.pack(">HIAH", lhost = lhost .. "\0"
o.data = stdnse.fromhex(
[[ [[
000000000000002849444c3a6f6d672e6f72672f53656e64696e67436f6e746 000000000000002849444c3a6f6d672e6f72672f53656e64696e67436f6e746
578742f436f6465426173653a312e300000000001000000000000006e000102 578742f436f6465426173653a312e300000000001000000000000006e000102
00 00
]], #lhost + 1, lhost .. "\0", ]])
.. string.pack(">s4", lhost)
.. stdnse.fromhex(
[[ [[
00ec5100000019afabcb000000000249765d6900000008000000000000000014 00ec5100000019afabcb000000000249765d6900000008000000000000000014
0000000000000200000001000000200000000000010001000000020501000100 0000000000000200000001000000200000000000010001000000020501000100

View File

@@ -75,6 +75,7 @@ local bin = require "bin"
local nmap = require "nmap" local nmap = require "nmap"
local match = require "match" local match = require "match"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string"
local table = require "table" local table = require "table"
_ENV = stdnse.module("informix", stdnse.seeall) _ENV = stdnse.module("informix", stdnse.seeall)
@@ -728,7 +729,7 @@ Packet.SQ_INFO =
Packet.SQ_PROTOCOLS = Packet.SQ_PROTOCOLS =
{ {
-- hex-encoded data to send as protocol negotiation -- hex-encoded data to send as protocol negotiation
data = "0007fffc7ffc3c8c8a00000c", data = stdnse.fromhex("0007fffc7ffc3c8c8a00000c"),
--- Creates a new Packet.SQ_PROTOCOLS instance --- Creates a new Packet.SQ_PROTOCOLS instance
-- --
@@ -744,7 +745,7 @@ Packet.SQ_PROTOCOLS =
-- --
-- @return string containing the packet data -- @return string containing the packet data
__tostring = function(self) __tostring = function(self)
return bin.pack(">SH", Constants.Message.SQ_PROTOCOLS, self.data) return string.pack(">I2", Constants.Message.SQ_PROTOCOLS) .. self.data
end end
} }
@@ -1096,18 +1097,26 @@ Packet.Connect = {
self:addDefaultParameters() self:addDefaultParameters()
end end
data = bin.pack(">HPPHPHS", unknown, self.username, self.password, unknown2, self.instance, unknown3, #self.parameters ) data = {
stdnse.fromhex(unknown),
string.pack(">s2s2", self.username, self.password),
stdnse.fromhex(unknown2),
string.pack(">s2", self.instance),
stdnse.fromhex(unknown3),
string.pack(">I2", #self.parameters),
}
if ( self.parameters ) then if ( self.parameters ) then
for _, v in ipairs( self.parameters ) do for _, v in ipairs( self.parameters ) do
for k2, v2 in pairs( v ) do for k2, v2 in pairs( v ) do
data = data .. Util.paramToString( k2 .. "\0", v2 .. "\0" ) data[#data+1] = Util.paramToString( k2 .. "\0", v2 .. "\0" )
end end
end end
end end
data = data .. bin.pack("H", unknown4) data[#data+1] = stdnse.fromhex(unknown4)
data = bin.pack(">S", #data + 2) .. data data = table.concat(data)
data = string.pack(">I2", #data + 2) .. data
return data return data
end, end,

View File

@@ -971,23 +971,9 @@ ColumnData =
return pos, 'Null' return pos, 'Null'
elseif ( len == 16 ) then elseif ( len == 16 ) then
-- Mixed-endian; first 3 parts are little-endian, next 2 are big-endian
-- Return the first 8 bytes local A, B, C, D, E, pos = string.unpack("<I4I2I2>c2c6", data, pos)
for index=1, 8 do coldata = ("%08x-%04x-%04x-%s-%s"):format(A, B, C, stdnse.tohex(D), stdnse.tohex(E))
pos, hex[index] = bin.unpack("H", data, pos)
end
-- reorder the bytes
coldata = hex[4] .. hex[3] .. hex[2] .. hex[1]
coldata = coldata .. '-' .. hex[6] .. hex[5]
coldata = coldata .. '-' .. hex[8] .. hex[7]
pos, nextdata = bin.unpack("H2", data, pos)
coldata = coldata .. '-' .. nextdata
pos, nextdata = bin.unpack("H6", data, pos)
coldata = coldata .. '-' .. nextdata
else else
stdnse.debug1("Unhandled length (%d) for GUIDTYPE", len) stdnse.debug1("Unhandled length (%d) for GUIDTYPE", len)
return pos + len, 'Unsupported Data' return pos + len, 'Unsupported Data'
@@ -1235,13 +1221,13 @@ ColumnData =
[DataTypes.XSYBVARBINARY] = function( data, pos ) [DataTypes.XSYBVARBINARY] = function( data, pos )
local len, coldata local len, coldata
pos, len = bin.unpack( "<S", data, pos ) len, pos = string.unpack( "<I2", data, pos )
if ( len == 65535 ) then if ( len == 65535 ) then
return pos, 'Null' return pos, 'Null'
else else
pos, coldata = bin.unpack( "A"..len, data, pos ) coldata, pos = string.unpack( "c"..len, data, pos )
return pos, "0x" .. select(2, bin.unpack("H"..coldata:len(), coldata ) ) return pos, "0x" .. stdnse.tohex(coldata)
end end
return -1, "Error" return -1, "Error"
@@ -3042,7 +3028,7 @@ Helper =
return false, "Failed to connect to sqlbrowser service" return false, "Failed to connect to sqlbrowser service"
end end
if ( not(socket:send(bin.pack("Hz", "0F01", instanceName))) ) then if ( not(socket:send(string.pack("c2z", "\x0F\x01", instanceName))) ) then
socket:close() socket:close()
return false, "Failed to send request to sqlbrowser service" return false, "Failed to send request to sqlbrowser service"
end end

View File

@@ -42,6 +42,7 @@ local bin = require "bin"
local match = require "match" local match = require "match"
local nmap = require "nmap" local nmap = require "nmap"
local stdnse = require "stdnse" local stdnse = require "stdnse"
local string = require "string"
_ENV = stdnse.module("nrpc", stdnse.seeall) _ENV = stdnse.module("nrpc", stdnse.seeall)
-- The Domino Packet -- The Domino Packet
@@ -121,14 +122,18 @@ Helper = {
-- @return domino_id if it exists and status is true -- @return domino_id if it exists and status is true
-- err if status is false -- err if status is false
isValidUser = function( self, username ) isValidUser = function( self, username )
local data = bin.pack("H", "00001e00000001000080000007320000700104020000fb2b2d00281f1e000000124c010000000000") local data = stdnse.fromhex("00001e00000001000080000007320000700104020000fb2b2d00281f1e000000124c010000000000")
local status, id_data local status, id_data
local data_len, pos, total_len, pkt_type, valid_user local data_len, pos, total_len, pkt_type, valid_user
self.domsock:send( tostring(DominoPacket:new( data )) ) self.domsock:send( tostring(DominoPacket:new( data )) )
data = DominoPacket:new():read( self.domsock ) data = DominoPacket:new():read( self.domsock )
data = bin.pack("HCHAH", "0100320002004f000100000500000900", #username + 1, "000000000000000000000000000000000028245573657273290000", username, "00") data = stdnse.fromhex("0100320002004f000100000500000900")
.. string.char(#username + 1)
.. stdnse.fromhex("000000000000000000000000000000000028245573657273290000")
.. string.pack("z", username)
self.domsock:send( tostring(DominoPacket:new( data ) ) ) self.domsock:send( tostring(DominoPacket:new( data ) ) )
status, id_data = DominoPacket:new():read( self.domsock ) status, id_data = DominoPacket:new():read( self.domsock )

View File

@@ -931,7 +931,7 @@ Packet.PostLogin = {
__tostring = function( self ) __tostring = function( self )
local unknown1 = "116b04" local unknown1 = "116b04"
local unknown2 = "0000002200000001000000033b05fefffffff4010000fefffffffeffffff" local unknown2 = "0000002200000001000000033b05fefffffff4010000fefffffffeffffff"
return string.pack(">I2HCH", self.flags) .. stdnse.fromhex(unknown1) .. string.char(self.sessid) .. stdnse.fromhex(unknown2) return string.pack(">I2", self.flags) .. stdnse.fromhex(unknown1) .. string.char(self.sessid) .. stdnse.fromhex(unknown2)
end end
} }