mirror of
https://github.com/nmap/nmap.git
synced 2025-12-27 01:49:03 +00:00
Remove trailing whitespace in lua files
Whitespace is not significant, so this should not be a problem. https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
132
nselib/rpcap.lua
132
nselib/rpcap.lua
@@ -34,20 +34,20 @@ local table = require "table"
|
||||
_ENV = stdnse.module("rpcap", stdnse.seeall)
|
||||
|
||||
RPCAP = {
|
||||
|
||||
|
||||
MessageType = {
|
||||
ERROR = 1,
|
||||
FIND_ALL_INTERFACES = 2,
|
||||
AUTH_REQUEST = 8,
|
||||
},
|
||||
|
||||
|
||||
-- Holds the two supported authentication mechanisms PWD and NULL
|
||||
Authentication = {
|
||||
|
||||
PWD = {
|
||||
|
||||
new = function(self, username, password)
|
||||
local o = {
|
||||
local o = {
|
||||
type = 1,
|
||||
username = username,
|
||||
password = password,
|
||||
@@ -56,37 +56,37 @@ RPCAP = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
__tostring = function(self)
|
||||
local DUMMY = 0
|
||||
return bin.pack(">SSSSAA", self.type, DUMMY, #self.username, #self.password, self.username, self.password)
|
||||
end,
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
NULL = {
|
||||
|
||||
|
||||
new = function(self)
|
||||
local o = {
|
||||
local o = {
|
||||
type = 0,
|
||||
}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
__tostring = function(self)
|
||||
local DUMMY = 0
|
||||
return bin.pack(">SSSS", self.type, DUMMY, 0, 0)
|
||||
end,
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
-- The common request and response header
|
||||
Header = {
|
||||
size = 8,
|
||||
size = 8,
|
||||
new = function(self, type, value, length)
|
||||
local o = {
|
||||
version = 0,
|
||||
@@ -98,25 +98,25 @@ RPCAP = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
parse = function(data)
|
||||
local header = RPCAP.Header:new()
|
||||
local pos
|
||||
pos, header.version, header.type, header.value, header.length = bin.unpack(">CCSI", data)
|
||||
return header
|
||||
end,
|
||||
|
||||
|
||||
__tostring = function(self)
|
||||
return bin.pack(">CCSI", self.version, self.type, self.value, self.length)
|
||||
end,
|
||||
|
||||
},
|
||||
|
||||
-- The implemented request types are kept here
|
||||
|
||||
-- The implemented request types are kept here
|
||||
Request = {
|
||||
|
||||
|
||||
Authentication = {
|
||||
|
||||
|
||||
new = function(self, data)
|
||||
local o = {
|
||||
header = RPCAP.Header:new(RPCAP.MessageType.AUTH_REQUEST, nil, #data),
|
||||
@@ -126,15 +126,15 @@ RPCAP = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
__tostring = function(self)
|
||||
return tostring(self.header) .. tostring(self.data)
|
||||
end,
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
FindAllInterfaces = {
|
||||
|
||||
|
||||
new = function(self)
|
||||
local o = {
|
||||
header = RPCAP.Header:new(RPCAP.MessageType.FIND_ALL_INTERFACES)
|
||||
@@ -143,27 +143,27 @@ RPCAP = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
__tostring = function(self)
|
||||
return tostring(self.header)
|
||||
end,
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
|
||||
-- Parsers for responses are kept here
|
||||
Response = {
|
||||
|
||||
Authentication = {
|
||||
|
||||
Authentication = {
|
||||
new = function(self)
|
||||
local o = { }
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
parse = function(data)
|
||||
local resp = RPCAP.Response.Authentication:new()
|
||||
local pos = RPCAP.Header.size + 1
|
||||
@@ -171,7 +171,7 @@ RPCAP = {
|
||||
return resp
|
||||
end
|
||||
},
|
||||
|
||||
|
||||
Error = {
|
||||
new = function(self)
|
||||
local o = { }
|
||||
@@ -187,9 +187,9 @@ RPCAP = {
|
||||
pos, err.error = bin.unpack("A" .. err.header.length, data, pos)
|
||||
return err
|
||||
end
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
FindAllInterfaces = {
|
||||
new = function(self)
|
||||
local o = { }
|
||||
@@ -197,7 +197,7 @@ RPCAP = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
parse = function(data)
|
||||
|
||||
-- Each address is made up of 4 128 byte fields, this function
|
||||
@@ -208,11 +208,11 @@ RPCAP = {
|
||||
local offset = pos
|
||||
local family, port
|
||||
pos, family, port = bin.unpack(">SS", data, pos)
|
||||
|
||||
|
||||
if ( family == 0x0017 ) then
|
||||
-- not sure why...
|
||||
pos = pos + 4
|
||||
|
||||
|
||||
local ipv6
|
||||
pos, ipv6 = bin.unpack("B16", data, pos)
|
||||
return offset + 128, ipOps.bin_to_ip(ipv6)
|
||||
@@ -221,27 +221,27 @@ RPCAP = {
|
||||
pos, ipv4 = bin.unpack("B4", data, pos)
|
||||
return offset + 128, ipOps.bin_to_ip(ipv4)
|
||||
end
|
||||
|
||||
|
||||
return offset + 128, nil
|
||||
end
|
||||
|
||||
|
||||
-- Parses one of X addresses returned for an interface
|
||||
local function parseAddress(data, pos)
|
||||
local fields = {"ip", "netmask", "bcast", "p2p"}
|
||||
local addr = {}
|
||||
|
||||
|
||||
for _, f in ipairs(fields) do
|
||||
pos, addr[f] = parseField(data, pos)
|
||||
end
|
||||
|
||||
return pos, addr
|
||||
end
|
||||
|
||||
|
||||
local resp = RPCAP.Response.FindAllInterfaces:new()
|
||||
local pos = RPCAP.Header.size + 1
|
||||
resp.header = RPCAP.Header.parse(data)
|
||||
resp.ifaces = {}
|
||||
|
||||
|
||||
for i=1, resp.header.value do
|
||||
local name_len, desc_len, iface_flags, addr_count, dummy
|
||||
pos, name_len, desc_len, iface_flags, addr_count, dummy = bin.unpack(">SSISS", data, pos)
|
||||
@@ -268,10 +268,10 @@ RPCAP = {
|
||||
return resp
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-- Maps packet types to classes
|
||||
@@ -284,7 +284,7 @@ RPCAP.TypeToClass = {
|
||||
|
||||
-- The communication class
|
||||
Comm = {
|
||||
|
||||
|
||||
-- Creates a new instance of the Comm class
|
||||
-- @param host table
|
||||
-- @param port table
|
||||
@@ -295,12 +295,12 @@ Comm = {
|
||||
self.__index = self
|
||||
return o
|
||||
end,
|
||||
|
||||
|
||||
-- Connects the socket to the server
|
||||
connect = function(self)
|
||||
return self.socket:connect(self.host, self.port)
|
||||
end,
|
||||
|
||||
|
||||
-- Sends an instance of the request class to the server
|
||||
-- @param req class instance
|
||||
-- @return status true on success, false on failure
|
||||
@@ -313,7 +313,7 @@ Comm = {
|
||||
-- in RPCAP.TypeToClass
|
||||
-- @return status true on success, false on failure
|
||||
-- @return resp instance of a Response class or
|
||||
-- err string containing the error message
|
||||
-- err string containing the error message
|
||||
recv = function(self)
|
||||
local status, hdr_data = self.socket:receive_buf(match.numbytes(RPCAP.Header.size), true)
|
||||
if ( not(status) ) then
|
||||
@@ -324,7 +324,7 @@ Comm = {
|
||||
if ( not(header) ) then
|
||||
return false, "rpcap: Failed to parse header"
|
||||
end
|
||||
|
||||
|
||||
local status, data = self.socket:receive_buf(match.numbytes(header.length), true)
|
||||
if ( not(status) ) then
|
||||
return false, "rpcap: Failed to read packet data"
|
||||
@@ -336,10 +336,10 @@ Comm = {
|
||||
return true, resp
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return false, "Failed to receive response from server"
|
||||
end,
|
||||
|
||||
|
||||
-- Sends and request and receives the response
|
||||
-- @param req the instance of the Request class to send
|
||||
-- @return status true on success, false on failure
|
||||
@@ -352,23 +352,23 @@ Comm = {
|
||||
end
|
||||
return self:recv()
|
||||
end,
|
||||
|
||||
|
||||
-- closes the socket
|
||||
close = function(self)
|
||||
return self.socket:close()
|
||||
end,
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Helper = {
|
||||
|
||||
|
||||
-- Creates a new instance of the Helper class
|
||||
-- @param host table
|
||||
-- @param port table
|
||||
-- @return o instance of Helper
|
||||
new = function(self, host, port)
|
||||
local o = {
|
||||
local o = {
|
||||
host = host,
|
||||
port = port,
|
||||
comm = Comm:new(host, port)
|
||||
@@ -382,7 +382,7 @@ Helper = {
|
||||
connect = function(self)
|
||||
return self.comm:connect(self.host, self.port)
|
||||
end,
|
||||
|
||||
|
||||
-- Authenticates to the service, in case no username or password is given
|
||||
-- NULL authentication is assumed.
|
||||
-- @param username [optional]
|
||||
@@ -391,20 +391,20 @@ Helper = {
|
||||
-- @return err string containing error mesage on failure
|
||||
login = function(self, username, password)
|
||||
local auth
|
||||
|
||||
|
||||
if ( username and password ) then
|
||||
auth = RPCAP.Authentication.PWD:new(username, password)
|
||||
else
|
||||
auth = RPCAP.Authentication.NULL:new()
|
||||
end
|
||||
|
||||
|
||||
local req = RPCAP.Request.Authentication:new(tostring(auth))
|
||||
local status, resp = self.comm:exch(req)
|
||||
|
||||
|
||||
if ( not(status) ) then
|
||||
return false, resp
|
||||
end
|
||||
|
||||
|
||||
if ( status and resp.error ) then
|
||||
return false, resp.error
|
||||
end
|
||||
@@ -416,11 +416,11 @@ Helper = {
|
||||
findAllInterfaces = function(self)
|
||||
local req = RPCAP.Request.FindAllInterfaces:new()
|
||||
local status, resp = self.comm:exch(req)
|
||||
|
||||
|
||||
if ( not(status) ) then
|
||||
return false, resp
|
||||
end
|
||||
|
||||
|
||||
local results = {}
|
||||
for _, iface in ipairs(resp.ifaces) do
|
||||
local entry = {}
|
||||
@@ -431,7 +431,7 @@ Helper = {
|
||||
end
|
||||
return true, results
|
||||
end,
|
||||
|
||||
|
||||
-- Closes the connection to the server
|
||||
close = function(self)
|
||||
return self.comm:close()
|
||||
|
||||
Reference in New Issue
Block a user