mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Re-indent some more scripts. Whitespace-only commit
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -73,14 +73,14 @@ portrule = shortport.port_or_service(5060, "sip", {"tcp", "udp"})
|
||||
-- @return status true on success, false on failure.
|
||||
-- @return Response instance on success, error string on failure.
|
||||
local registerext = function(sess, ext)
|
||||
-- set session values
|
||||
local request = sip.Request:new(sip.Method.REGISTER)
|
||||
-- set session values
|
||||
local request = sip.Request:new(sip.Method.REGISTER)
|
||||
|
||||
request:setUri("sip:" .. sess.sessdata:getServer())
|
||||
sess.sessdata:setUsername(ext)
|
||||
request:setSessionData(sess.sessdata)
|
||||
request:setUri("sip:" .. sess.sessdata:getServer())
|
||||
sess.sessdata:setUsername(ext)
|
||||
request:setSessionData(sess.sessdata)
|
||||
|
||||
return sess:exch(request)
|
||||
return sess:exch(request)
|
||||
end
|
||||
|
||||
--- Function that returns a number as string with a number of zeroes padded to
|
||||
@@ -89,14 +89,14 @@ end
|
||||
-- @arg padding number of digits to pad up to.
|
||||
-- @return string of padded number.
|
||||
local padnum = function(num, padding)
|
||||
-- How many zeroes do we need to add
|
||||
local n = #tostring(num)
|
||||
if n >= padding then
|
||||
return tostring(num)
|
||||
end
|
||||
n = padding - n
|
||||
-- How many zeroes do we need to add
|
||||
local n = #tostring(num)
|
||||
if n >= padding then
|
||||
return tostring(num)
|
||||
end
|
||||
n = padding - n
|
||||
|
||||
return string.rep(tostring(0), n) .. tostring(num)
|
||||
return string.rep(tostring(0), n) .. tostring(num)
|
||||
end
|
||||
|
||||
--- Iterator function that returns values from a lower value up to a greater
|
||||
@@ -106,11 +106,11 @@ end
|
||||
-- @arg padding number of digits to pad up to.
|
||||
-- @return string current value.
|
||||
local numiterator = function(minval, maxval, padding)
|
||||
local i = minval - 1
|
||||
return function()
|
||||
i = i + 1
|
||||
if i <= maxval then return padnum(i, padding), '' end
|
||||
end
|
||||
local i = minval - 1
|
||||
return function()
|
||||
i = i + 1
|
||||
if i <= maxval then return padnum(i, padding), '' end
|
||||
end
|
||||
end
|
||||
|
||||
--- Iterator function that returns lines from a file
|
||||
@@ -118,19 +118,19 @@ end
|
||||
-- @return status false if error.
|
||||
-- @return string current line.
|
||||
local useriterator = function(list)
|
||||
local f = nmap.fetchfile(list) or list
|
||||
if not f then
|
||||
return false, ("\n ERROR: Couldn't find %s"):format(list)
|
||||
end
|
||||
f = io.open(f)
|
||||
if ( not(f) ) then
|
||||
return false, ("\n ERROR: Failed to open %s"):format(list)
|
||||
end
|
||||
return function()
|
||||
for line in f:lines() do
|
||||
return line
|
||||
end
|
||||
local f = nmap.fetchfile(list) or list
|
||||
if not f then
|
||||
return false, ("\n ERROR: Couldn't find %s"):format(list)
|
||||
end
|
||||
f = io.open(f)
|
||||
if ( not(f) ) then
|
||||
return false, ("\n ERROR: Failed to open %s"):format(list)
|
||||
end
|
||||
return function()
|
||||
for line in f:lines() do
|
||||
return line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- function that tests for 404 status code when sending a REGISTER request
|
||||
@@ -138,128 +138,128 @@ end
|
||||
-- @arg host Target host table.
|
||||
-- @arg port Target port table.
|
||||
local test404 = function(host, port)
|
||||
local session, status, randext, response
|
||||
-- Random extension
|
||||
randext = math.random(1234567,987654321)
|
||||
local session, status, randext, response
|
||||
-- Random extension
|
||||
randext = math.random(1234567,987654321)
|
||||
|
||||
session = sip.Session:new(host, port)
|
||||
status = session:connect()
|
||||
if not status then
|
||||
return false, "ERROR: Failed to connect to the SIP server."
|
||||
end
|
||||
session = sip.Session:new(host, port)
|
||||
status = session:connect()
|
||||
if not status then
|
||||
return false, "ERROR: Failed to connect to the SIP server."
|
||||
end
|
||||
|
||||
status, response = registerext(session, randext)
|
||||
if not status then
|
||||
return false, "ERROR: No response from the SIP server."
|
||||
end
|
||||
if response:getErrorCode() ~= 404 then
|
||||
return false, "Server not returning 404 for random extension."
|
||||
end
|
||||
return true
|
||||
status, response = registerext(session, randext)
|
||||
if not status then
|
||||
return false, "ERROR: No response from the SIP server."
|
||||
end
|
||||
if response:getErrorCode() ~= 404 then
|
||||
return false, "Server not returning 404 for random extension."
|
||||
end
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
Driver = {
|
||||
|
||||
new = function(self, host, port)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
o.host = host
|
||||
o.port = port
|
||||
return o
|
||||
end,
|
||||
new = function(self, host, port)
|
||||
local o = {}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
o.host = host
|
||||
o.port = port
|
||||
return o
|
||||
end,
|
||||
|
||||
connect = function( self )
|
||||
self.session = sip.Session:new(self.host, self.port)
|
||||
local status = self.session:connect()
|
||||
if ( not(status) ) then
|
||||
return false, brute.Error:new( "Couldn't connect to host" )
|
||||
end
|
||||
return true
|
||||
end,
|
||||
connect = function( self )
|
||||
self.session = sip.Session:new(self.host, self.port)
|
||||
local status = self.session:connect()
|
||||
if ( not(status) ) then
|
||||
return false, brute.Error:new( "Couldn't connect to host" )
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
login = function( self, username, password)
|
||||
-- We are using the "password" values instead of the "username" so we
|
||||
-- could benifit from brute.lua passonly option and setPasswordIterator
|
||||
-- function, as we are doing usernames enumeration only and not
|
||||
-- credentials brute forcing.
|
||||
local status, response, responsecode
|
||||
-- Send REGISTER request for each extension
|
||||
status, response = registerext(self.session, password)
|
||||
if status then
|
||||
responsecode = response:getErrorCode()
|
||||
-- If response status code is 401 or 407, then extension exists but
|
||||
-- requires authentication
|
||||
if responsecode == sip.Error.UNAUTHORIZED or
|
||||
responsecode == sip.Error.PROXY_AUTH_REQUIRED then
|
||||
return true, brute.Account:new(password, " Auth required", '')
|
||||
login = function( self, username, password)
|
||||
-- We are using the "password" values instead of the "username" so we
|
||||
-- could benifit from brute.lua passonly option and setPasswordIterator
|
||||
-- function, as we are doing usernames enumeration only and not
|
||||
-- credentials brute forcing.
|
||||
local status, response, responsecode
|
||||
-- Send REGISTER request for each extension
|
||||
status, response = registerext(self.session, password)
|
||||
if status then
|
||||
responsecode = response:getErrorCode()
|
||||
-- If response status code is 401 or 407, then extension exists but
|
||||
-- requires authentication
|
||||
if responsecode == sip.Error.UNAUTHORIZED or
|
||||
responsecode == sip.Error.PROXY_AUTH_REQUIRED then
|
||||
return true, brute.Account:new(password, " Auth required", '')
|
||||
|
||||
-- If response status code is 200, then extension exists
|
||||
-- and requires no authentication
|
||||
elseif responsecode == sip.Error.OK then
|
||||
return true, brute.Account:new(password, " No auth", '')
|
||||
-- If response status code is 200, then extension exists
|
||||
-- but access is forbidden.
|
||||
-- If response status code is 200, then extension exists
|
||||
-- and requires no authentication
|
||||
elseif responsecode == sip.Error.OK then
|
||||
return true, brute.Account:new(password, " No auth", '')
|
||||
-- If response status code is 200, then extension exists
|
||||
-- but access is forbidden.
|
||||
|
||||
elseif responsecode == sip.Error.FORBIDDEN then
|
||||
return true, brute.Account:new(password, " Forbidden", '')
|
||||
end
|
||||
return false,brute.Error:new( "Not found" )
|
||||
else
|
||||
return false,brute.Error:new( "No response" )
|
||||
end
|
||||
end,
|
||||
elseif responsecode == sip.Error.FORBIDDEN then
|
||||
return true, brute.Account:new(password, " Forbidden", '')
|
||||
end
|
||||
return false,brute.Error:new( "Not found" )
|
||||
else
|
||||
return false,brute.Error:new( "No response" )
|
||||
end
|
||||
end,
|
||||
|
||||
disconnect = function(self)
|
||||
self.session:close()
|
||||
return true
|
||||
end,
|
||||
disconnect = function(self)
|
||||
self.session:close()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
|
||||
action = function(host, port)
|
||||
local result, lthreads = {}, {}
|
||||
local status, err
|
||||
local minext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".minext")) or 0
|
||||
local minext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".minext")) or 0
|
||||
local maxext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".maxext")) or 999
|
||||
local padding = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".padding")) or 0
|
||||
local users = stdnse.get_script_args(SCRIPT_NAME .. ".users")
|
||||
local usersfile = stdnse.get_script_args(SCRIPT_NAME .. ".userslist")
|
||||
or "nselib/data/usernames.lst"
|
||||
local result, lthreads = {}, {}
|
||||
local status, err
|
||||
local minext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".minext")) or 0
|
||||
local minext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".minext")) or 0
|
||||
local maxext = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".maxext")) or 999
|
||||
local padding = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".padding")) or 0
|
||||
local users = stdnse.get_script_args(SCRIPT_NAME .. ".users")
|
||||
local usersfile = stdnse.get_script_args(SCRIPT_NAME .. ".userslist")
|
||||
or "nselib/data/usernames.lst"
|
||||
|
||||
-- min extension should be less than max extension.
|
||||
if minext > maxext then
|
||||
return "ERROR: maxext should be greater or equal than minext."
|
||||
end
|
||||
-- If not set to zero, number of digits to pad up to should have less or
|
||||
-- equal the number of digits of max extension.
|
||||
if padding ~= 0 and #tostring(maxext) > padding then
|
||||
return "ERROR: padding should be greater or equal to number of digits of maxext."
|
||||
-- min extension should be less than max extension.
|
||||
if minext > maxext then
|
||||
return "ERROR: maxext should be greater or equal than minext."
|
||||
end
|
||||
-- If not set to zero, number of digits to pad up to should have less or
|
||||
-- equal the number of digits of max extension.
|
||||
if padding ~= 0 and #tostring(maxext) > padding then
|
||||
return "ERROR: padding should be greater or equal to number of digits of maxext."
|
||||
end
|
||||
|
||||
-- We test for false positives by sending a request for a random extension
|
||||
-- and checking if it did return a 404.
|
||||
status, err = test404(host, port)
|
||||
if not status then
|
||||
return err
|
||||
end
|
||||
|
||||
local engine = brute.Engine:new(Driver, host, port)
|
||||
engine.options.script_name = SCRIPT_NAME
|
||||
|
||||
local iterator = numiterator(minext, maxext, padding)
|
||||
if users then
|
||||
local usernames, err = useriterator(usersfile)
|
||||
if not usernames then
|
||||
return err
|
||||
end
|
||||
-- Concat numbers and users iterators
|
||||
iterator = unpwdb.concat_iterators(iterator, usernames)
|
||||
end
|
||||
engine:setPasswordIterator(iterator)
|
||||
engine.options.passonly = true
|
||||
status, result = engine:start()
|
||||
|
||||
-- We test for false positives by sending a request for a random extension
|
||||
-- and checking if it did return a 404.
|
||||
status, err = test404(host, port)
|
||||
if not status then
|
||||
return err
|
||||
end
|
||||
|
||||
local engine = brute.Engine:new(Driver, host, port)
|
||||
engine.options.script_name = SCRIPT_NAME
|
||||
|
||||
local iterator = numiterator(minext, maxext, padding)
|
||||
if users then
|
||||
local usernames, err = useriterator(usersfile)
|
||||
if not usernames then
|
||||
return err
|
||||
end
|
||||
-- Concat numbers and users iterators
|
||||
iterator = unpwdb.concat_iterators(iterator, usernames)
|
||||
end
|
||||
engine:setPasswordIterator(iterator)
|
||||
engine.options.passonly = true
|
||||
status, result = engine:start()
|
||||
|
||||
return result
|
||||
return result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user