Lucene search
K

Cisco RV Authentication Bypass / Code Execution Vulnerability

🗓️ 20 Apr 2021 00:00:00Reported by T ShiomitsuType 
zdt
 zdt
🔗 0day.today👁 53 Views

Cisco RV series Authentication Bypass and Remote Command Execution Vulnerabilit

Related
Code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              title: Cisco RV series Authentication Bypass and Remote Command 
                     Execution
     vendor/product: Cisco (https://www.cisco.com/)
 vulnerable version: RV16X/RV26X: 1.0.01.02 & below.
                     RV34X: 1.0.03.20 & below.
      fixed version: RV16X/RV26X: 1.0.01.03. 
                     RV34X: 1.0.03.21.
         CVE number: CVE-2021-1472, CVE-2021-1473
             impact: 5.3 (medium) CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
                     8.8 (high)   CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L
           reported: 2021-01-02
        publication: 2021-04-14
                 by: T Shiomitsu, IoT Inspector Research Lab
                     https://www.iot-inspector.com/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Vendor description:
-------------------
The RV series devices are Cisco's line of small business routers with extra
functionality, including VPN and other security measures. 


Vulnerability overview/description:
-----------------------------------
All Cisco RV-series routers suffer from an authentication bypass vulnerability.
The RV34X series are also affected by a command injection vulnerability in the
sessionid cookie, when requesting the /upload endpoint. A combination of these
issues would allow any person who is able to communicate with the web 
interface to run arbitrary system commands on the router as the www-data user.


Root Cause Analysis:
--------------------
CVE-2021-1472: /upload Authentication Bypass Vulnerability

While Cisco has noted that this issue also affects the RV160, I will provide
a RCA for only the RV34X series here.

The RV340 web interface is served by nginx on port 443. The nginx configuration
(found in files in /etc/nginx) is such that requests made to the web interface
URIs /upload, /form-file-upload and 
/api/operations/ciscosb-file:form-file-upload are all proxied to a CGI binary 
called upload.cgi. Depending on which URI is requested, the behaviour of the 
binary will be slightly different.

While some attempt was introduced in recent firmware revisions to prevent 
unauthenticated access to the functionality available at the /upload endpoint,
the authentication check is incomplete. An attacker simply has to pass any 
generic Authorization header as part of the request to bypass the authorization
check. This can be seen in web.upload.conf:

[...snip...]
location /upload {
        set $deny 1;

        if ($http_authorization != "") {
                set $deny "0";
        }

        if (-f /tmp/websession/token/$cookie_sessionid) {
                set $deny "0";
        }

        if ($deny = "1") {
                return 403;
        }
[...snip...]

As can be seen, the $deny is set to 0 if the $cookie_sessionid is valid (i.e. 
that the authorization file exists on the system). But it also set to 0 if the
$http_authorization value (i.e. the Authorization header) is not blank. 
Therefore, passing any value to an Authorization header can allow an attacker
access to the /upload endpoint.

CVE-2021-1473: /upload sessionid Command Injection Remote Code Execution

Within the main() function in upload.cgi, the HTTP_COOKIE environmental 
variable is read, and the value from the sessionid cookie is extracted using 
a simple series of strtok_r and strstr. This specific sessionid-reading logic 
is notable because, due to the strtok_r call, it's not possible to use ";" 
characters in any injection, as it will prematurely terminate the injection 
string. In pseudocode, it looks like this:

if (HTTP_COOKIE != (char *)0x0) { 
     StrBufSetStr(cookie,HTTP_COOKIE); 
     cookie = StrBufToStr(cookie); 
     cookie = strtok_r(cookie, ";", &saveptr); 
     while (cookie != 0x0) { 
       cookie = strstr(cookie, "sessionid="); 
       if (cookie != 0x0) { 
         sessionid_cookie_value = pathparam_ + 10; 
       } 
     } 
   }

Because our HTTP request is made to the /upload URI, the main() function in 
upload.cgi calls a function at 000124a4, which I've named handle_upload(). 
This function takes a pointer to the sessionid cookie value as its first 
argument.

void handle_upload(char *sessionId, char *destination, char *option, 
    char *pathparam, char *fileparam, char *cert_name, char *cert_type, 
    char *password) 

It also takes several other arguments, each of which are populated by the 
multipart request parsing that takes place in the main() function. The names 
I've given these arguments roughly align with the names of the parameters 
that this multipart ingesting logic looks for.

(Depending on what string is passed as the pathparam parameter, slightly 
different code paths will be taken, which means that slightly different checks
must be bypassed to be able to reach the vulnerable code. In this example, I 
am using a request with the pathparam set to "Configuration", so the pseudocode
I'm showing reflects this.)

Within handle_upload(), a curl command is constructed with a call to sprintf, 
the resulting buffer of which is then passed directly to popen:

ret = strcmp(pathparam, "Configuration"); 
 if (ret == 0) { 
   config_json = upload_Configuration_json(destination,fileparam); 
   if (config_json != 0) { 
     post_data = json_object_to_json_string(config_json); 
     sprintf(command_buf, "curl %s --cookie \'sessionid=%s\' -X POST -H \'Content-Type: application/json\' -d\'%s\' ", jsonrpc_cgi, sessionId , post_data); 
     debug("curl_cmd=%s",command_buf); 
     __stream = popen(command_buf, "r"); 
     if (__stream != (FILE *)0x0) { 
       [...snip...] 
   }

The sessionid cookie value that we have passed in our request is passed 
directly into this sprintf() call. With a crafted sessionid value, we would 
therefore be able to inject arbitrary commands into this command buffer. This 
will run the command with the privileges of the upload.cgi process which, in 
this case, is www-data.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Vulnerable / tested versions:
-----------------------------
Cisco RV16X, RV26X and RV34X series devices.


Solution:
---------
Apply Cisco-supplied patch. For RV16X/26X, 1.0.01.03. For RV34X, 1.0.03.21.

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