Lucene search
+L

MongoDB Detection (MongoDB Wire Protocol)

🗓️ 06 Aug 2010 00:00:00Reported by Copyright (C) 2010 Greenbone AGType 
openvas
 openvas
🔗 plugins.openvas.org👁 14 Views

Detects the installed version of MongoDB database. The script sends a connection request to the server and attempts to extract the version number from the reply

Refs
Code
SourceLink
mongodbwww.mongodb.com/
# SPDX-FileCopyrightText: 2010 Greenbone AG
# Some text descriptions might be excerpted from (a) referenced
# source(s), and are Copyright (C) by the respective right holder(s).
#
# SPDX-License-Identifier: GPL-2.0-only

if(description)
{
  script_oid("1.3.6.1.4.1.25623.1.0.100747");
  script_version("2026-01-09T05:47:51+0000");
  script_tag(name:"last_modification", value:"2026-01-09 05:47:51 +0000 (Fri, 09 Jan 2026)");
  script_tag(name:"creation_date", value:"2010-08-06 15:09:20 +0200 (Fri, 06 Aug 2010)");
  script_tag(name:"cvss_base", value:"0.0");
  script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:N/I:N/A:N");

  script_tag(name:"qod_type", value:"remote_banner");

  script_name("MongoDB Detection (MongoDB Wire Protocol)");

  script_category(ACT_GATHER_INFO);

  script_copyright("Copyright (C) 2010 Greenbone AG");
  script_family("Product detection");
  script_dependencies("find_service.nasl");
  script_require_ports("Services/www", "Services/mongodb", "Services/unknown", 27017);

  script_tag(name:"summary", value:"MongoDB Wire Protocol based detection of MongoDB.");

  script_xref(name:"URL", value:"https://www.mongodb.com/");

  exit(0);
}

include("cpe.inc");
include("dump.inc");
include("host_details.inc");
include("http_func.inc");
include("misc_func.inc");
include("port_service_func.inc");
include("list_array_func.inc");

ports = make_list();
unkwn_ports = unknownservice_get_ports( default_port_list:make_list( 27017 ) );
if( unkwn_ports )
  ports = make_list( ports, unkwn_ports );

# nb: Some MongoDB services seems to answer with a:
#
# HTTP/1.0 200 OK
# *snip*
# "It looks like you are trying to access MongoDB over HTTP on the native driver port."
#
# which will be detected by find_service.nasl as "Services/www". To catch such services
# on non-default ports we need to iterate over these services as well.
http_ports = http_get_ports( default_port_list:make_list( 27017 ) );
if( http_ports ) {

  foreach http_port( http_ports ) {
    banners = get_kb_list( "FindService/tcp/" + http_port + "/get_http" );
    if( ! banners )
      continue;

    foreach banner( banners ) {
      if( ! banner || banner !~ "It looks like you are trying to access MongoDB over HTTP on the native driver port" )
        continue;

      ports = make_list( ports, http_ports );
    }
  }
}

# Starting with GVM 20.04 the services detected as HTTP above are detected as MongoDB correctly.
# TODO: Once all GVM versions < 20.04 are EOL we can remove the HTTP code above.
mongo_ports = service_get_ports( default_port_list:make_list( 27017 ), proto:"mongodb" );
if( mongo_ports )
  ports = make_list( ports, mongo_ports );

ports = make_list_unique( ports );

req1 = raw_string(
  0x3c, 0x00, 0x00, 0x00,                # Message Length: 60
  0xff, 0x0d, 0xc2, 0xc0,                # Request ID
  0xff, 0xff, 0xff, 0xff,                # Response To
  0xd4, 0x07, 0x00, 0x00,                # OpCode: Query
  0x00, 0x00, 0x00, 0x00,                # Query Flags
  "admin",                               # Database Name
  0x2e,
  "$cmd",                                # Collection Name
  0x00,
  0x00, 0x00, 0x00, 0x00,                # Number to Skip: 0
  0x01, 0x00, 0x00, 0x00,                # Number to Return: 1
  # Query
  0x15, 0x00, 0x00, 0x00,                # Document length: 21
  0x10,                                  # Type: Int32
  "whatsmyuri",                          # Element
  0x00,
  0x01, 0x00, 0x00, 0x00,                # Value: 1
  0x00);

req2 = raw_string(
  0x3f, 0x00, 0x00, 0x00,                # Message Length: 63
  0x00, 0x0e, 0xc2, 0xc0,                # Request ID
  0xff, 0xff, 0xff, 0xff,                # Response To
  0xd4, 0x07, 0x00, 0x00,                # OpCode: Query
  0x00, 0x00, 0x00, 0x00,                # Query Flags
  "admin",                               # Database Name
  0x2e,
  "$cmd",                                # Collection Name
  0x00,
  0x00, 0x00, 0x00, 0x00,                # Number to Skip: 0
  0xff, 0xff, 0xff, 0xff,                # Number to Return: -1
  # Query
  0x18, 0x00, 0x00, 0x00,                # Document Length: 24
  0x01,                                  # Type: Double
  "buildinfo",                           # Element
  0x00,
  0x00, 0x00, 0x00, 0x00,                # Value: 1
  0x00, 0x00, 0xf0, 0x3f,
  0x00);

foreach port( ports ) {

  soc = open_sock_tcp( port );
  if( ! soc )
    continue;

  send( socket:soc, data:req1 );
  buf = recv( socket:soc, length:1024 );

  if( ! buf || ( "you" >!< buf && "OP_QUERY" >!< buf ) || "ok" >!< buf || "ff0dc2c0" >!< hexstr( buf ) ) { # ff0dc2c0 == response to above request id
    close( soc );
    continue;
  }

  version = "unknown";
  location = "/";

  service_register( port:port, proto:"mongodb" );

  send( socket:soc, data:req2 );
  buf = recv( socket:soc, length:1024 );
  close( soc );

  if( buf ) {
    txt = bin2string( ddata:buf );
    vers = eregmatch( pattern:"version([0-9.]+)(-)?(rc([0-9]))?", string:txt );
    if( vers[3] && vers[1] ) {
      version = vers[1] + "-" + vers[3];
    } else if( vers[1] && ! ( vers[3] ) ) {
      version = vers[1];
    }
  }

  set_kb_item( name:"mongodb/detected", value:TRUE );
  set_kb_item( name:"mongodb/wire_protocol/detected", value:TRUE );

  cpe = build_cpe( value:version, exp:"^([0-9.]+-?[a-zA-Z0-9]+?)", base:"cpe:/a:mongodb:mongodb:" );
  if( ! cpe )
    cpe = "cpe:/a:mongodb:mongodb";

  register_product( cpe:cpe, location:location, port:port, service:"mongodb" );

  log_message( data:build_detection_report( app:"MongoDB", version:version, install:location, cpe:cpe,
                                            concluded:vers[0] ),
               port:port );
}

exit( 0 );

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

09 Jan 2026 00:00Current
7High risk
Vulners AI Score7
14