天天看点

Apache Airflow example_bash_operator DAG 远程代码执行漏洞

作者:棱镜七彩7cai
Apache Airflow example_bash_operator DAG 远程代码执行漏洞

项目介绍

Airflow 是一个使用 python 语言编写的 data pipeline 调度和监控工作流的平台。 Airflow 是通过 DAG(Directed acyclic graph 有向无环图)来管理任务流程的任务调度工具, 不需要知道业务数据的具体内容,设置任务的依赖关系即可实现任务调度。

项目地址

https://github.com/apache/airflow

漏洞概述

Apache Airflow的默认DAG example_bash_operator 参数使用不当,具备后台权限的攻击者可以通过run_id注入恶意命令从而造成rce。

影响版本

Apache Airflow < 2.4.0

漏洞复现

构造特殊run_id,反弹shell成功

Apache Airflow example_bash_operator DAG 远程代码执行漏洞
Apache Airflow example_bash_operator DAG 远程代码执行漏洞

漏洞分析

根据官方发布的修复补丁可知,修复前是直接获取了run_id 值并拼接到了bash_command中。

Apache Airflow example_bash_operator DAG 远程代码执行漏洞

run_id是什么呢?原来每个DAG 实例都有一个上下文的概念,以context参数的形式会透传给所有的任务,以及所有任务的回调函数。run_id也在context中,其含义是DAG运行实例id

Apache Airflow example_bash_operator DAG 远程代码执行漏洞

在触发dag执行的时候,可以指定run_id的值

Apache Airflow example_bash_operator DAG 远程代码执行漏洞

因此只要具备触发DAG执行的权限就可以注入恶意命令。

注入恶意命令后,如何执行呢?参考官方文档可知,BashOperator作用是在shell中执行命令,airflow使用 Jinja templates为dag传递变量并且不会对传入数据进行转义处理

Apache Airflow example_bash_operator DAG 远程代码执行漏洞
Apache Airflow example_bash_operator DAG 远程代码执行漏洞

因此,在2.4.0之前版本,当example_bash_operator存在时,具备执行权限的攻击者可以通过run_id注入恶意代码从而执行系统命令。

修复方式

官方已发布安全版本 2.4.0,建议升级至安全版本或以上。

参考连接

https://cloud.tencent.com/developer/article/1019700

https://github.com/apache/airflow/pull/25960

https://airflow.apache.org/docs/apache-airflow/stable/howto/operator/bash.html#bashoperator