• Apache Spark UI 命令注入漏洞 CVE-2022-33891


     https://www.cnsuc.net/thread-522.htm

    0e6ad1de515cb59505260d0b1f6bfa94.png

    漏洞简介

    The Apache Spark UI offers the possibility to enable ACLs via the
    configuration option spark.acls.enable. With an authentication filter, this
    checks whether a user has access permissions to view or modify the
    application. If ACLs are enabled, a code path in HttpSecurityFilter can
    allow someone to perform impersonation by providing an arbitrary user name.
    A malicious user might then be able to reach a permission check function
    that will ultimately build a Unix shell command based on their input, and
    execute it. This will result in arbitrary shell command execution as the
    user Spark is currently running as. This affects Apache Spark versions
    3.0.3 and earlier, versions 3.1.1 to 3.1.2, and versions 3.2.0 to 3.2.1.

      ‍

    Apache Spark UI 提供了通过配置选项 spark.acls.enable。使用身份验证过滤器,这检查用户是否有访问权限来查看或修改应用。如果启用了 ACL,则 HttpSecurityFilter 中的代码路径可以允许某人通过提供任意用户名来执行模拟。然后恶意用户可能能够访问权限检查功能,最终将根据他们的输入构建一个 Unix shell 命令,并且执行它。这将导致任意 shell 命令执行

    影响版本:Apache Spark 版本 3.0.3 及更早版本,版本 3.11 至 3.1.2 ,以及版本 3.2.0 至 3.2.1

    漏洞复现

      下载 Apache Spark 3.2.1 https://archive.apache.org/dist/spark/

      https://archive.apache.org/dist/spark/spark-3.2.1/spark-3.2.1-bin-hadoop2.7.tgz

      根据描述是需要开启 acl 功能才可以触发漏洞

      开启 ACL 可以通过设定启动时的参数 ./spark-shell --conf spark.acls.enable=true 或者在 conf/spark-defaults.conf 中添加 spark.acls.enable true

    8dec850a72b8bccad9f080c656c718bd.png

    d4c9f590d2657734f9297dfb4b91995e.png

      ‍

      构造 poc

    http://localhost:4040/?doAs=\`[command injection here]`

    25ebabae9ebd257955063507cc4c5c61.png

    f0266ce89f7ec863bc6b88c729ef5829.png

    漏洞分析

      为了方便调试在启动脚本中添加上调试参数

    export SPARK_SUBMIT_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"

    f0389b3343d9ae0337fcfe29dc4f49c6.png


      输入错误的执行语句时的报错信息

    ebf81ca4a1d1b9338b9bca57efd04a3c.png

      漏洞的触发大概就在 org.apache.spark.security.ShellBasedGroupsMappingProvider.getUnixGroups

      漏洞的调用栈应该为

    1. org.apache.spark.ui.HttpSecurityFilter.doFilter(HttpSecurityFilter.scala:71)
    2. org.apache.spark.SecurityManager.checkUIViewPermissions(SecurityManager.scala:238)
    3. org.apache.spark.SecurityManager.isUserInACL(SecurityManager.scala:381)
    4. org.apache.spark.util.Utils$.getCurrentUserGroups(Utils.scala:2523)
    5. org.apache.spark.security.ShellBasedGroupsMappingProvider.getGroups(ShellBasedGroupsMappingProvider.scala:34)
    6. org.apache.spark.security.ShellBasedGroupsMappingProvider.getUnixGroups(ShellBasedGroupsMappingProvider.scala:43)

      加上断点进行调试分析

      org.apache.spark.ui.HttpSecurityFilter#doFilter

    e357eeeb7c8353363dc8f14deb08b953.png

      获取到参数 doAS 赋值为 effectiveUser 传到函数 checkUIViewPermissions

      org.apache.spark.SecurityManager#checkUIViewPermissions

    9d1089704d830f12a4216eec930675d0.png

      org.apache.spark.SecurityManager#isUserInACL

    e40d9f02aa827b260e77479f3fbb6720.png

      org.apache.spark.util.Utils$#getCurrentUserGroups

    68f2ce0ec5ea6c310f28aab6b32eef05.png

      org.apache.spark.security.ShellBasedGroupsMappingProvider#getGroups

    cb3ca5143bfa7676526fc3ee63725cd7.png

    org.apache.spark.security.ShellBasedGroupsMappingProvider#getUnixGroups

    551b7b3bcae56ce27aacd0baed056e68.png

      通过反引号将想要执行的命令包含起来,拼接到原本的命令执行语句中

      org.apache.spark.util.Utils$#executeAndGetOutput

    15cedbf01eb5d1a32f66c4fda683f0d3.png

      org.apache.spark.util.Utils$#executeCommand

    928bd3c03414f2af4318a01065fbb7a4.png

      ‍

    漏洞补丁

    cac2876ef8ba08fd95a66890af9fcb4a.png

      新版本的修复 删除了 ShellBasedGroupsMappingProvider 中的 bash 的调用,最后执行命令的语句应该变为/usr/bin/id -Gn + 传入参数

    原创稿件征集

    征集原创技术文章中,欢迎投递

    投稿邮箱:edu@antvsion.com

    文章类型:黑客极客技术、信息安全热点安全研究分析等安全相关

    通过审核并发布能收获200-800元不等的稿酬。

    更多详情,点我查看!

    f33795afdab25fc086e0d3baf00c716d.gif

    靶场实操,戳“阅读原文“

  • 相关阅读:
    CentOS Python环境搭建
    C++项目-求水仙花数
    day02-创建项目,注解,环境,容器
    基于4G智能网关的野外光伏逆变器数据采集方案
    oled清屏函数记录
    美团、飞猪基础架构组实习经历分享
    怎样选择第三方检测机构获取功能测试报告?
    SpringBoot 24 任务机制
    《数据结构》——顺序表和链表
    多语言翻译软件 Mate Translate mac中文版特色功能
  • 原文地址:https://blog.csdn.net/qq_38154820/article/details/127399819