Lucene search

K
nmapPatrik KarlssonNMAP:MONGODB-BRUTE.NSE
HistoryMar 02, 2012 - 12:28 p.m.

mongodb-brute NSE Script

2012-03-0212:28:30
Patrik Karlsson
nmap.org
440

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%

Performs brute force password auditing against the MongoDB database.

Script Arguments

mongodb-brute.db

Database against which to check. Default: admin

passdb, unpwdb.passlimit, unpwdb.timelimit, unpwdb.userlimit, userdb

See the documentation for the unpwdb library.

creds.[service], creds.global

See the documentation for the creds library.

mongodb.db

See the documentation for the mongodb library.

brute.credfile, brute.delay, brute.emptypass, brute.firstonly, brute.guesses, brute.mode, brute.passonly, brute.retries, brute.start, brute.threads, brute.unique, brute.useraspass

See the documentation for the brute library.

Example Usage

nmap -p 27017 <ip> --script mongodb-brute

Script Output

PORT      STATE SERVICE
27017/tcp open  mongodb
| mongodb-brute:
|   Accounts
|     root:Password1 - Valid credentials
|   Statistics
|_    Performed 3542 guesses in 9 seconds, average tps: 393

Requires


local brute = require "brute"
local creds = require "creds"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"

local mongodb = stdnse.silent_require "mongodb"

description = [[
Performs brute force password auditing against the MongoDB database.
]]

---
-- @usage
-- nmap -p 27017 <ip> --script mongodb-brute
--
-- @args mongodb-brute.db Database against which to check. Default: admin
--
-- @output
-- PORT      STATE SERVICE
-- 27017/tcp open  mongodb
-- | mongodb-brute:
-- |   Accounts
-- |     root:Password1 - Valid credentials
-- |   Statistics
-- |_    Performed 3542 guesses in 9 seconds, average tps: 393
--


author = "Patrik Karlsson"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"intrusive", "brute"}

local arg_db = stdnse.get_script_args(SCRIPT_NAME .. ".db") or "admin"

portrule = shortport.port_or_service({27017}, {"mongodb", "mongod"})

Driver = {

  new = function(self, host, port, options)
    local o = { host = host, port = port, sock = brute.new_socket() }
    setmetatable(o, self)
    self.__index = self
    return o
  end,

  connect = function(self)
    return self.sock:connect(self.host, self.port)
  end,

  login = function(self, username, password)
    local status, resp = mongodb.login(self.sock, arg_db, username, password)
    if ( status ) then
      return true, creds.Account:new(username, password, creds.State.VALID)
    elseif ( resp ~= "Authentication failed" ) then
      local err = brute.Error:new( resp )
      err:setRetry( true )
      return false, err
    end
    return false, brute.Error:new( "Incorrect password" )
  end,

  disconnect = function(self)
    return self.sock:close()
  end,

}

local function needsAuth(host, port)
  local socket = nmap.new_socket()
  local status, result = socket:connect(host, port)
  if ( not(status) ) then
    return false, "Failed to connect to server"
  end

  local packet
  status, packet = mongodb.listDbQuery()
  if ( not(status) ) then
    return false, result
  end

  --- Send packet
  status, result = mongodb.query(socket, packet)
  if ( not(status) ) then
    return false, result
  end

  socket:close()
  if ( status and result.errmsg ) then
    return true
  end
  return false
end

action = function(host, port)

  if ( not(needsAuth(host, port)) ) then
    return "No authentication needed"
  end

  local engine = brute.Engine:new(Driver, host, port )

  engine.options.script_name = SCRIPT_NAME
  engine.options.firstonly = true
  local status, result = engine:start()

  return result
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:MONGODB-BRUTE.NSE