본문 바로가기

리눅스

Apache 웹 서버에서 디렉터리 리스팅(Directory Listing) 비활성화

728x90
반응형

Apache 웹 서버에서 디렉터리 리스팅(Directory Listing) 비활성화

Apache 웹 서버에서 디렉터리 리스팅(Directory Listing)이 활성화되어 있으면 디렉터리 내 파일 목록이 외부에 노출될 수 있습니다.

 

보안상 불필요한 파일이나 백업 파일 등의 정보가 노출될 수 있으므로 운영 환경에서는 Indexes 옵션을 제거하여 디렉터리 리스팅을 비활성화하는 것을 권장합니다.

1. Apache 설정 확인

VirtualHost 또는 Directory 설정에서 Options 지시어를 확인합니다.

<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

여기서 Indexes 옵션을 제거합니다.

<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

2. VirtualHost 설정 적용

실제 운영 환경의 VirtualHost에 Indexes가 설정되어 있다면 제거합니다.

  • 기존
<Directory "/user/www/cdms_80/htdocs">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    ...
</Directory>
  • 변경
<Directory "/user/www/cdms_80/htdocs">
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews SymLinksIfOwnerMatch IncludesNoExec 
    Require all granted
</Directory>

주요 변경 사항

- Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+ Options MultiViews SymLinksIfOwnerMatch IncludesNoExec

Indexes를 제거하면 DirectoryIndex 파일이 없는 디렉터리에 접근하더라도 파일 목록이 표시되지 않습니다.

AllowOverride의 Indexes는 디렉터리 리스팅 자체를 활성화하는 설정이 아니라 .htaccess에서 관련 설정을 사용할 수 있도록 허용하는 옵션입니다.
728x90

3. 디렉터리 리스팅 차단 확인

DirectoryIndex 파일이 없는 디렉터리에 접근하여 확인합니다.

curl -I http://<서버주소>/<디렉터리>/

Indexes가 비활성화되어 있다면 일반적으로 다음과 같이 403 Forbidden 응답을 확인할 수 있습니다.

HTTP/1.1 403 Forbidden

또한 실제 Apache 설정 전체에서 Indexes가 활성화되어 있는지 확인하는 것도 좋습니다.

sudo grep -Rni "Options.*Indexes" /etc/httpd/

Apache 웹 서버 디렉터리 리스팅 차단

<VirtualHost *:80>
    serverAdmin logman@sangchul.kr
    ServerName cdms.sangchul.kr
    ServerAlias tcdms.sangchul.kr
    DocumentRoot "/user/www/cdms_80/htdocs"
    ErrorLog "/logs/httpd/cdms.sangchul.kr-error_log"
    CustomLog "/logs/httpd/cdms.sangchul.kr-access_log" common
    <Directory "/user/www/cdms_80/htdocs">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec => Indexes 제거
        <Limit GET POST OPTIONS>
            Order allow,deny
            Allow from all
        </Limit>
        <LimitExcept GET POST OPTIONS>
            Order deny,allow
            Deny from all
        </LimitExcept>
    </Directory>
</VirtualHost>

 

728x90
반응형