diff --git a/scripts/asn-query.nse b/scripts/asn-query.nse index 05e47fa28..20e154471 100644 --- a/scripts/asn-query.nse +++ b/scripts/asn-query.nse @@ -366,7 +366,7 @@ function get_prefix_length( range ) last = ipOps.ip_to_bin( last ):reverse() local hostbits = 0 - for pos = 1, string.len( first ), 1 do + for pos = 1, # first , 1 do if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then hostbits = hostbits + 1 @@ -376,7 +376,7 @@ function get_prefix_length( range ) end - return ( string.len( first ) - hostbits ) + return ( # first - hostbits ) end @@ -394,7 +394,7 @@ function get_assignment( ip, prefix ) if err then return nil, err end prefix = tonumber( prefix ) - if not prefix or ( prefix < 0 ) or ( prefix > string.len( some_ip ) ) then + if not prefix or ( prefix < 0 ) or ( prefix > # some_ip ) then return nil, "Error in get_assignment: Invalid prefix length." end diff --git a/scripts/dns-random-srcport.nse b/scripts/dns-random-srcport.nse index ab02f0173..c312f2a05 100644 --- a/scripts/dns-random-srcport.nse +++ b/scripts/dns-random-srcport.nse @@ -83,7 +83,7 @@ action = function(host, port) -- Now we need to "parse" the results to check to see if they are good -- We need a minimum of 5 bytes... - if (string.len(result) < 5) then + if (#result < 5) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Malformed response" else @@ -133,7 +133,7 @@ action = function(host, port) end -- We need a minimum of 128 bytes... - if (string.len(result) < 128) then + if (#result < 128) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Truncated response" else @@ -171,7 +171,7 @@ action = function(host, port) local txtlen = string.byte(result, 128) -- We now need a minimum of 128 + txtlen bytes + 1... - if (string.len(result) < 128 + txtlen) then + if (#result < 128 + txtlen) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Truncated response" else diff --git a/scripts/dns-random-txid.nse b/scripts/dns-random-txid.nse index 19ff303c6..151451a52 100644 --- a/scripts/dns-random-txid.nse +++ b/scripts/dns-random-txid.nse @@ -83,7 +83,7 @@ action = function(host, port) -- Now we need to "parse" the results to check to see if they are good -- We need a minimum of 5 bytes... - if (string.len(result) < 5) then + if (#result < 5) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Malformed response" else @@ -133,7 +133,7 @@ action = function(host, port) end -- We need a minimum of 128 bytes... - if (string.len(result) < 128) then + if (#result < 128) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Truncated response" else @@ -171,7 +171,7 @@ action = function(host, port) local txtlen = string.byte(result, 128) -- We now need a minimum of 128 + txtlen bytes + 1... - if (string.len(result) < 128 + txtlen) then + if (#result < 128 + txtlen) then if (nmap.verbosity() >= 2 or nmap.debugging() >= 1) then return "ERROR: Truncated response" else diff --git a/scripts/dns-zone-transfer.nse b/scripts/dns-zone-transfer.nse index bbe037f88..289923a69 100644 --- a/scripts/dns-zone-transfer.nse +++ b/scripts/dns-zone-transfer.nse @@ -228,7 +228,7 @@ function build_domain(host) -- prepend each element with its length while i <= #abs_name do - buf = buf .. string.char(string.len(abs_name[i])) .. abs_name[i] + buf = buf .. string.char(#abs_name[i]) .. abs_name[i] i = i + 1 end @@ -373,7 +373,7 @@ function responses_iter(data) return function() local length, remaining, response - remaining = string.len(data) - offset + 1 + remaining = #data - offset + 1 if remaining == 0 then return nil end @@ -551,7 +551,7 @@ action = function(host, port) local req_id = '\222\173' local offset = 1 local name = build_domain(string.lower(dns_opts.domain)) - local pkt_len = string.len(name) + 16 + local pkt_len = #name + 16 -- build axfr request local buf = strbuf.new() @@ -571,7 +571,7 @@ action = function(host, port) soc:close() local response_str = strbuf.dump(response) - local length = string.len(response_str) + local length = #response_str -- check server response code if length < 6 or diff --git a/scripts/http-title.nse b/scripts/http-title.nse index 666af41bd..33f0cef3c 100644 --- a/scripts/http-title.nse +++ b/scripts/http-title.nse @@ -75,7 +75,7 @@ action = function(host, port) if title and title ~= "" then result = string.gsub(title , "[\n\r\t]", "") - if string.len(title) > 65 then + if #title > 65 then stdnse.print_debug("http-title.nse: (%s) Title got truncated!", host.targetname or host.ip ); result = string.sub(result, 1, 62) .. "..." end diff --git a/scripts/iax2-version.nse b/scripts/iax2-version.nse index dd7302429..fbd3af4eb 100644 --- a/scripts/iax2-version.nse +++ b/scripts/iax2-version.nse @@ -32,7 +32,7 @@ action = function(host, port) return end - if (string.len(recv)) == 12 then + if (#recv) == 12 then local byte11 = string.format("%02X", string.byte(recv, 11)) local byte12 = string.format("%02X", string.byte(recv, 12)) diff --git a/scripts/nbstat.nse b/scripts/nbstat.nse index 95ba57b2d..e4d07330f 100644 --- a/scripts/nbstat.nse +++ b/scripts/nbstat.nse @@ -132,7 +132,7 @@ action = function(host) local names_output = {} names_output['name'] = "Names" for i = 1, #names, 1 do - local padding = string.rep(" ", 17 - string.len(names[i]['name'])) + local padding = string.rep(" ", 17 - #names[i]['name']) local flags_str = netbios.flags_to_string(names[i]['flags']) table.insert(names_output, string.format("%s<%02x>%sFlags: %s", names[i]['name'], names[i]['suffix'], padding, flags_str)) end diff --git a/scripts/p2p-conficker.nse b/scripts/p2p-conficker.nse index 188a49fc2..289b8b17a 100644 --- a/scripts/p2p-conficker.nse +++ b/scripts/p2p-conficker.nse @@ -243,9 +243,9 @@ end --@return An integer representing the checksum. local function p2p_checksum(data) local pos, i - local hash = string.len(data) + local hash = #data - stdnse.print_debug(2, "Conficker: Calculating checksum for %d-byte buffer", string.len(data)) + stdnse.print_debug(2, "Conficker: Calculating checksum for %d-byte buffer", #data) -- Get the first character pos, i = bin.unpack(" (string.len(response) - 2) do + while length > (#response - 2) do local response2 status, response2 = socket:receive_bytes(2) diff --git a/scripts/pptp-version.nse b/scripts/pptp-version.nse index 46f5c7c87..025016a73 100644 --- a/scripts/pptp-version.nse +++ b/scripts/pptp-version.nse @@ -71,7 +71,7 @@ action = function(host, port) -- get the vendor (should be 64 octets, but capture to end of the string to be safe) local s4, length - length = string.len(result) + length = #result s4 = string.sub(result, 88, length) vendor = string.match(s4, "(.-)%z") diff --git a/scripts/smb-psexec.nse b/scripts/smb-psexec.nse index c95ca5976..4c947e062 100644 --- a/scripts/smb-psexec.nse +++ b/scripts/smb-psexec.nse @@ -921,7 +921,7 @@ local function cipher(str, config) c = string.char(bit.bxor(c, string.byte(config.key, config.key_index + 1))) config.key_index = config.key_index + 1 - config.key_index = config.key_index % string.len(config.key) + config.key_index = config.key_index % #config.key result = result .. c end diff --git a/scripts/sql-injection.nse b/scripts/sql-injection.nse index f9181cefa..a0acd7371 100644 --- a/scripts/sql-injection.nse +++ b/scripts/sql-injection.nse @@ -177,7 +177,7 @@ local function find_links(list, base_path, page, host) for w in string.gmatch(page, 'href%s*=%s*"%s*[^"]+%s*"') do s, e = string.find(w, '"') - httpurl = string.sub(w, s+1, string.len(w)-1) + httpurl = string.sub(w, s+1, #w-1) i = 1 -- parse out duplicates, otherwise we'll be here all day diff --git a/scripts/sslv2.nse b/scripts/sslv2.nse index 5c53b5b2a..7af601961 100644 --- a/scripts/sslv2.nse +++ b/scripts/sslv2.nse @@ -61,7 +61,7 @@ cyphers = function(cypher_list, len) if (len == 0) then return "none"; end -- something's got broken along the way if these aren't equal - if (len ~= string.len(cypher_list)) then + if (len ~= #cypher_list) then return ""; end @@ -94,7 +94,7 @@ give_n_bytes = function(idx, n, str) -- returns the next n bytes of a string - if (idx + (n - 1) > string.len(str)) then + if (idx + (n - 1) > #str) then return (idx + n), string.rep(string.char(0x00), n); end @@ -173,8 +173,8 @@ action = function(host, port) return; end --try to get entire hello, if we don't already - if (string.len(server_hello) < server_hello_len) then - status, tmp = socket:receive_bytes(server_hello_len - string.len(server_hello)); + if (#server_hello < server_hello_len) then + status, tmp = socket:receive_bytes(server_hello_len - #server_hello); if (not status) then socket:close(); diff --git a/scripts/whois.nse b/scripts/whois.nse index 5bed15889..068f5b536 100644 --- a/scripts/whois.nse +++ b/scripts/whois.nse @@ -427,7 +427,7 @@ function get_prefix_length( range ) last = ipOps.ip_to_bin( last ):reverse() local hostbits = 0 - for pos = 1, string.len( first ), 1 do + for pos = 1, # first , 1 do if first:sub( pos, pos ) == "0" and last:sub( pos, pos ) == "1" then hostbits = hostbits + 1 @@ -437,7 +437,7 @@ function get_prefix_length( range ) end - return ( string.len( first ) - hostbits ) + return ( # first - hostbits ) end @@ -1159,7 +1159,7 @@ function get_assignment( ip, prefix ) if err then return nil, err end prefix = tonumber( prefix ) - if not prefix or ( prefix < 0 ) or ( prefix > string.len( some_ip ) ) then + if not prefix or ( prefix < 0 ) or ( prefix > # some_ip ) then return nil, "Error in get_assignment: Invalid prefix length." end