mirror of
https://github.com/nmap/nmap.git
synced 2025-12-08 05:31:31 +00:00
check_globals cleanup
This commit is contained in:
@@ -91,9 +91,10 @@ function sendcmd (socket, command, cnt)
|
|||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
return false, "error receiving length"
|
return false, "error receiving length"
|
||||||
end
|
end
|
||||||
_,size = bin.unpack(">I",response,1)
|
local _,size = bin.unpack(">I",response,1)
|
||||||
|
|
||||||
if (string.len(response) < size+4 ) then
|
if (string.len(response) < size+4 ) then
|
||||||
|
local resp2
|
||||||
status, resp2 = socket:receive_bytes(size+4 - string.len(response))
|
status, resp2 = socket:receive_bytes(size+4 - string.len(response))
|
||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
return false, "error receiving payload"
|
return false, "error receiving payload"
|
||||||
@@ -116,7 +117,6 @@ end
|
|||||||
--@return result : value if status ok, error msg if bad
|
--@return result : value if status ok, error msg if bad
|
||||||
function describe_cluster_name (socket,cnt)
|
function describe_cluster_name (socket,cnt)
|
||||||
local cname = "describe_cluster_name"
|
local cname = "describe_cluster_name"
|
||||||
local size
|
|
||||||
local status,resp = sendcmd(socket,cname,cnt)
|
local status,resp = sendcmd(socket,cname,cnt)
|
||||||
|
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
@@ -126,8 +126,8 @@ function describe_cluster_name (socket,cnt)
|
|||||||
|
|
||||||
-- grab the size
|
-- grab the size
|
||||||
-- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position
|
-- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position
|
||||||
position = 12+string.len(cname)+7+1
|
local position = 12+string.len(cname)+7+1
|
||||||
_,size = bin.unpack(">I",resp,position)
|
local _,size = bin.unpack(">I",resp,position)
|
||||||
|
|
||||||
-- read the string after the size
|
-- read the string after the size
|
||||||
local value = string.sub(resp,position+4,position+4+size-1)
|
local value = string.sub(resp,position+4,position+4+size-1)
|
||||||
@@ -141,7 +141,6 @@ end
|
|||||||
--@return result : value if status ok, error msg if bad
|
--@return result : value if status ok, error msg if bad
|
||||||
function describe_version (socket,cnt)
|
function describe_version (socket,cnt)
|
||||||
local cname = "describe_version"
|
local cname = "describe_version"
|
||||||
local size
|
|
||||||
local status,resp = sendcmd(socket,cname,cnt)
|
local status,resp = sendcmd(socket,cname,cnt)
|
||||||
|
|
||||||
if (not(status)) then
|
if (not(status)) then
|
||||||
@@ -151,8 +150,8 @@ function describe_version (socket,cnt)
|
|||||||
|
|
||||||
-- grab the size
|
-- grab the size
|
||||||
-- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position
|
-- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position
|
||||||
position = 12+string.len(cname)+7+1
|
local position = 12+string.len(cname)+7+1
|
||||||
_,size = bin.unpack(">I",resp,position)
|
local _,size = bin.unpack(">I",resp,position)
|
||||||
|
|
||||||
-- read the string after the size
|
-- read the string after the size
|
||||||
local value = string.sub(resp,position+4,position+4+size-1)
|
local value = string.sub(resp,position+4,position+4+size-1)
|
||||||
@@ -182,19 +181,20 @@ function login (socket,username,password)
|
|||||||
return false, err
|
return false, err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local response
|
||||||
status, response = socket:receive_bytes(22)
|
status, response = socket:receive_bytes(22)
|
||||||
if ( not(status) ) then
|
if ( not(status) ) then
|
||||||
stdnse.print_debug(3, "Receive packet for "..combo)
|
stdnse.print_debug(3, "Receive packet for "..combo)
|
||||||
return false, err
|
return false, err
|
||||||
end
|
end
|
||||||
_, size = bin.unpack(">I", response, 1)
|
local _, size = bin.unpack(">I", response, 1)
|
||||||
|
|
||||||
loginresp = string.sub(response,5,17)
|
loginresp = string.sub(response,5,17)
|
||||||
if (loginresp ~= CASSANDRARESP..pack4str("login")) then
|
if (loginresp ~= CASSANDRARESP..pack4str("login")) then
|
||||||
return false, "protocol error"
|
return false, "protocol error"
|
||||||
end
|
end
|
||||||
|
|
||||||
magic = string.sub(response,18,22)
|
local magic = string.sub(response,18,22)
|
||||||
stdnse.print_debug(3, "packet for "..combo)
|
stdnse.print_debug(3, "packet for "..combo)
|
||||||
stdnse.print_debug(3, "packet hex: %s", stdnse.tohex(response) )
|
stdnse.print_debug(3, "packet hex: %s", stdnse.tohex(response) )
|
||||||
stdnse.print_debug(3, "size packet hex: %s", stdnse.tohex(size) )
|
stdnse.print_debug(3, "size packet hex: %s", stdnse.tohex(size) )
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ Comm = {
|
|||||||
if nmap.is_privileged() then
|
if nmap.is_privileged() then
|
||||||
-- Try to bind to a reserved port
|
-- Try to bind to a reserved port
|
||||||
for i = 1, 10, 1 do
|
for i = 1, 10, 1 do
|
||||||
resvport = math.random(1, 1024)
|
local resvport = math.random(1, 1024)
|
||||||
socket = nmap.new_socket()
|
socket = nmap.new_socket()
|
||||||
status, err = socket:bind(nil, resvport)
|
status, err = socket:bind(nil, resvport)
|
||||||
if status then
|
if status then
|
||||||
@@ -184,7 +184,7 @@ Comm = {
|
|||||||
if nmap.is_privileged() then
|
if nmap.is_privileged() then
|
||||||
-- Try to bind to a reserved port
|
-- Try to bind to a reserved port
|
||||||
for i = 1, 10, 1 do
|
for i = 1, 10, 1 do
|
||||||
resvport = math.random(1, 1024)
|
local resvport = math.random(1, 1024)
|
||||||
socket = nmap.new_socket("udp")
|
socket = nmap.new_socket("udp")
|
||||||
status, err = socket:bind(nil, resvport)
|
status, err = socket:bind(nil, resvport)
|
||||||
if status then break end
|
if status then break end
|
||||||
|
|||||||
@@ -680,8 +680,8 @@ function get_security_blob(security_blob, ip, username, domain, password, passwo
|
|||||||
local lanman, ntlm, mac_key = get_password_response(ip, username, domain, password, password_hash, hash_type, challenge, true)
|
local lanman, ntlm, mac_key = get_password_response(ip, username, domain, password, password_hash, hash_type, challenge, true)
|
||||||
|
|
||||||
-- Convert the username and domain to unicode (TODO: Disable the unicode flag, evaluate if that'll work)
|
-- Convert the username and domain to unicode (TODO: Disable the unicode flag, evaluate if that'll work)
|
||||||
|
local hostname = to_unicode("nmap")
|
||||||
username = to_unicode(username)
|
username = to_unicode(username)
|
||||||
hostname = to_unicode("nmap")
|
|
||||||
domain = (#username > 0 ) and to_unicode(domain) or ""
|
domain = (#username > 0 ) and to_unicode(domain) or ""
|
||||||
ntlm = (#username > 0 ) and ntlm or ""
|
ntlm = (#username > 0 ) and ntlm or ""
|
||||||
lanman = (#username > 0 ) and lanman or string.char(0)
|
lanman = (#username > 0 ) and lanman or string.char(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user