서버보안SW와 관련된 보안 업무를 수행하다 보면 수 많은 공공기관과 기업의 서버를 접하게 됩니다. 전산실도 따로 없이 서버 두 세 대를 운용하고 있는 직원 수십명의 작은 제조업체 부터 전국민의 주민등록 정보를 담아두고 있는 안행부의 주민등록 서버와 같은 공공기관의 서버는 물론 1금융권 은행의 가장 중요한 서버인 계정계(금융계좌의 원장 역할) 서버까지 온갖 서버를 모두 만져볼 수 있습니다. (물론 제맘대로 만지지는 못합니다. 살떨리거든요.. 그리고 요즘은 외부인에게 함부로 프롬프트를 주지 않습니다. 게다가 실시간 감시도 합니다.)
하지만 공통적인 것은 모든 서버는 “모두 똑 같은 서버다”라는 겁니다. 크나 작으나 동일한 운영체제에 어딜가나 비슷한 데이터베이스, 미들웨어, 백업, 배치작업관리와 같은 시스템SW…그리고 비슷 비슷한 이름의 계정들을 갖고 있죠. 간혹 “우리 서버가 어떤 서번데..”하면서 마치 특별한 서버로 생각하는 관리자도 볼 수 있습니다만…실상은 그냥 다 똑같은 서버 입니다. 환경이 조금 다를 뿐이죠.
그리고 오늘의 글을 쓰는 주된 이유 중 하나인 서버 관리 업무 상 발생하는 정체를 알 수 없는 유지보수를 위해 업로드 된 것으로 보이는 정체 불명의 파일들을 대부분의 서버들은 갖고 있다는 것 또한 공통점입니다.
이 정체불명의 파일들은 서버 운영자나 개발자, 관리자 또는 외부 엔지니어들에 의해 업로드 된 파일들이 대부분입니다. 서버의 유지보수나 신규 서비스를 위해 개발된 어플리케이션 관련 작업을 위해 임시로 업로드 된 파일들이죠. 그리고 이러한 파일들은 대부분 “위험” 요소로 봐야 합니다. 이러한 파일들은 수퍼유저 권한 또는 서비스의 관리자 계정의 권한으로 실행시킬 경우 공격도구나 정보유출을 유발할 수 있는 스크립트나 명령어를 포함하고 있기 때문입니다.
이렇게 작업을 위해 업로드 된 뒤 방치되고 있는 파일들을 서비스 운용시에는 사용하지 못하도록 통제할 필요가 있습니다.
Autofs 를 통한 안전한 유지보수 및 작업 환경 구축
Autofs는 평소에는 마운트되어 있지 않은 디바이스 또는 NFS 서버의 특정 경로를 접근하고자 할 때 자동으로 마운트 시켜주는 auto mount 서비스 입니다.
이 Autofs를 NIS와 NFS를 엮어 구성하면 해당 계정으로 로그인할 때 NFS서버에 존재하는 동일한 계정의 홈디렉토리를 로컬에 자동으로 mount 하고 로그아웃 할 때 자동으로 umount 할 수 있습니다. 이 구성에 대한 설정 방법은 인터넷에 많이 공개되어 있습니다. 최근 RedHat 리눅스 6.6 서버 3대에서 이 환경을 구축해볼 일이 생겨 구성을 해보았습니다.
구성된 NIS + NFS + Autofs 환경은 다음과 같습니다.
NIS는 Network Information Service 를 말합니다. 어디서는 DNS와 비교하기도 하는데 DNS는 IP와 Domain 주소를 상호 변환할 수 있는 서비스인데 반해 NIS는 작은 네트워크(NIS는 DNS 이름풀이를 사용하지 않고 /etc/hosts 파일만을 참조한다고 함)에서 서버의 계정을 NIS 서버에서만 생성하고 NIS 클라이언트에 접속 시 NIS 클라이언트에 없는 계정일 경우 NIS 서버의 인증을 받고 접속할 수 있도록 해주는 통합 계정 관리 서비스라고 할 수 있습니다. (다만 서버와 클라이언트 모두 Unix/Linux 서버입니다.) 그래서 앞의 그림에서 보듯 NIS 클라이언트에는 lee와 kim 이라는 계정이 없습니다만 이 두계정을 통해 NIS서버의 인증을 받고 NIS 클라이언트에 접속할 수 있습니다.
NFS는 Network File System의 약자입니다. 즉 NFS 클라이언트에서 nfsmount 라는 명령으로 미리 정의된 NFS 서버의 특정 디렉토리를 NFS 클라이언트의 특정 디렉토리에 마운트하여 로컬 파일시스템처럼 사용할 수 있게 해줍니다.
Autofs는 이 NIS와 NFS를 엮어서 특정 계정으로 NIS서버의 인증을 받고 자동으로 NFS 서버에 있는 동일한 계정의 홈디렉토리를 로컬에 nfsmount 시켜 주도록 설정할 수 있습니다.
이렇게 구성하게 되면 작업자 계정에서 접속하여 작업할 때에는 nfs 서버에 있는 작업자 계정의 홈디렉토리를 마운트하여 사용하고 로그아웃 하면 해당 작업 디렉토리가 자동으로 umount 되어 서비스를 수행하함으로써 서버는 항상 깨끗한 파일시스템을 유지할 수 있게 됩니다. 게다가 작업 디렉토리에 위험한 명령어와 파일이 존재하여도 로그아웃 하는 순간 서버에서 사라지게 되는 효과를 얻을 수 있기 때문에 보안 관점에서도 유리하게 됩니다.
NIS + NFS + autofs 설정 방법
*** 기본 구조 ***
192.168.100.11 node1.test.kr node1 <- nfs, nis server
192.168.100.12 node2.test.kr node2 <- nfs, nis client
RedHat Enterprise Linux 6 Update 6 (2.6.32-504.3.3 x64)
1. nfs 설정
1.1 nfs server 설정
1.1.1 host 파일 수정
[root@node1 /]# vi /etc/hosts
192.168.100.11 node1.test.kr node1
192.168.100.12 node2.test.kr node2
1.1.2. export 파일 수정
[root@node1 /]# vi /etc/exports
/home node*(rw,no_root_squash)
1.1.3. nfs 활성화
[root@node1 /]# rpm -qa | grep nfs
nfs-utils-lib-1.1.5-9.el6.x86_64
nfs-utils-1.2.3-54.el6.x86_64
nfs4-acl-tools-0.3.3-6.el6.x86_64
*** 설치되지 않았다면 설치
[root@node1 /]# yum -y install nfs-utils
[root@node1 /]# vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name
Domain = nis.test.kr <– 수정
[root@node1 /]# /etc/rc.d/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@node1 /]# /etc/rc.d/init.d/nfslock start
Starting NFS statd: [ OK ]
[root@node1 /]# /etc/rc.d/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@node1 /]# chkconfig rpcbind on
[root@node1 /]# chkconfig nfslock on
[root@node1 /]# chkconfig nfs on
1.2 nfs client 설정
1.2.1 host 파일 수정
[root@node2 /]# vi /etc/hosts
192.168.100.11 node1.test.kr node1
192.168.100.12 node2.test.kr node2
1.2.2 nfs 활성화
[root@node2 /]# rpm -qa | grep nfs
nfs-utils-lib-1.1.5-9.el6.x86_64
nfs-utils-1.2.3-54.el6.x86_64
nfs4-acl-tools-0.3.3-6.el6.x86_64
*** 설치되지 않았다면 설치
[root@node2 /]# yum -y install nfs-utils
[root@node2 /]# vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name
Domain = nis.test.kr
[root@node2 /]# /etc/rc.d/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@node2 /]# /etc/rc.d/init.d/nfslock start
Starting NFS statd: [ OK ]
[root@node2 /]# /etc/rc.d/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@node2 /]# chkconfig rpcbind on
[root@node2 /]# chkconfig nfslock on
[root@node2 /]# chkconfig netfs on
1.2.1 fstab 수정
~
[root@node2 etc]# vi fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
# 아래 줄 추가
node1.test.kr:/home /home nfs defaults 0 0
2. nis 설치
2.1 서버 구성
2.1.1 nis 구성 파일 설치
[root@node1 /]# yum -y install ypserv rpcbind
2.1.2 nis 환경 파일 설정
# set NIS domain
[root@node1 /]# ypdomainname nic.test.kr
[root@node1 /]# vi /etc/sysconfig/network
# add to the end
NISDOMAIN=nic.test.kr
[root@node1 /]# vi /var/yp/securenets
# create new (specify networks you allow to access)
255.0.0.0 127.0.0.0
255.255.255.0 10.0.0.0
2.1.2 nis 서비스 기동
[root@node1 /]# /etc/rc.d/init.d/rpcbind start
Starting portmap: [ OK ]
[root@node1 /]# /etc/rc.d/init.d/ypserv start
Starting YP server services: [ OK ]
[root@node1 /]# /etc/rc.d/init.d/ypxfrd start
Starting YP server services: [ OK ]
[root@node1 /]# /etc/rc.d/init.d/yppasswdd start
Starting YP passwd service: [ OK ]
[root@node1 /]# chkconfig rpcbind on
[root@node1 /]# chkconfig ypserv on
[root@node1 /]# chkconfig ypxfrd on
[root@node1 /]# chkconfig yppasswdd on
2.1.3 nis database update
[root@node1 /]# /usr/lib64/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS servers. dlp is in the list of NIS server hosts. Please continue to add the names for the other hosts, one per line. When you are done with the
list, type a .
next host to add: node1.test.kr
next host to add: <- Ctrl + D key
The current list of NIS servers looks like this:
node1.test.kr
Is this correct? [y/n: y] y <- ‘y’ key and Enter
We need a few minutes to build the databases…
Building /var/yp/server.world/ypservers…
Running /var/yp/Makefile…
gmake[1]: Entering directory `/var/yp/server.world’
Updating passwd.byname…
Updating passwd.byuid…
Updating shadow.byname…
Updating group.byname…
Updating group.bygid…
Updating hosts.byname…
Updating hosts.byaddr…
Updating rpc.byname…
Updating rpc.bynumber…
Updating services.byname…
Updating services.byservicename…
Updating netid.byname…
Updating protocols.bynumber…
Updating protocols.byname…
Updating mail.aliases…
gmake[1]: Leaving directory `/var/yp/nic.test.kr’
node1.test.kr has been set up as a NIS master server.
Now you can run ypinit -s node1.test.kr on all slave server.
2.2 nis client 설정
2.2.1 nis 설치
[root@node2 /]# yum -y install ypserv rpcbind
2.2.2 nis 환경 설정
[root@node2 /]# ypdomainname nis.test.kr
[root@node2 /]# vi /etc/sysconfig/network
NISDOMAIN=nis.test.kr <- 추가
[root@node2 /]# vi /etc/nsswitch.conf
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis
passwd: files nis <- 수정
shadow: files nis <- 수정
group: files nis <- 수정
#hosts: db files nisplus nis dns
hosts: files dns nis <- 수정
[root@node2 /]# authconfig \
–enablenis \
–nisdomain=nis.test.kr \
–nisserver=node1.test.kr \
–update
Starting rpcbind: [ OK ]
Starting NIS service: [ OK ]
Binding NIS service: .[ OK ]
2.2.3 설정 확인
[root@node2 /]# ypwhich
node1.test.kr
3. auto-mount 설정 (nfs client 서버에서 작업)
3.1 auto-mont 설치
[root@node2 /]# yum –y install autofs
3.2 auto-mount 환경 파일 수정
[root@node2 /]# vi /etc/auto.master
/home /etc/auto.home –timeout=60 추가
[root@node2 /]# vi auto.home 파일 생성
* node1.test.kr:/home/& 추가
3.3 auto-mount 시작
[root@node2 /]# /etc/rc.d/init.d/autofs start
[root@node2 /]# chkconfig autofs on
4. 계정 생성 및 mount 확인
4.1 nis server 에서 계정 생성
[root@node1 /]# useradd nuser1
[root@node1 /]#
[root@node1 /]# cd /var/yp
[root@node1 /]# make
gmake[1]: Entering directory `/var/yp/nis.test’
Updating passwd.byname…
Updating passwd.byuid…
Updating group.byname…
Updating group.bygid…
Updating netid.byname…
gmake[1]: Leaving directory `/var/yp/nis.test
4.2 nis client 서버에서 신규 생성된 계정으로 로그인
Last login: Tue Mar 31 10:15:52 2015 from 192.168.100.224
[nuser1@node2 ~]$
[nuser1@node2 ~]$ df –h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2.8G 1.9G 794M 71% /
/dev/sda1 99M 20M 75M 21% /boot
tmpfs 249M 0 249M 0% /dev/shm
node1:/home 2.8G 2.0G 687M 75% /home 확인