-
Nginx - Root Location MisconfigurationHacking/CTF 문제 풀이 2025. 7. 7. 23:53728x90반응형
Working through problems
Nginx 서버 설정에서 잘못된 root 경로 지정으로 인해 웹 서버의 설정 파일들이 외부에 노출되는 보안 취약점을 이용하는 문제입니다.
웹 서버에서는 아래처럼 Nginx 설정하고 있습니다.server { listen 80; server_name _; root /etc/nginx; location = / { return 302 /login/login.html; } location /login/ { alias /usr/share/nginx/html/login/; } location /static/ { alias /var/www/app/static/; } location / { try_files $uri $uri/ =404; default_type text/plain; } error_page 404 =200 /error.txt; location /error.txt { internal; } }- root가 /etc/nginx로 설정되어 있어 해당 디렉토리의 모든 파일이 웹 루트를 통해 접근 가능합니다.
- location / 블록에서는 try_files를 통해 파일이 없으면 404를 반환하지만 실제로 존재하는 설정 파일은 그대로 노출됩니다.
- 별도 필터링이 없어 사용자는 웹 브라우저로 /nginx.conf, /conf.d/default.conf 등 내부 설정 파일에 직접 접근할 수 있습니다.
http://challenge01.root-me.org:59093/nginx.conf
- /etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/default.conf; }- 다양한 설정 경로가 노출되는것을 확인할 수 있습니다.
노출 되는 경로 중 http://challenge01.root-me.org:59093/conf.d/default.conf
- /etc/nginx/conf.d/default.conf
server { listen 59093; server_name _; root /etc/nginx; location = / { return 302 /login/login.html; } location /login/ { alias /usr/share/nginx/html/login/; } location /static/ { alias /var/www/app/static/; } location / { try_files $uri $uri/ =404; default_type text/plain; } error_page 404 =200 /error.txt; location /error.txt { internal; } } #Congratulation the flag is [Flag]민감한 설정 파일 노출을 방지하기 위해 아래와 같이 특정 확장자에 대한 접근을 명시적으로 차단하는 것이 좋습니다.
location ~* \\.(conf|ini|env|bak|log|sql|yaml|yml)$ { deny all; }그리고 root 디렉토리는 반드시 /etc/nginx와 같이 설정 파일이 포함된 시스템 디렉토리가 아닌 정적 파일 전용 디렉토리로 분리하여 구성해야 합니다.
728x90반응형'Hacking > CTF 문제 풀이' 카테고리의 다른 글
File upload - Double extensions (0) 2025.07.09 File upload - MIME type (0) 2025.07.08 Nginx - Alias Misconfiguration (0) 2025.07.07 Install files (0) 2025.07.07 HTTP - Verb tampering (0) 2025.07.07