Lucene search

K
nmapToni RuottuNMAP:HTTP-CORS.NSE
HistoryOct 04, 2011 - 6:22 a.m.

http-cors NSE Script

2011-10-0406:22:27
Toni Ruottu
nmap.org
106

9.8 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

NONE

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

10 High

CVSS2

Access Vector

NETWORK

Access Complexity

LOW

Authentication

NONE

Confidentiality Impact

COMPLETE

Integrity Impact

COMPLETE

Availability Impact

COMPLETE

AV:N/AC:L/Au:N/C:C/I:C/A:C

0.973 High

EPSS

Percentile

99.8%

Tests an http server for Cross-Origin Resource Sharing (CORS), a way for domains to explicitly opt in to having certain methods invoked by another domain.

The script works by setting the Access-Control-Request-Method header field for certain enumerated methods in OPTIONS requests, and checking the responses.

Script Arguments

http-cors.path

The path to request. Defaults to /.

http-cors.origin

The origin used with requests. Defaults to example.com.

slaxml.debug

See the documentation for the slaxml library.

http.host, http.max-body-size, http.max-cache-size, http.max-pipeline, http.pipeline, http.truncated-ok, http.useragent

See the documentation for the http library.

smbdomain, smbhash, smbnoguest, smbpassword, smbtype, smbusername

See the documentation for the smbauth library.

Example Usage

nmap -p 80 --script http-cors <target>

Script Output

80/tcp open
|_cors.nse: GET POST OPTIONS

Requires


local http = require "http"
local nmap = require "nmap"
local shortport = require "shortport"
local stringaux = require "stringaux"
local table = require "table"

description = [[
Tests an http server for Cross-Origin Resource Sharing (CORS), a way
for domains to explicitly opt in to having certain methods invoked by
another domain.

The script works by setting the Access-Control-Request-Method header
field for certain enumerated methods in OPTIONS requests, and checking
the responses.
]]

---
-- @args http-cors.path The path to request. Defaults to
-- <code>/</code>.
--
-- @args http-cors.origin The origin used with requests. Defaults to
-- <code>example.com</code>.
--
-- @usage
-- nmap -p 80 --script http-cors <target>
--
-- @output
-- 80/tcp open
-- |_cors.nse: GET POST OPTIONS


author = "Toni Ruottu"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"default", "discovery", "safe"}


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 = stringaux.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 = stringaux.strsplit(" ", raw)
  local nospace = table.concat(stuff, "")
  local allowed = stringaux.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
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 table.concat(allowed, " ")
  end
end

9.8 High

CVSS3

Attack Vector

NETWORK

Attack Complexity

LOW

Privileges Required

NONE

User Interaction

NONE

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

10 High

CVSS2

Access Vector

NETWORK

Access Complexity

LOW

Authentication

NONE

Confidentiality Impact

COMPLETE

Integrity Impact

COMPLETE

Availability Impact

COMPLETE

AV:N/AC:L/Au:N/C:C/I:C/A:C

0.973 High

EPSS

Percentile

99.8%

Related for NMAP:HTTP-CORS.NSE