mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Re-indent some scripts. Whitespace-only commit
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -55,7 +55,7 @@ categories = {"default", "safe"}
|
||||
|
||||
-- We don't report these methods except with verbosity.
|
||||
local UNINTERESTING_METHODS = {
|
||||
"GET", "HEAD", "POST", "OPTIONS"
|
||||
"GET", "HEAD", "POST", "OPTIONS"
|
||||
}
|
||||
|
||||
local filter_out, merge_headers
|
||||
@@ -63,92 +63,92 @@ local filter_out, merge_headers
|
||||
portrule = shortport.http
|
||||
|
||||
action = function(host, port)
|
||||
local url_path, retest_http_methods
|
||||
local response, methods, options_status_line, output
|
||||
local url_path, retest_http_methods
|
||||
local response, methods, options_status_line, output
|
||||
|
||||
-- default vaules for script-args
|
||||
url_path = stdnse.get_script_args("http-methods.url-path") or "/"
|
||||
retest_http_methods = stdnse.get_script_args("http-methods.retest") ~= nil
|
||||
-- default vaules for script-args
|
||||
url_path = stdnse.get_script_args("http-methods.url-path") or "/"
|
||||
retest_http_methods = stdnse.get_script_args("http-methods.retest") ~= nil
|
||||
|
||||
response = http.generic_request(host, port, "OPTIONS", url_path)
|
||||
if not response.status then
|
||||
stdnse.print_debug("http-methods: OPTIONS %s failed.", url_path)
|
||||
return
|
||||
end
|
||||
-- Cache in case retest is requested.
|
||||
options_status_line = response["status-line"]
|
||||
stdnse.print_debug("http-methods.nse: HTTP Status for OPTIONS is " .. response.status)
|
||||
response = http.generic_request(host, port, "OPTIONS", url_path)
|
||||
if not response.status then
|
||||
stdnse.print_debug("http-methods: OPTIONS %s failed.", url_path)
|
||||
return
|
||||
end
|
||||
-- Cache in case retest is requested.
|
||||
options_status_line = response["status-line"]
|
||||
stdnse.print_debug("http-methods.nse: HTTP Status for OPTIONS is " .. response.status)
|
||||
|
||||
if not (response.header["allow"] or response.header["public"]) then
|
||||
return string.format("No Allow or Public header in OPTIONS response (status code %d)", response.status)
|
||||
end
|
||||
if not (response.header["allow"] or response.header["public"]) then
|
||||
return string.format("No Allow or Public header in OPTIONS response (status code %d)", response.status)
|
||||
end
|
||||
|
||||
-- The Public header is defined in RFC 2068, but was removed in its
|
||||
-- successor RFC 2616. It is implemented by at least IIS 6.0.
|
||||
methods = merge_headers(response.header, {"Allow", "Public"})
|
||||
-- The Public header is defined in RFC 2068, but was removed in its
|
||||
-- successor RFC 2616. It is implemented by at least IIS 6.0.
|
||||
methods = merge_headers(response.header, {"Allow", "Public"})
|
||||
|
||||
output = {}
|
||||
output = {}
|
||||
|
||||
if nmap.verbosity() > 0 then
|
||||
output[#output + 1] = stdnse.strjoin(" ", methods)
|
||||
end
|
||||
if nmap.verbosity() > 0 then
|
||||
output[#output + 1] = stdnse.strjoin(" ", methods)
|
||||
end
|
||||
|
||||
local interesting = filter_out(methods, UNINTERESTING_METHODS)
|
||||
if #interesting > 0 then
|
||||
output[#output + 1] = "Potentially risky methods: " .. stdnse.strjoin(" ", interesting)
|
||||
output[#output + 1] = "See http://nmap.org/nsedoc/scripts/http-methods.html"
|
||||
end
|
||||
local interesting = filter_out(methods, UNINTERESTING_METHODS)
|
||||
if #interesting > 0 then
|
||||
output[#output + 1] = "Potentially risky methods: " .. stdnse.strjoin(" ", interesting)
|
||||
output[#output + 1] = "See http://nmap.org/nsedoc/scripts/http-methods.html"
|
||||
end
|
||||
|
||||
-- retest http methods if requested
|
||||
if retest_http_methods then
|
||||
local _
|
||||
for _, method in ipairs(methods) do
|
||||
local str
|
||||
if method == "OPTIONS" then
|
||||
-- Use the saved value.
|
||||
str = options_status_line
|
||||
else
|
||||
response = http.generic_request(host, port, method, url_path)
|
||||
if not response.status then
|
||||
str = "Error getting response"
|
||||
else
|
||||
str = response["status-line"]
|
||||
end
|
||||
end
|
||||
output[#output + 1] = string.format("%s %s -> %s", method, url_path, str)
|
||||
end
|
||||
end
|
||||
-- retest http methods if requested
|
||||
if retest_http_methods then
|
||||
local _
|
||||
for _, method in ipairs(methods) do
|
||||
local str
|
||||
if method == "OPTIONS" then
|
||||
-- Use the saved value.
|
||||
str = options_status_line
|
||||
else
|
||||
response = http.generic_request(host, port, method, url_path)
|
||||
if not response.status then
|
||||
str = "Error getting response"
|
||||
else
|
||||
str = response["status-line"]
|
||||
end
|
||||
end
|
||||
output[#output + 1] = string.format("%s %s -> %s", method, url_path, str)
|
||||
end
|
||||
end
|
||||
|
||||
return #output > 0 and stdnse.strjoin("\n", output) or nil
|
||||
return #output > 0 and stdnse.strjoin("\n", output) or nil
|
||||
end
|
||||
|
||||
function filter_out(t, filter)
|
||||
local result = {}
|
||||
local _, e, f
|
||||
for _, e in ipairs(t) do
|
||||
if not stdnse.contains(filter, e) then
|
||||
result[#result + 1] = e
|
||||
end
|
||||
end
|
||||
return result
|
||||
local result = {}
|
||||
local _, e, f
|
||||
for _, e in ipairs(t) do
|
||||
if not stdnse.contains(filter, e) then
|
||||
result[#result + 1] = e
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Split header field contents on commas and return a table without duplicates.
|
||||
function merge_headers(headers, names)
|
||||
local seen = {}
|
||||
local result = {}
|
||||
local seen = {}
|
||||
local result = {}
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
name = string.lower(name)
|
||||
if headers[name] then
|
||||
for _, v in ipairs(stdnse.strsplit(",%s*", headers[name])) do
|
||||
if not seen[v] then
|
||||
result[#result + 1] = v
|
||||
end
|
||||
seen[v] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, name in ipairs(names) do
|
||||
name = string.lower(name)
|
||||
if headers[name] then
|
||||
for _, v in ipairs(stdnse.strsplit(",%s*", headers[name])) do
|
||||
if not seen[v] then
|
||||
result[#result + 1] = v
|
||||
end
|
||||
seen[v] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
return result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user