天天看點

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