Latest Posts

Fresh thoughts and recent updates from the blog

tistory view

728x90
반응형

취약점 설명

nginx는 가볍고 높은 성능을 목표로하는 웹서버이다. 웹서버, 리버스 프록시, 로드 밸런서, 메일 프록시, HTTP 캐시 등의 기능을 가진다.

nginx 설정 시 location 경로를 지정할 때 root 나 alias 를 설정할 수 있는데, alias 는 특정 URL이 서빙할 파일 경로를 변경하는 역할을 한다.

location /posts/ {
    alias /data/blogs/;
}

만약 클라이언트 사용자가 /posts/domdom.png 파일을 요청했다고 했을 때, /data/blogs/domdom.png 경로에 있는 파일을 클라이언트에게 응답할 것이다.

 

여기서 만약 location 이 디렉터리 구분자인 / 로 끝나지 않게 되면,

location /posts {
    alias /data/blogs/;
}

클라이언트 사용자가 /posts../app/config.ini 로 요청했을 때, /data/app/config.ini 경로에 있는 파일을 클라이언트에게 응답하게 된다.

 

이런 alias에 대한 잘못된 설정으로 인해 공격자에게 대상 디렉토리를 벗어나서 파일을 읽을 수 있게 하는 취약점이다.

참고로 alias 뿐만 아니라 proxy_pass 에도 동일하게 적용된다고 한다. 그리고 한 단계 상위 경로까지만 올라갈 수 있다.

 

해당 취약점은 nginx misconfiguration, nginx off-by-slash fail, nginx path traversal, nginx alias traversal 등 다양한 이름으로 불린다.

 

해결법

모든 nginx alias 디렉티브들을 아래와 같이 반드시 디렉토리 구분자인 / 로 끝나게 하면 된다.

location /posts/ {
    alias /data/blogs/;
}

 

취약점 원인 분석

만약 아래와 같은 location 설정이 있다고 가정하면,

location /api {
        proxy_pass http://domdomserver/api/v1/;
}

클라이언트 사용자가 서버에 /api/user 로 요청했을 때, nginx 서버에서는 먼저 URL에서 /api 와 일치하는 것이 있는지 확인하고 일치하는 부분을 제거한다. 그러면 /api/user에서 남은 것으로는 /user 만 남는다. 그런 다음에 이제 proxy_pass 에 정의되어 있는 값을 추가시켜 최종적으로 http://domdomserver/api/v1//user 가 되도록 한다. 주목해야할 점으로는 /(슬래시)가 2개인 점이다. proxy_pass 에서 location 디렉티브를 / 로 끝내지 않았기 때문에 생긴 문제이다.

 

그리고 일반적으로 대부분의 웹 서버에서는 /(슬래시)가 2개면 한 개로 변환해주는 로직을 가지고 있기 때문에 nginx 를 거치고 최종적으로 웹서버를 거치면 http://domdomserver/api/v1/user 의 URL형태가 된다.

 

그러면 당연히 위에서도 언급한 ../ (double-dot and slash)를 사용해서 /api../v2/user 형태로 보냈다고 가정하면, 최종적으로 URL은 http://domdomserver/api/v2/user 와 같은 형태가 될 수 있다.

 

nginx 서버에 이런 잘못된 설정이 존재하는지 확인하는 통상적인 방법으로는 아래의 서로 다른 요청들이 동일한 응답을 보내오는지 확인하면 된다.

/api/user -> http://domdomserver/v1//user -> http://domdomserver/v1/user
/apiuser -> http://domdomserver/v1/user

 

마무리

nginx 측에서는 해당 사항을 취약점이라고 판단하지 않았기 때문에 취약점으로 분류되지 않고 단순히 잘못된 설정으로 취급되는 것 같다. 2016년도부터 알려지기 시작한 취약점이라고 한다. 해당 취약점에 대해서 발표한 PPT가 있는데 참고하기 좋은 것 같다.

https://i.blackhat.com/us-18/Wed-August-8/us-18-Orange-Tsai-Breaking-Parser-Logic-Take-Your-Path-Normalization-Off-And-Pop-0days-Out-2.pdf

 

참고자료

https://portswigger.net/bappstore/a5fdd2cdffa6410eb530de5a4c294d3a

 

NGINX Alias Traversal

Detects NGINX alias traversal due to misconfiguration.

portswigger.net

https://blog.detectify.com/2020/11/10/common-nginx-misconfigurations/

 

Common Nginx misconfigurations that leave your web server open to attack - Detectify Blog

Detectify analyzed 50,000 unique Nginx configuration files on GitHub and reported some common misconfigurations.

blog.detectify.com

https://www.acunetix.com/vulnerabilities/web/path-traversal-via-misconfigured-nginx-alias/

 

Path traversal via misconfigured NGINX alias - Vulnerabilities - Acunetix

 

www.acunetix.com

 

728x90
반응형
Comments

Visitor Trends

Daily blog stats and creator awards

✿ DASHBOARD
Today

Yesterday

Total

Posts

0

2023 IT Creator
2024 Food Creator
2025 News Creator
2026 News Creator