diff --git a/nselib/mssql.lua b/nselib/mssql.lua index 322d2ec4d..9d186f16e 100644 --- a/nselib/mssql.lua +++ b/nselib/mssql.lua @@ -103,7 +103,6 @@ -- listening on 43210/tcp, which was not scanned) will be reported but -- will not be stored for use by other ms-sql-* scripts. -local bin = require "bin" local math = require "math" local match = require "match" local nmap = require "nmap" @@ -623,7 +622,7 @@ SSRP = local instances local pos, messageType, dataLength = 1, nil, nil - pos, messageType, dataLength = bin.unpack(" 0 and len <= 16 ) then + coldata, pos = string.unpack("CSS", optionType, offset, optionLength ) + local data = { string.pack( ">BI2I2", optionType, offset, optionLength ) } offset = offset + optionLength optionType = PreLoginPacket.OPTION_TYPE.Encryption optionLength = OPTION_LENGTH_CLIENT[ optionType ] - data = data .. bin.pack( ">CSS", optionType, offset, optionLength ) + data[#data+1] = string.pack( ">BI2I2", optionType, offset, optionLength ) offset = offset + optionLength optionType = PreLoginPacket.OPTION_TYPE.InstOpt optionLength = #self._instanceName + 1 --(string length + null-terminator) - data = data .. bin.pack( ">CSS", optionType, offset, optionLength ) + data[#data+1] = string.pack( ">BI2I2", optionType, offset, optionLength ) offset = offset + optionLength optionType = PreLoginPacket.OPTION_TYPE.ThreadId optionLength = OPTION_LENGTH_CLIENT[ optionType ] - data = data .. bin.pack( ">CSS", optionType, offset, optionLength ) + data[#data+1] = string.pack( ">BI2I2", optionType, offset, optionLength ) offset = offset + optionLength if self.requestMars then optionType = PreLoginPacket.OPTION_TYPE.MARS optionLength = OPTION_LENGTH_CLIENT[ optionType ] - data = data .. bin.pack( ">CSS", optionType, offset, optionLength ) + data[#data+1] = string.pack( ">BI2I2", optionType, offset, optionLength ) offset = offset + optionLength end - data = data .. bin.pack( "C", PreLoginPacket.OPTION_TYPE.Terminator ) + data[#data+1] = string.pack( "B", PreLoginPacket.OPTION_TYPE.Terminator ) -- Now that the pre-login headers are done, write the data - data = data .. bin.pack( ">CCSS", self.versionInfo.major, self.versionInfo.minor, + data[#data+1] = string.pack( ">BBI2I2", self.versionInfo.major, self.versionInfo.minor, self.versionInfo.build, self.versionInfo.subBuild ) - data = data .. bin.pack( "C", self._requestEncryption ) - data = data .. bin.pack( "z", self._instanceName ) - data = data .. bin.pack( "CCSSCCA", packetType, messageStatus, packetLength, spid, self._packetId, window, packetData ) + local assembledPacket = string.pack(">BBI2I2BB", packetType, messageStatus, packetLength, spid, self._packetId, window) .. packetData if ( self._socket ) then return self._socket:send( assembledPacket ) @@ -2227,8 +2214,8 @@ TDSStream = { end -- read in the TDS headers - pos, packetType, messageStatus, packetLength = bin.unpack(">CCS", readBuffer, pos ) - pos, spid, self._packetId, window = bin.unpack(">SCC", readBuffer, pos ) + packetType, messageStatus, packetLength, pos = string.unpack(">BBI2", readBuffer, pos ) + spid, self._packetId, window, pos = string.unpack(">I2BB", readBuffer, pos ) -- TDS packet validity check: packet type is Response (0x4) if ( packetType ~= PacketType.Response ) then @@ -2806,7 +2793,7 @@ Helper = -- Iterate over tokens until we get to a rowtag while( pos < data:len() ) do - local rowtag = select(2, bin.unpack("C", data, pos)) + local rowtag = string.unpack("B", data, pos) if ( rowtag == TokenType.Row ) then break @@ -2828,7 +2815,7 @@ Helper = while(true) do local rowtag - pos, rowtag = bin.unpack("C", data, pos ) + rowtag, pos = string.unpack("B", data, pos ) if ( rowtag ~= TokenType.Row ) then break @@ -3044,7 +3031,7 @@ Helper = if ( #data < 6 ) then return nil end - return select(2, bin.unpack("> 4 ) & 0x0F0F local m2= ( c << 4 ) & 0xF0F0 - return bin.pack("