Why keep your Zoo doors closed
An unauthenticated ZooKeeper instance used for ClickHouse replication allowed an attacker to create a fake replica and inject a malicious log entry, causing other replicas to fetch data from the attacker's server. The attacker could then exploit a path traversal in the replication protocol to write arbitrary files, potentially leading to remote code execution.
medium.com
Published on medium.com
Here is a story of one specific vulnerability in ClickHouse (CVE-2019–15024) replication protocol but it also illustrates how the increase of attack surface can be exploited.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the replication protocol trusted data from any replica without authentication, and the file name from the replica was concatenated into a file path without sanitisation, enabling path traversal.
Impact
An attacker could write arbitrary files with clickhouse user rights, potentially leading to remote code execution via external dictionaries or ODBC, if certain conditions (like writable config directory or home directory) are met.
What the attacker needed
ZooKeeper without authentication; attacker can read/write ZooKeeper; replication port accessible
The fix
The vulnerabilities were fixed in ClickHouse version 19.14.3, and users should also configure authentication and authorization for ZooKeeper.
How it was found
- Attacker gains read/write access to the ZooKeeper instance used by ClickHouse.
- Attacker copies an existing replica node in ZooKeeper and changes the host to point to their own server.
- Attacker creates a new log entry in ZooKeeper with a block_id and source replica set to the attacker's replica.
- Other replicas read the log entry and request the data block from the attacker's server.
- Attacker's server responds with a crafted file name containing path traversal sequences and malicious content.
- The replica writes the content to an arbitrary file path due to unsafe concatenation.
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 write-up has not been written yet. The Original tab links to the source.
ClickHouse is a database that uses ZooKeeper to coordinate replication between servers. If ZooKeeper is left without authentication, an attacker can pretend to be a new replica and trick other servers into downloading malicious data. This data can contain a file path that lets the attacker write files anywhere on the server, which can be used to run their own code.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.