서버 정보 은닉: 버전 노출 방지와 에러 페이지 커스터마이징
서버 소프트웨어 버전 정보가 외부에 노출되면 공격자가 알려진 취약점을 찾아 공격하기 쉬워집니다. 버전 정보 제거와 에러 페이지 커스터마이징으로 서버 정보를 최소화합니다.
Nginx 서버 정보 은닉
server_tokens 비활성화
# /etc/nginx/nginx.conf — http 블록
http {
# 응답 헤더의 Server: nginx/1.24.0 → Server: nginx
server_tokens off;
}
# 적용 전: Server: nginx/1.24.0
curl -I https://example.com | grep Server
# Server: nginx/1.24.0
# 적용 후: Server: nginx
curl -I https://example.com | grep Server
# Server: nginx
# 완전 제거 (nginx-extras 또는 OpenResty 필요)
# more_clear_headers Server;
Server 헤더 완전 제거 또는 변경
# nginx-extras 패키지 설치 시 headers-more 모듈 사용 가능
# sudo apt install nginx-extras
http {
server_tokens off;
# Server 헤더 내용 변경
more_set_headers 'Server: WebServer';
# 또는 완전 제거
more_clear_headers 'Server';
more_clear_headers 'X-Powered-By';
}
Apache 서버 정보 은닉
# /etc/apache2/conf-available/security.conf 또는 apache2.conf
# 응답 헤더에서 Apache 버전 제거
# Full: Apache/2.4.41 (Ubuntu)
# Prod: Apache (버전 없음)
# Min: Apache
ServerTokens Prod
# 서버 서명 (에러 페이지 하단 표시) 비활성화
ServerSignature Off
# X-Powered-By 헤더 제거
Header unset X-Powered-By
# ETag 헤더에서 inode 정보 제거 (정보 노출 방지)
FileETag MTime Size
sudo a2enconf security
sudo systemctl reload apache2
PHP/Tomcat 정보 은닉
PHP X-Powered-By 제거
# /etc/php/8.x/fpm/php.ini 또는 apache2/php.ini
expose_php = Off
# X-Powered-By: PHP/8.1.0 → 헤더 제거됨
Tomcat 서버 정보 제거
<!-- conf/server.xml -->
<!-- Connector에서 server 속성 제거 -->
<Connector port="8080"
protocol="HTTP/1.1"
server="" ← 빈 문자열로 Server 헤더 제거
/>
// Spring Boot에서 Server 헤더 커스터마이징
@Configuration
public class TomcatConfig {
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(connector -> {
connector.setProperty("server", ""); // Server 헤더 제거
});
return factory;
}
}
커스텀 에러 페이지 설정
기본 에러 페이지에는 서버 버전 정보가 포함됩니다. 커스텀 에러 페이지로 교체합니다.
Nginx 커스텀 에러 페이지
server {
# 에러 페이지 매핑
error_page 400 /errors/400.html;
error_page 401 /errors/401.html;
error_page 403 /errors/403.html;
error_page 404 /errors/404.html;
error_page 500 502 503 504 /errors/500.html;
# 에러 페이지 파일 위치
location ^~ /errors/ {
root /var/www;
internal; # 외부에서 직접 접근 불가
}
# JSON API 서버는 JSON 에러 응답
location /api/ {
error_page 404 @api_not_found;
error_page 500 @api_error;
proxy_pass http://backend;
}
location @api_not_found {
add_header Content-Type "application/json" always;
return 404 '{"error":"Not Found","code":404}';
}
location @api_error {
add_header Content-Type "application/json" always;
return 500 '{"error":"Internal Server Error","code":500}';
}
}
에러 페이지 예시 (/var/www/errors/404.html):
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>404 - 페이지를 찾을 수 없습니다</title>
<style>
body { font-family: sans-serif; text-align: center; padding: 50px; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>페이지를 찾을 수 없습니다</h1>
<p>요청하신 페이지가 존재하지 않습니다.</p>
<a href="/">홈으로 돌아가기</a>
<!-- 서버 버전 정보 없음 -->
</body>
</html>
Apache 커스텀 에러 페이지
# /etc/apache2/sites-available/example.com.conf
<VirtualHost *:443>
# 에러 페이지 설정
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html
# 에러 페이지 디렉토리
Alias /errors/ /var/www/errors/
<Directory /var/www/errors/>
Require all granted
Options -Indexes
</Directory>
</VirtualHost>
디렉토리 리스팅 비활성화
# Nginx — 기본적으로 비활성화됨 (autoindex off 기본값)
location /files/ {
autoindex off; # 명시적으로 비활성화
alias /var/www/files/;
}
# Apache — 기본 활성화되어 있어 명시적으로 비활성화 필요
<Directory /var/www/html>
Options -Indexes -FollowSymLinks # Indexes 제거
AllowOverride None
</Directory>
민감한 파일 접근 차단
# 숨김 파일(.env, .git, .htpasswd 등) 접근 차단
location ~ /\. {
deny all;
return 404;
}
# 설정 파일 직접 접근 차단
location ~* \.(env|conf|config|bak|backup|sql|log)$ {
deny all;
return 404;
}
# git 디렉토리 차단
location ~ /\.git {
deny all;
return 404;
}
보안 정보 노출 현황 점검
# 현재 노출되는 헤더 확인
curl -sI https://example.com | grep -iE "server|x-powered|via|x-aspnet|x-generator"
# Nikto로 정보 노출 취약점 스캔
sudo apt install nikto
nikto -h https://example.com -Tuning 0 # 정보 노출 항목만
# 에러 페이지 확인 (서버 정보 노출 여부)
curl -s https://example.com/nonexistent-page-xyz | grep -i "nginx\|apache\|tomcat\|version"