mirror of
https://github.com/nmap/nmap.git
synced 2025-12-25 00:49:01 +00:00
Re-indent some scripts. Whitespace-only commit
https://secwiki.org/w/Nmap/Code_Standards
This commit is contained in:
@@ -39,62 +39,62 @@ portrule = shortport.http
|
||||
local methods = {"HEAD", "GET", "POST", "PUT", "DELETE", "TRACE", "OPTIONS", "CONNECT", "PATCH"}
|
||||
|
||||
local function origin_ok(raw, origin)
|
||||
if not raw then
|
||||
return false
|
||||
end
|
||||
if raw == "*" then
|
||||
return true
|
||||
end
|
||||
if raw == "null" then
|
||||
return false
|
||||
end
|
||||
local allowed = stdnse.strsplit(" ", raw)
|
||||
for _, ao in ipairs(allowed) do
|
||||
if origin == ao then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
if not raw then
|
||||
return false
|
||||
end
|
||||
if raw == "*" then
|
||||
return true
|
||||
end
|
||||
if raw == "null" then
|
||||
return false
|
||||
end
|
||||
local allowed = stdnse.strsplit(" ", raw)
|
||||
for _, ao in ipairs(allowed) do
|
||||
if origin == ao then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function method_ok(raw, method)
|
||||
if not raw then
|
||||
return false
|
||||
end
|
||||
local stuff = stdnse.strsplit(" ", raw)
|
||||
local nospace = stdnse.strjoin("", stuff)
|
||||
local allowed = stdnse.strsplit(",", nospace)
|
||||
for _, am in ipairs(allowed) do
|
||||
if method == am then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
if not raw then
|
||||
return false
|
||||
end
|
||||
local stuff = stdnse.strsplit(" ", raw)
|
||||
local nospace = stdnse.strjoin("", stuff)
|
||||
local allowed = stdnse.strsplit(",", nospace)
|
||||
for _, am in ipairs(allowed) do
|
||||
if method == am then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function test(host, port, method, origin)
|
||||
local header = {
|
||||
["Origin"] = origin,
|
||||
["Access-Control-Request-Method"] = method,
|
||||
}
|
||||
local response = http.generic_request(host, port, "OPTIONS", "/", {header = header})
|
||||
local aorigins = response.header["access-control-allow-origin"]
|
||||
local amethods = response.header["access-control-allow-methods"]
|
||||
local ook = origin_ok(aorigins, response)
|
||||
local mok = method_ok(amethods, method)
|
||||
return ook and mok
|
||||
local header = {
|
||||
["Origin"] = origin,
|
||||
["Access-Control-Request-Method"] = method,
|
||||
}
|
||||
local response = http.generic_request(host, port, "OPTIONS", "/", {header = header})
|
||||
local aorigins = response.header["access-control-allow-origin"]
|
||||
local amethods = response.header["access-control-allow-methods"]
|
||||
local ook = origin_ok(aorigins, response)
|
||||
local mok = method_ok(amethods, method)
|
||||
return ook and mok
|
||||
end
|
||||
|
||||
action = function(host, port)
|
||||
local path = nmap.registry.args["http-cors.path"] or "/"
|
||||
local origin = nmap.registry.args["http-cors.origin"] or "example.com"
|
||||
local allowed = {}
|
||||
for _, method in ipairs(methods) do
|
||||
if test(host, port, method, origin) then
|
||||
table.insert(allowed, method)
|
||||
end
|
||||
end
|
||||
if #allowed > 0 then
|
||||
return stdnse.strjoin(" ", allowed)
|
||||
end
|
||||
local path = nmap.registry.args["http-cors.path"] or "/"
|
||||
local origin = nmap.registry.args["http-cors.origin"] or "example.com"
|
||||
local allowed = {}
|
||||
for _, method in ipairs(methods) do
|
||||
if test(host, port, method, origin) then
|
||||
table.insert(allowed, method)
|
||||
end
|
||||
end
|
||||
if #allowed > 0 then
|
||||
return stdnse.strjoin(" ", allowed)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user