From 40b1c4705be2729458920d5daaad0209cc194ecc Mon Sep 17 00:00:00 2001 From: patrik Date: Sun, 7 Oct 2012 12:39:21 +0000 Subject: [PATCH] check_globals cleanup --- nselib/cassandra.lua | 18 +++++++++--------- nselib/rpc.lua | 4 ++-- nselib/smbauth.lua | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nselib/cassandra.lua b/nselib/cassandra.lua index 86f895f15..c5bbada6c 100644 --- a/nselib/cassandra.lua +++ b/nselib/cassandra.lua @@ -91,9 +91,10 @@ function sendcmd (socket, command, cnt) if ( not(status) ) then return false, "error receiving length" end - _,size = bin.unpack(">I",response,1) + local _,size = bin.unpack(">I",response,1) if (string.len(response) < size+4 ) then + local resp2 status, resp2 = socket:receive_bytes(size+4 - string.len(response)) if ( not(status) ) then return false, "error receiving payload" @@ -116,7 +117,6 @@ end --@return result : value if status ok, error msg if bad function describe_cluster_name (socket,cnt) local cname = "describe_cluster_name" - local size local status,resp = sendcmd(socket,cname,cnt) if (not(status)) then @@ -126,8 +126,8 @@ function describe_cluster_name (socket,cnt) -- grab the size -- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position - position = 12+string.len(cname)+7+1 - _,size = bin.unpack(">I",resp,position) + local position = 12+string.len(cname)+7+1 + local _,size = bin.unpack(">I",resp,position) -- read the string after the size 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 function describe_version (socket,cnt) local cname = "describe_version" - local size local status,resp = sendcmd(socket,cname,cnt) if (not(status)) then @@ -151,8 +150,8 @@ function describe_version (socket,cnt) -- grab the size -- pktlen(4) + CASSANDRARESP(4) + lencmd(4) + lencmd(v) + params(7) + next byte position - position = 12+string.len(cname)+7+1 - _,size = bin.unpack(">I",resp,position) + local position = 12+string.len(cname)+7+1 + local _,size = bin.unpack(">I",resp,position) -- read the string after the size local value = string.sub(resp,position+4,position+4+size-1) @@ -182,19 +181,20 @@ function login (socket,username,password) return false, err end + local response status, response = socket:receive_bytes(22) if ( not(status) ) then stdnse.print_debug(3, "Receive packet for "..combo) return false, err end - _, size = bin.unpack(">I", response, 1) + local _, size = bin.unpack(">I", response, 1) loginresp = string.sub(response,5,17) if (loginresp ~= CASSANDRARESP..pack4str("login")) then return false, "protocol error" 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 hex: %s", stdnse.tohex(response) ) stdnse.print_debug(3, "size packet hex: %s", stdnse.tohex(size) ) diff --git a/nselib/rpc.lua b/nselib/rpc.lua index 3efb7d533..1399b6a05 100644 --- a/nselib/rpc.lua +++ b/nselib/rpc.lua @@ -167,7 +167,7 @@ Comm = { if nmap.is_privileged() then -- Try to bind to a reserved port for i = 1, 10, 1 do - resvport = math.random(1, 1024) + local resvport = math.random(1, 1024) socket = nmap.new_socket() status, err = socket:bind(nil, resvport) if status then @@ -184,7 +184,7 @@ Comm = { if nmap.is_privileged() then -- Try to bind to a reserved port for i = 1, 10, 1 do - resvport = math.random(1, 1024) + local resvport = math.random(1, 1024) socket = nmap.new_socket("udp") status, err = socket:bind(nil, resvport) if status then break end diff --git a/nselib/smbauth.lua b/nselib/smbauth.lua index 20515787c..cccd08829 100644 --- a/nselib/smbauth.lua +++ b/nselib/smbauth.lua @@ -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) -- 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) - hostname = to_unicode("nmap") domain = (#username > 0 ) and to_unicode(domain) or "" ntlm = (#username > 0 ) and ntlm or "" lanman = (#username > 0 ) and lanman or string.char(0)