Linux Server - FTP 실습 (1 / 2) : chroot 옵션 설정 / hosts.allow, hosts.deny 파일 설정

● Linux Server - FTP 실습 : chroot 옵션


○ 조건
DNS Server (175) = FTP Server
Apache (172) = Client


○ 순서
   1. FTP 서버 구축
   2. chroot 설정을 바꿔본다
     2-1) chroot_local_user = YES / chroot_list_enable = YES
     2-2) chroot_local_user = NO / chroot_list_enable = YES
     2-3) chroot_local_user = YES / chroot_list_enable = NO
     2-4) chroot_local_user = NO / chroot_list_enable = NO
   3. 각 설정 별 클라이언트 접속을 통해 차이점을 알아보자


○ 결과 예상
   1) chroot_local_user = YES / chroot_list_enable = YES
     → chroot list에 있는 계정은 chroot 적용하지 않음

   2) chroot_local_user = NO / chroot_list_enable = YES
     → chroot list에 있는 계정은 chroot 적용

   3) chroot_local_user = YES / chroot_list_enable = NO
     → 모든 사용자가 chroot 적용

   4) chroot_local_user = NO / chroot_list_enable = NO
     → 모두 상관없이 chroot 적용되지 않음


FTP 설치 확인

[root@DNS-Server ~]# rpm -qa |grep vsftpd
vsftpd-2.0.5-13.SUL2



① (chroot 권한 수정 - local_user YES, list_enable YES)


/etc/vsftpd/vsftpd.conf 파일 수정
[root@DNS-Server ~]# vi /etc/vsftpd/vsftpd.conf
chroot_local_user=YES // 디폴트 값으로 주석처리 조차 안되어있으니 새로 추가
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list // 이 두 줄은 주석처리 제거

chroot 할 계정을 설정 ( /etc/vsftpd/chroot_list 파일 생성 )
[root@DNS-Server ~]# vi /etc/vsftpd/chroot_list
root
→ 한 단어만 추가해주자.

client의 접속
[root@Apache ~]# ftp 192.168.10.175
Connected to 192.168.10.175.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.175:root): root
530 Permission denied.
Login failed.
→ 퍼미션이 거부되었다고 한다.
→ FTP의 접근 제한 파일을 확인해보자 ( /etc/vsftpd/ftpusers  /etc/vsftpd/user_list )

[root@DNS-Server ~]# vi /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftp
root  → root가 list에 올라와 있다, 해당 계정은 자동으로 거부된다
→ #root 로 주석처리

[root@DNS-Server ~]# vi /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
→ 역시 #root로 주석처리

설정을 바꿨으니 ftp 서비스를 재시작
[root@DNS-Server ~]# service vsftpd restart
vsftpd를 종료 중:                                          [  OK  ]
vsftpd에 대한 vsftpd을 시작 중:                            [  OK  ]

다시 접속
[root@Apache ~]# ftp 192.168.10.175
Connected to 192.168.10.175.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.175:root): (여기에 ID 입력 : root)
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
→ ftp 서버에 성공적으로 접속 확인

디렉토리를 확인
ftp> pwd
257 "/root"

- /root 디렉토리를 최상위 디렉토리 / 로 인식하고 있지 않은 모습이다.
- 이번 조건은 chroot_local_user=YES, chroot_list_enable=YES 이었다.
- 이 경우 chroot_list_file에 지정된 chroot_list 목록에 있는 계정은 chroot를 적용하지
 않는다.


② (chroot 권한 수정 - local_user NO, list_enable YES)

/etc/vsftpd/vsftpd.conf 파일 수정
[root@DNS-Server ~]# vi /etc/vsftpd/vsftpd.conf
chroot_local_user=NO (디폴트가 NO이므로 아예 지워도 된다)
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

설정을 바꿨으니 ftp 서비스를 재시작
[root@DNS-Server ~]# service vsftpd restart
vsftpd를 종료 중:                                          [  OK  ]
vsftpd에 대한 vsftpd을 시작 중:                            [  OK  ]

client의 접속
[root@Apache ~]# ftp 192.168.10.175
Connected to 192.168.10.175.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.175:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

