Pwning a Cisco RV340 漏洞分析(CVE-2022-20705 和 CVE-2022-20707
2022-4-2 00:0:0 Author: bestwing.me(查看原文) 阅读量:278 收藏

原作者用到了四个漏洞, 我这里简单分析其中两个,分别是 CVE-2022-20705 和 CVE-2022-20707

漏洞描述

影响版本: RV34X-v1.0.03.22-2021-06-14-02-33-28-AM.img

Relyze Software Limited - Advanced Software Analysis: Pwning a Cisco RV340 with a 4 bug chain exploit

固件下载

Software Download - Cisco Systems

CVE-2022-20705 Improper Session Management Vulnerability

Nginx 配置不当加上 upload.cgi 对 cookie 两者处理不一致导致的授权绕过。

首先 nginx 对 upload 模块的 session 的处理如下:

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
$ cat web.upload.conf
location /form-file-upload {
include uwsgi_params;
proxy_buffering off;
uwsgi_modifier1 9;
uwsgi_pass 127.0.0.1:9003;
uwsgi_read_timeout 3600;
uwsgi_send_timeout 3600;
}

location /upload {
set $deny 1;

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

if ($deny = "1") {
return 403;
}

upload_pass /form-file-upload;
upload_store /tmp/upload;
upload_store_access user:rw group:rw all:rw;
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
upload_resumable on;
}

可以发现, 这里是判断如果 /tmp/websession/token/$cookie_sessionid 文件存在,则返回。 注意这里的 $cookie_sessionid 是由用户在 HTTP 请求中传入的。可以看到这里的文件没有判断是否存在 ../../ 。因此如果我们跨目录指向一个存在的文件就可能造成授权绕过。像这里作者使用的是 ../../../etc/firmware_version

虽然在 upload.cgi 对 HTTP_COOKIE 进行了正则校验

1
2
3
4
5
6
7
8
9
10
11
12
13
14
v16 = strcmp_1(REQUEST_URI, "/api/operations/ciscosb-file:form-file-upload");
if (v16 != 0) {
v17 = strcmp_1(REQUEST_URI, "/upload");
if (v17 == 0 && HTTP_COOKIE != 0) {
v18 = strlen_1(HTTP_COOKIE);
if (v18 < 81) {
v19 = match_regex("^[A-Za-z0-9+=/]*$", HTTP_COOKIE);
if (v19 == 0) {
v20 = StrBufToStr(local_0x44);
func_0x2684(HTTP_COOKIE, content_destination, content_option, content_pathparam, v20, content_cert_name, content_cert_type, content_password);
}
}
}
}

但是在程序没有考虑用户在 HTTP cookie 中传入多个 session_id 的情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (HTTP_COOKIE != 0) { 
StrBufSetStr(cookie_str, HTTP_COOKIE);
__s2 = StrBufToStr(cookie_str);
next_semicolon = strtok_r(__s2, ";", &saveptr);
HTTP_COOKIE = 0;
while (next_semicolon != 0) {
sessionid = strstr(next_semicolon, "sessionid=");
if (sessionid != 0) {

HTTP_COOKIE = sessionid + 10;

}
next_semicolon = strtok_r(0, ";", &saveptr);
}
}

那么如果设置两个 seesionid , 第一个为 ../../../etc/frimware_version , 第二个为可以通过正则的有效字符。

最后我们就可以用授权的状态访问 upload.cgi 了。

CVE-2022-20707 Command Injection

作者在 upload.cgi 里找到了一个命令注入。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (json_obj != 0) {

json_str = json_object_to_json_string(json_obj);

sprintf(&buff, "curl %s --cookie 'sessionid=%s' -X POST -H 'Content-Type: application/json' -d '%s'", v3, sessionid, json_str);

debug("curl_cmd=%s", &buff);

__stream = popen(&buff, "r");

if (__stream != 0) {

fread_1(&buff[2048], 2048, 1, __stream);

fclose_1(__stream);

}

这里的的 json_str 没有校验, 会造成命令注入。

我们之前分析了 CVE-2022-20699-cisco-RV34X 的时候,注意到一个补丁, 修补了 Nginx 的配置不当的漏洞。然后今天和 @leommxj 一起追溯了一下 cisco 的修补历史。

Firmware version 1.0.03.19

nginx 对调用 upload.cgi 没有任何的校验, 因此可以访问 upload.cgi , 还出两个漏洞 #CVE-2020-3451 #CVE-2020-3453

相关的漏洞信息为:

ZDI-20-1100 | Zero Day Initiative
ZDI-20-1101 | Zero Day Initiative
Cisco Small Business RV340 Series Routers Command Injection and Remote Code Execution Vulnerabilities

Firmware version 1.0.03.21

之后有个老哥发现 cisco 虽然加行了授权校验,但是加得不行。

这加之前和加之后的 diff:

这个修复有一个致命的缺陷。逻辑是这样的,任何非空的授权标头都会将 $deny 设置为“0”。因此,从字面上发送任何看起来有效的授权标头作为请求/上传的一部分将绕过授权检查。

相关漏洞信息为:

#CVE-2021-1473 #CVE-2021-1472
Advisory: Cisco RV34X Series - Authentication Bypass and Remote Command Execution - IoT Inspector (iot-inspector.com)

Firmware version 1.0.03.22

然后这个版本之后去掉了上图 13 行的 nginx 配置。但是出现了此次 CVE-2022-20705 这个漏洞了。

other

一个点有意思的是, 这CVE-2022-20705 作者 和 CVE-2021-1473 作者用到的命令注入和我当时挖到两个编号 #CVE-2021-1609 和 #CVE-2021-1610 的漏洞点在一行代码里,这意思就是这行代码一共出了 4 个漏洞编号

以后挖 IoT 漏洞也要多注意一下 web 相关的配置了。


文章来源: https://bestwing.me/Pwning%20a%20Cisco%20RV340%20%20%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90%EF%BC%88CVE-2022-20705%20%E5%92%8C%20CVE-2022-20707.html
如有侵权请联系:admin#unsafe.sh