mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Remove bin.lua from a couple libs
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
-- @author Patrik Karlsson <patrik@cqure.net>
|
-- @author Patrik Karlsson <patrik@cqure.net>
|
||||||
--
|
--
|
||||||
|
|
||||||
local bin = require "bin"
|
|
||||||
local ipOps = require "ipOps"
|
local ipOps = require "ipOps"
|
||||||
local match = require "match"
|
local match = require "match"
|
||||||
local math = require "math"
|
local math = require "math"
|
||||||
@@ -50,15 +49,14 @@ Header = {
|
|||||||
-- @name Header.parse
|
-- @name Header.parse
|
||||||
parse = function(data)
|
parse = function(data)
|
||||||
local header = Header:new()
|
local header = Header:new()
|
||||||
local pos
|
header.type, header.length, header.trans_id = string.unpack(">I2I2 c16", data)
|
||||||
pos, header.type, header.length, header.trans_id = bin.unpack(">SSA16", data)
|
|
||||||
return header
|
return header
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- converts the header to an opaque string
|
-- converts the header to an opaque string
|
||||||
-- @return string containing the header instance
|
-- @return string containing the header instance
|
||||||
__tostring = function(self)
|
__tostring = function(self)
|
||||||
return bin.pack(">SSA", self.type, self.length, self.trans_id)
|
return string.pack(">I2I2", self.type, self.length) .. self.trans_id
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,14 +133,12 @@ Attribute = {
|
|||||||
local attr = Attribute:new()
|
local attr = Attribute:new()
|
||||||
local pos = 1
|
local pos = 1
|
||||||
|
|
||||||
pos, attr.type, attr.length = bin.unpack(">SS", data, pos)
|
attr.type, attr.length, pos = string.unpack(">I2I2", data, pos)
|
||||||
|
|
||||||
local function parseAddress(data, pos)
|
local function parseAddress(data, pos)
|
||||||
local _, addr = nil, {}
|
local addr = {}
|
||||||
pos, _, addr.family, addr.port, addr.ip = bin.unpack(">CCSI", data, pos)
|
addr.family, addr.port, addr.ip, pos = string.unpack(">xBI2c4", data, pos)
|
||||||
if ( addr.ip ) then
|
addr.ip = ipOps.str_to_ip(addr.ip)
|
||||||
addr.ip = ipOps.fromdword(addr.ip)
|
|
||||||
end
|
|
||||||
return addr
|
return addr
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -155,7 +151,7 @@ Attribute = {
|
|||||||
end
|
end
|
||||||
attr.addr = parseAddress(data, pos)
|
attr.addr = parseAddress(data, pos)
|
||||||
elseif( attr.type == Attribute.SERVER ) then
|
elseif( attr.type == Attribute.SERVER ) then
|
||||||
pos, attr.server = bin.unpack("A" .. attr.length-1, data, pos)
|
attr.server = data:sub(pos, pos + attr.length - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
@@ -164,7 +160,7 @@ Attribute = {
|
|||||||
-- converts an attribute to string
|
-- converts an attribute to string
|
||||||
-- @return string containing the serialized attribute
|
-- @return string containing the serialized attribute
|
||||||
__tostring = function(self)
|
__tostring = function(self)
|
||||||
return bin.pack(">SSA", self.type, self.length, self.data or "")
|
return string.pack(">I2I2", self.type, self.length) .. (self.data or "")
|
||||||
end,
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -350,7 +346,7 @@ Helper = {
|
|||||||
if ( self.mode == "classic" ) then
|
if ( self.mode == "classic" ) then
|
||||||
trans_id = Util.randomString(16)
|
trans_id = Util.randomString(16)
|
||||||
else
|
else
|
||||||
trans_id = bin.pack("HA","2112A442", Util.randomString(12))
|
trans_id = "\x21\x12\xA4\x42" .. Util.randomString(12)
|
||||||
end
|
end
|
||||||
local req = Request.Bind:new(trans_id)
|
local req = Request.Bind:new(trans_id)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local bin = require "bin"
|
|
||||||
local match = require "match"
|
local match = require "match"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
@@ -60,8 +59,8 @@ Versant = {
|
|||||||
ver = ver or Versant.VERSION
|
ver = ver or Versant.VERSION
|
||||||
arg = arg or ""
|
arg = arg or ""
|
||||||
|
|
||||||
local data = bin.pack("Hzzz",
|
local data = stdnse.fromhex("000100000000000000020002000000010000000000000000000000000000000000010000")
|
||||||
"000100000000000000020002000000010000000000000000000000000000000000010000",
|
.. string.pack("zzz",
|
||||||
cmd,
|
cmd,
|
||||||
user,
|
user,
|
||||||
ver
|
ver
|
||||||
@@ -69,8 +68,8 @@ Versant = {
|
|||||||
-- align to even 4 bytes
|
-- align to even 4 bytes
|
||||||
data = data .. string.rep("\0", 4 - ((#data % 4) or 0))
|
data = data .. string.rep("\0", 4 - ((#data % 4) or 0))
|
||||||
|
|
||||||
data = data .. bin.pack("Hzxxxxxxxxxxz",
|
data = data .. stdnse.fromhex("0000000b000001000000000000000000")
|
||||||
"0000000b000001000000000000000000",
|
.. string.pack("zxxxxxxxxxxz",
|
||||||
("%s:%d"):format(self.host.ip, self.port.number),
|
("%s:%d"):format(self.host.ip, self.port.number),
|
||||||
arg
|
arg
|
||||||
)
|
)
|
||||||
@@ -109,7 +108,7 @@ Versant = {
|
|||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, db_count = bin.unpack(">I", data)
|
local db_count = string.unpack(">I4", data)
|
||||||
if ( db_count == 0 ) then
|
if ( db_count == 0 ) then
|
||||||
return false, "Database count was zero"
|
return false, "Database count was zero"
|
||||||
end
|
end
|
||||||
@@ -119,17 +118,17 @@ Versant = {
|
|||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, buf_size = bin.unpack(">I", data)
|
local buf_size = string.unpack(">I4", data)
|
||||||
local dbs = {}
|
local dbs = {}
|
||||||
|
|
||||||
for i=1, db_count do
|
for i=1, db_count do
|
||||||
status, data = self.socket:receive_buf(match.numbytes(buf_size), true)
|
status, data = self.socket:receive_buf(match.numbytes(buf_size), true)
|
||||||
local _, db = nil, {}
|
local db = {}
|
||||||
|
|
||||||
_, db.name = bin.unpack("z", data, 23)
|
db.name = string.unpack("z", data, 23)
|
||||||
_, db.owner = bin.unpack("z", data, 599)
|
db.owner = string.unpack("z", data, 599)
|
||||||
_, db.created= bin.unpack("z", data, 631)
|
db.created= string.unpack("z", data, 631)
|
||||||
_, db.version= bin.unpack("z", data, 663)
|
db.version= string.unpack("z", data, 663)
|
||||||
|
|
||||||
-- remove trailing line-feed
|
-- remove trailing line-feed
|
||||||
db.created = db.created:match("^(.-)\n*$")
|
db.created = db.created:match("^(.-)\n*$")
|
||||||
@@ -156,13 +155,13 @@ Versant = {
|
|||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos, success = bin.unpack(">I", data)
|
local success, pos = string.unpack(">I4", data)
|
||||||
if ( success ~= 0 ) then
|
if ( success ~= 0 ) then
|
||||||
return false, "Response contained invalid data"
|
return false, "Response contained invalid data"
|
||||||
end
|
end
|
||||||
|
|
||||||
local port = { protocol = "tcp" }
|
local port = { protocol = "tcp" }
|
||||||
pos, port.number = bin.unpack(">S", data, pos)
|
port.number, pos = string.unpack(">I2", data, pos)
|
||||||
|
|
||||||
return true, port
|
return true, port
|
||||||
end,
|
end,
|
||||||
@@ -183,7 +182,7 @@ Versant = {
|
|||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, len = bin.unpack(">I", data)
|
local len = string.unpack(">I4", data)
|
||||||
if ( len == 0 ) then
|
if ( len == 0 ) then
|
||||||
return false, "Failed to retrieve license file"
|
return false, "Failed to retrieve license file"
|
||||||
end
|
end
|
||||||
@@ -210,8 +209,8 @@ Versant = {
|
|||||||
return false, "Failed to connect to database"
|
return false, "Failed to connect to database"
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, port = nil, { protocol = "tcp" }
|
local port = { protocol = "tcp" }
|
||||||
_, port.number = bin.unpack(">I", data, 27)
|
port.number = string.unpack(">I4", data, 27)
|
||||||
if ( port == 0 ) then
|
if ( port == 0 ) then
|
||||||
return false, "Failed to determine database port"
|
return false, "Failed to determine database port"
|
||||||
end
|
end
|
||||||
@@ -254,10 +253,9 @@ Versant.OBE = {
|
|||||||
-- <code>lib_path</code> - the library directory
|
-- <code>lib_path</code> - the library directory
|
||||||
-- <code>hostname</code> - the database host name
|
-- <code>hostname</code> - the database host name
|
||||||
getVODInfo = function(self)
|
getVODInfo = function(self)
|
||||||
local data = bin.pack("Hz",
|
local data = stdnse.fromhex("1002005d00000000000100000000000d000000000000000000000000") --28
|
||||||
"1002005d00000000000100000000000d000000000000000000000000", --28
|
.. "-noprint -i " --12
|
||||||
"-noprint -i " --12 + 1 (for null)
|
.. string.rep("\0", 216) -- 256 - (28 + 12)
|
||||||
) .. string.rep("\0", 215) -- 256 - (28 + 12 + 1)
|
|
||||||
|
|
||||||
self.socket:send(data)
|
self.socket:send(data)
|
||||||
local status, data = self.socket:receive_buf(match.numbytes(256), true)
|
local status, data = self.socket:receive_buf(match.numbytes(256), true)
|
||||||
@@ -265,17 +263,18 @@ Versant.OBE = {
|
|||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos, len = bin.unpack(">I", data, 13)
|
local len = string.unpack(">I4", data, 13)
|
||||||
status, data = self.socket:receive_buf(match.numbytes(len), true)
|
status, data = self.socket:receive_buf(match.numbytes(len), true)
|
||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
return false, "Failed to read response from server"
|
return false, "Failed to read response from server"
|
||||||
end
|
end
|
||||||
|
|
||||||
local result, pos, offset = {}, 1, 13
|
local result = {}
|
||||||
pos, result.version = bin.unpack("z", data)
|
local offset = 13
|
||||||
|
result.version = string.unpack("z", data)
|
||||||
|
|
||||||
for _, item in ipairs({"root_path", "db_path", "lib_path", "hostname"}) do
|
for _, item in ipairs({"root_path", "db_path", "lib_path", "hostname"}) do
|
||||||
pos, result[item] = bin.unpack("z", data, offset)
|
result[item] = string.unpack("z", data, offset)
|
||||||
offset = offset + 256
|
offset = offset + 256
|
||||||
end
|
end
|
||||||
return true, result
|
return true, result
|
||||||
|
|||||||
Reference in New Issue
Block a user