디렉토리를 확인
ftp> pwd
257 "/"
→ root 디렉토리가 최상위 / 디렉토리로 인식됨을 확인할 수 있다.
- 이번 조건은 chroot_local_user=NO, chroot_list_enable=YES 이었다.
- 이 경우 chroot_list_file에 지정된 chroot_list 목록에 있는 계정은 chroot를 적용한다.


③ (chroot 권한 수정 - local_user YES, list_enable NO)

/etc/vsftpd/vsftpd.conf 파일 수정
[root@DNS-Server ~]# vi /etc/vsftpd/vsftpd.conf
chroot_local_user=YES
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list

설정을 바꿨으니 ftp 서비스를 재시작
[root@DNS-Server ~]# service vsftpd restart
vsftpd를 종료 중:                                          [  OK  ]
vsftpd에 대한 vsftpd을 시작 중:                            [  OK  ]

client의 접속
[root@Apache ~]# ftp 192.168.10.175
Connected to 192.168.10.175.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.175:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

디렉토리의 확인
ftp> pwd
257 "/"
→ root 디렉토리가 최상위 / 디렉토리로 인식됨을 확인할 수 있다.
→ 이번 조건은 chroot_local_user=YES, chroot_list_enable=NO 이었다.
→ 이 경우 list와는 무관하게 전체 사용자에게 홈디렉토리를 각각의 root로 인식시킨다.


④ (chroot 권한 수정 - local_user NO, list_enable NO)

/etc/vsftpd/vsftpd.conf 파일 수정
[root@DNS-Server ~]# vi /etc/vsftpd/vsftpd.conf
chroot_local_user=NO
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list

설정을 바꿨으니 ftp 서비스를 재시작
[root@DNS-Server ~]# service vsftpd restart
vsftpd를 종료 중:                                          [  OK  ]
vsftpd에 대한 vsftpd을 시작 중:                            [  OK  ]

client의 접속
[root@Apache ~]# ftp 192.168.10.175
Connected to 192.168.10.175.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.175:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

디렉토리의 확인
ftp> pwd
257 "/root"
→ /root 디렉토리를 최상위 디렉토리 / 로 인식하고 있지 않은 모습이다.
→ 이번 조건은 chroot_local_user=NO, chroot_list_enable=NO 이었다.
→ 이 경우 list와도 관계 없고, chroot 옵션 자체가 NO이므로, chroot 하지 않는다.


● Linux Server - FTP 실습 : ip주소 대상 서비스 거부 / 허용
(hosts.deny / hosts.allow)

① standalone 방식을 사용할 때 ip주소를 통한 서비스 거부/허용

/etc/vsftpd/vsftpd.conf 파일 수정
  listen=YES
  tcp_wrappers=YES

/etc/hosts.deny
 - 데몬명 or ALL : IP주소 or ALL
 - 이 파일에 설정된 IP는 설정된 데몬에 대해 접근이 거부된다.

[root@DNS-Server ~]# cat /etc/hosts.deny
#
# hosts.deny    This file describes the names of the hosts which are
#               *not* allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!
vsftpd : ALL

→ 위와 같이 설정했다면, 모든 IP에 대해서 vsftpd 데몬 서비스는 거부된다는 것을 의미한다.


/etc/hosts.allow
 - 구조는 deny 파일과 같다.
 - 반면, 이 파일에 설정된 IP는 설정한 데몬에 대해 접근이 허용된다.

[root@DNS-Server ~]# cat /etc/hosts.allow
#
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
vsftpd : 192.168.10.175

→ 위와 같이 설정했다면, 192.168.10.175의 IP에 대해서 vsftpd 데몬 서비스는 허용된다는 것을 의미한다.

※ Allow 파일과 Deny 파일이 동시에 모든 사용자에 대해 권한을 제한/허용한다면 어떻게 되나?
→ Allow 파일이 Deny 파일보다 우선권을 갖게 된다고 한다. 그렇기 때문에 위와 같이 설정해도 175번 ip는 서비스가 허용되는 것!

댓글

이 블로그의 인기 게시물

Linux Server - FTP 실습 (2 / 2) : 사용자 제한 ( ftpuser / user_list )

전자서명 개념

3.27 (화) - Network (패킷 통신 - 4가지 지연)