WEB 설정 및 취약점

:)·2024년 5월 24일
0

보안 

목록 보기
13/28

WEB - aphache 기반 Tomcat

설치

  • yum install httpd* -y

  • apache 웹 서버 설치 (selinux는 항상 확인할 것)

    1. 패키지 확인
      rpm -qa |grep httpd
    2. 패키지 설치
      yum install httpd* -y
    3. 패키지 설치 확인
      rpm -qa |grep httpd
    4. 포트 확인
      netstat -lntup |grep httpd
      service httpd restart
      netstat -lntup |grep httpd
    5. 설정 파일 및 데몬 확인
      rpm -ql httpd | grep httpd.conf
      rpm -ql httpd | grep service
      설정 파일:  /etc/httpd/conf/httpd.conf
      데몬 파일: /usr/lib/systemd/system/httpd.service
    6. 자동 실행
      chkconfig --level 35 httpd on
      systemctl enable httpd.service
      확인: systemctl list-unit-files |grep http
    7. 방화벽 설정
      firewall-cmd --permanent --add-port 80/tcp
      firewall-cmd --reload
      확인 firewall-cmd --list-all
  • 보안 포트 설정

    #Listen 12.34.56.78:80
    Listen 10.10.10.10:8080 <<<<<< IP 바인딩 설정
    Listen 80

  • 8080 포트를 쓰는 이유

    1. tomcat WAS(JSP)를 쓰기 위한 웹서버

    2. 별도의 테스트 서버나 관리자 페이지

      ServerAdmin root@localhost 관리자 메일 주소
      ServerName www.sevas10.com:80 서버 네임


웹 옵션설정

  • 기본 디렉토리 옵션 ( 기본적으로 /var/www/html을 제외하고 모두 거부 )
 <Directory />
 AllowOverride none
  # Require all denied
 </Directory>
  • DocumentRoot (웹페이지 출력위치 지정)
    
 #DocumentRoot "/var/www/html"
 DocumentRoot "/home/sevas/test"
 service httpd restat  ( 에러 )
 mkdir -p /home/sevas/test ( 경로 만들어주기 ) 
 403 forbidden error   권한 문제
 404 not found error   파일 없음   
 chmod 755 ~sevas
 cat > /home/sevas/test/index.html (/home/sevas)
  • 디폴트 디렉토리 옵션
<Directory/>
AllowOverride none
# Require all denied
</Directory>
  • /var/www/html의 디렉토리 옵션 -> 모든 접근 허용

    <Directory "/var/www/html">
    Options Indexes FollowSymLinks -> 인덱스 / 링크를 사용할 수 있게 됨(보안이 취약해짐)
    AllowOverride None
    Require all granted

  • 사용자 지정 디렉토리 옵션

    <Directory /home/sevas/test>
    AllowOverride AuthConfig
    Options Indexes FollowSymLinks

  • AAA (3A란?)

    authentication 인증

    authorization 인가 ( 권한부여 )
    accounting 계정관리

인증 필요한 페이지로 만들기(실습)

    - 사전준비
        1. DocumentRoot "/home/sevas"
        2. cat > /home/sevas/index.html
        /home/sevas
        3. cat > /home/sevas/test/index.html
        test
        4. mkdir -p /home/sevas/admin
        5. cat > /home/sevas/admin/index.html
        admin
- /etc/httpd/conf/httpd.conf
        <Directory /home/sevas/admin>
        #Options Indexes FollowSymLinks
        AllowOverride AuthConfig
        </Directory>
        
  • .htaccess 보안 페이지 파일 만들기
    - vi /home/sevas/admin/.htaccess
authname "sevas-auth"
authtype basic
authuserfile /etc/httpd/conf/mypasswd/sevas
require valid-user
`mkdir -p /etc/httpd/conf/mypasswd`
`htpasswd -m -c /etc/httpd/conf/mypasswd/sevas sevas`

결과 ( admin 으로 이동 시 로그인 필요)

  • 데몬 : 포트관리자 = 서비스
  • 웹에서 중요한 3가지
    1. 환경 설정 - 포트설정
    2. 서버 설정
    3. 도메인 별 웹 서비스 (virtual host)
  • 유저 DIR 설정 (http://10.10.10.10/~계정명)
    • 사전준비

      [ 사전준비 ][root@localhost conf.d]# useradd test1
      [root@localhost conf.d]# useradd test2
      [root@localhost conf.d]# chmod 755 ~test1
      [root@localhost conf.d]# chmod 755 ~test2
      [root@localhost conf.d]# mkdir -p ~test1/public_html
      [root@localhost conf.d]# mkdir -p ~test2/public_html
      [root@localhost conf.d]# mkdir -p ~sevas/public_html
      [root@localhost conf.d]# cat > ~test1/public_html/index.html
      test1
      ^C
      [root@localhost conf.d]# cat > ~test2/public_html/index.html
      test2
      ^C
      [root@localhost conf.d]# cat > ~sevas/public_html/index.html
      sevas
      ^C

    • vi /etc/httpd/conf.d/userdir.conf

      UserDir disabled → 두 설정을 적절히 섞어서 사용
      UserDir enabled sevas → ~sevas 만 가능

      #UserDir public_html
      UserDir public_html

    • alias 단축 페이지 설정

      alias /linux1 "/a/b/c/"
      alias /linux2 "/home/sevas/a/b/c/"

      mkdir -p /a/b/c
      mkdir -p ~sevas/a/b/c
      cat > /a/b/c/index.html
      linux1
      cat > ~sevas/a/b/c/index.html
      linux2

      vi /etc/httpd/conf.d/userdir.conf

      alias /linux2 "/export/sdb/home/alias/a/b/c/"

  • 웹서버 호스팅 방법 4가지

    DocumentRoot
    UserDir
    Alias
    virtualhost

웹서버 대표적인 기본 취약점

  • OS 종류 노출
    - 공격: banner grabbing ( telnet [ip] 80 )
    - 보안: 서버설정으로 토큰 노출 제어

    a. vi /etc/httpd/conf/httpd.conf
    ServerTokens Prod
    prod : 웹서버 이름
    major: 웹서버 이름 major 버전
    minor: 웹서버 이름 minor 버전
    min : 웹서버 이름과 minimum 버전
    os : 웹서버 버전 운영체제 (기본값)
    Full : 전체

  • Directory Listening : 웹에 파일 목록 리스트
    - 보안 : Directory Listening기능 삭제

    vi /etc/httpd/conf/httpd.conf
    #Options Indexes FollowSymLinks <<<<<indexes 는 디렉토리 리스닝
    Options (기능을 빼줌)

  • not found 와 forbidden: 디렉토리가 존재하는지 여부를 확인

    404 not found ( 파일 없음 )
    403 forbidden ( 권한 오류 )
    500 internal service ( 설정 오류 )

    - 보안 : 해당 에러메세지를 구분할 수 없도록 설정
    
        vi /etc/httpd/conf/httpd.conf
        ErrorDocument 404 /index.html
        ErrorDocument 403 /index.html
profile
:) GITHUB: https://github.com/YJ2123412

0개의 댓글