[시스템] 철학이 있는 리눅스 설치 -3 장 (OS 관련 기본 보안 정책 및 보안 패키지 설치 )

3. OS 관련 기본 보안 정책 및 보안 패키지 설치

* 불필요한 데몬 제거

/sbin/chkconfig –del anacron

/sbin/chkconfig –del atd

/sbin/chkconfig –del autofs

/sbin/chkconfig –del echo

/sbin/chkconfig –del finger

/sbin/chkconfig –del gpm

/sbin/chkconfig –del nfs

/sbin/chkconfig –del nfslock

/sbin/chkconfig –del portmap

/sbin/chkconfig –del rlogin

/sbin/chkconfig –del rsh

/sbin/chkconfig –del rsync

/sbin/chkconfig –del lpd

/sbin/chkconfig –del xfs

* 기본 데몬

/sbin/chkconfig –add crond

/sbin/chkconfig –add network

/sbin/chkconfig –add sshd

/sbin/chkconfig –add syslog

* 서비스 데몬

/sbin/chkconfig –add named

/sbin/chkconfig –add proftpd

/sbin/chkconfig –add sendmail

/sbin/chkconfig –add nfs

/sbin/chkconfig –add portmap

/sbin/chkconfig –add rlogin

/sbin/chkconfig –add rsh

/sbin/chkconfig –add rsync

* 불필요한 xinetd 데몬 제거

rm -f chargen

rm -f chargen-udp

rm -f daytime

rm -f daytime-udp

rm -f echo

rm -f echo-udp

rm -f finger

rm -f ntalk

rm -f rexec

rm -f rlogin

rm -f rsh

rm -f rsync

rm -f servers

rm -f services

rm -f sgi_fam

rm -f talk

rm -f telnet

rm -f time

rm -f time-udp

rm -f proftpd-inetd

* 불필요한 계정 삭제

userdel adm

userdel lp

        userdel sync

        userdel shutdown

        userdel halt

        userdel news

        userdel uucp

        userdel operator

        userdel games

        userdel gopher

* 불필요한 그룹 삭제

        groupdel adm

        groupdel lp

        groupdel news

        groupdel uucp

        groupdel games

        groupdel dip

* suid sgid 퍼미션의 명령어 검색 후 퍼미션 변경

# find / -type f \\( -perm -4000 -o -perm -2000 \\)

chmod 700 /usr/bin/chage

chmod 700 /usr/bin/gpasswd

chmod 700 /usr/bin/wall

chmod 700 /usr/bin/chfn

chmod 700 /usr/bin/chsh

chmod 700 /usr/bin/newgrp

chmod 700 /usr/bin/write

chmod 700 /usr/bin/passwd

chmod 700 /usr/bin/at

chmod 700 /usr/bin/lockfile

chmod 700 /usr/bin/rcp

chmod 700 /usr/bin/rlogin

chmod 700 /usr/bin/rsh

chmod 700 /usr/bin/slocate

chmod 700 /usr/bin/crontab

chmod 700 /usr/libexec/openssh/ssh-keysign

chmod 700 /usr/sbin/ping6

chmod 700 /usr/sbin/traceroute6

chmod 700 /usr/sbin/usernetctl

chmod 700 /usr/sbin/userhelper

chmod 700 /usr/sbin/lockdev

chmod 700 /usr/sbin/userisdnctl

chmod 700 /usr/sbin/sendmail.sendmail

chmod 700 /usr/sbin/traceroute

chmod 700 /usr/sbin/utempter

chmod 700 /bin/ping

chmod 700 /bin/mount

chmod 700 /bin/umount

chmod 700 /bin/su

chmod 700 /sbin/pam_timestamp_check

chmod 700 /sbin/pwdb_chkpwd

chmod 700 /sbin/unix_chkpwd

chmod 700 /sbin/netreport

chmod 4750 /usr/bin/rcp

chmod 4750 /usr/bin/rsh

chmod 4750 /usr/bin/rlogin

chmod 4111 /usr/bin/sudo

chmod 2750 /usr/sbin/sendmail.sendmail

chmod 4750 /bin/su

* 중요 시스템 설정 파일 보호 정책

chattr +i /etc/fstab

* 관리자 그룹에 포함된 계정에게 시스템 관리 명령어 사용 허용 정책

chmod 750 /bin/ps

chmod 750 /bin/netstat

chmod 750 /bin/dmesg

chmod 750 /bin/df

chmod 750 /usr/bin/w

chmod 750 /usr/bin/who

chmod 750 /usr/bin/last

chmod 750 /usr/bin/top

chmod 750 /usr/sbin/lsof

chgrp wheel /bin/ps

chgrp wheel /bin/netstat

chgrp wheel /bin/dmesg

chgrp wheel /bin/df

chgrp wheel /usr/bin/w

chgrp wheel /usr/bin/who

chgrp wheel /usr/bin/last

chgrp wheel /usr/bin/top

chgrp wheel /usr/sbin/lsof

chgrp wheel /usr/bin/rcp

chgrp wheel /usr/bin/rsh

chgrp wheel /usr/bin/rlogin

# vi /etc/group

==================================================================

.

.

wheel:x:10:root,clunix,alang

.

==================================================================

* 시스템 최 상위 디렉토리 퍼미션  정책

        chmod 711 /

        chmod 711 /home

        chmod 711 /var

        chmod 711 /var/log

        chmod 711 /etc

        chmod 700 /root

* 일반 shell 사용자 작업 내용 감시 하기

/etc/profile  파일의 제일 밑 부분에 아래 내용 추가

===================================================================

if [ $LOGNAME != “admin” ]

then

HISTFILE=/var/log/user_history

TMOUT=200

echo -n ”

===================================================================

userhistory 로그인 ID: $LOGNAME 접속시간 : `/bin/date`

===================================================================

” >> /var/log/user_history

fi

===================================================================

/root/.bashrc 파일 밑 부분에 다음 라인 추가

===================================================================

HISTFILE=/root/.bash_history

TMOUT=-1

===================================================================

마지막으로 /var/log/user_history 파일의 퍼미션을 662 으로 해줍니다.

* TCP Wrapper 로 TCP 서비스 접근 권한 정책

# vi /etc/hosts.deny

===================================================================

sshd : ALL : twist ( /root/bin/hostchk Y Y %a %c %d %h %n %p %s %u ) &

in.proftpd : ALL : twist ( /root/bin/hostchk Y Y %a %c %d %h %n %p %s %u ) &

===================================================================

# vi /etc/hosts.allow

====================================================================

sshd : localhost 127.0.0.1 211.241.202. 192.168.1.

in.proftpd : localhost 127.0.0.1 211.241.202. 192.168.1.

=====================================================================

# vi /root/bin/hostchk

=====================================================================

#!/bin/sh

################################  변수정의부문

# 메일 수신자

mailto=alang@clunix.com

# 화면출력 여부, 메일전송 여부

dsp=$1; msg=$2

# 접속자 정보 등

a=$3; c=$4; d=$5; h=$6; n=$7; p=$8; s=$9; u=$10

# 현재 시간

time=`date`

# 접속시도자 소속 서버의 finger 정보

finger=`/usr/bin/finger -l @$h 2> /dev/null`

################################  화면 출력부문

if [ $dsp = Y ]

    then

/bin/echo -n ”

                      ===================================

                           접속이 허용되지 않습니다.

                      ===================================

               Access Time             : $time

               Client host address     : $a

               Client information      : $c

               Client host name(or IP) : $h

               Client host name        : $n

               Client user name        : $u



fi

################################  메일 송신부문

if [ $msg = Y ]

    then

/bin/echo -n ”

                        ===============================

                              접속 거부자 상세정보

                        ===============================

         Access Time                    : $time

         Access client host address     : $a

         Access client information      : $c

         The daemon process name        : $d

         Access client host name(or IP) : $h

         Access client host name        : $n

         The daemon process id          : $p

         Server information             : $s

         Access client user name        : $u

                   ————————————–

                      Access client finger information

                   ————————————–

                            $finger

              ————————————————

” | \\

      /bin/mail -s “tcp_wrapper report [$d]” $mailto

fi

======================================================================

* Syn Flooding DOS 공격 방지 정책

# vi /root/bin/synfl

======================================================================

sysctl -w net.ipv4.tcp_max_syn_backlog=1024

sysctl -w net.ipv4.tcp_syncookies=1

sysctl -w net.ipv4.icmp_destunreach_rate=1

sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1

sysctl -w net.ipv4.icmp_echoreply_rate=1

sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1

sysctl -w net.ipv4.icmp_paramprob_rate=1

sysctl -w net.ipv4.icmp_timeexceed_rate=1

sysctl -w net.ipv4.igmp_max_memberships=1

sysctl -w net.ipv4.ip_default_ttl=64

sysctl -w net.ipv4.ip_forward=0

sysctl -w net.ipv4.ipfrag_time=15

sysctl -w net.ipv4.tcp_syn_retries=3

sysctl -w net.ipv4.tcp_retries1=3

sysctl -w net.ipv4.tcp_retries2=7

sysctl -w net.ipv4.conf.eth0.rp_filter=2

sysctl -w net.ipv4.conf.lo.rp_filter=2

susctl -w net.ipv4.conf.default.rp_filter=2

sysctl -w net.ipv4.conf.default.rp_filter=2

sysctl -w net.ipv4.conf.all.rp_filter=2

sysctl -w net.ipv4.conf.eth0.accept_redirects=0

sysctl -w net.ipv4.conf.lo.accept_redirects=0

sysctl -w net.ipv4.conf.default.accept_redirects=0

sysctl -w net.ipv4.conf.all.accept_redirects=0

sysctl -w net.ipv4.conf.eth0.accept_source_route=0

sysctl -w net.ipv4.conf.lo.accept_source_route=0

sysctl -w net.ipv4.conf.default.accept_source_route=0

sysctl -w net.ipv4.conf.all.accept_source_route=0

sysctl -w net.ipv4.conf.eth0.bootp_relay=0

sysctl -w net.ipv4.conf.lo.bootp_relay=0

sysctl -w net.ipv4.conf.default.bootp_relay=0

sysctl -w net.ipv4.conf.all.bootp_relay=0

sysctl -w net.ipv4.conf.eth0.log_martians=1

sysctl -w net.ipv4.conf.lo.log_martians=1

sysctl -w net.ipv4.conf.default.log_martians=1

sysctl -w net.ipv4.conf.all.log_martians=1

sysctl -w net.ipv4.conf.eth0.secure_redirects=0

sysctl -w net.ipv4.conf.lo.secure_redirects=0

sysctl -w net.ipv4.conf.default.secure_redirects=0

sysctl -w net.ipv4.conf.all.secure_redirects=0

sysctl -w net.ipv4.tcp_keepalive_time=30

sysctl -w net.ipv4.tcp_fin_timeout=30

sysctl -w net.ipv4.tcp_tw_buckets=1440000

sysctl -w net.ipv4.tcp_tw_buckets=1440000

sysctl -w net.ipv4.tcp_keepalive_probes=2

sysctl -w net.ipv4.tcp_max_ka_probes=100

======================================================================

* 시스템 시작 시 자동 실행 코드 추가

# vi /etc/rc.d/rc.local

======================================================================

rdate -s time.bora.net

/root/bin/synfl

======================================================================

* 최종적으로 Open port scan 확인

기본적인 OS 설정 및 보안 설정이 완료되면 최종적으로 현재 서비스가 이루어

지는 TCP/IP Port 에 대해 시스템 초기 상태에서 알아 두어야 한다.

이후 이때 파악 되지 않는 서비스 포트가 열려 있을 경우 보안에 의심을 해보

아야 할것이다.

Port Scan 도구로는 가장 많이 사용하는것이 nmap,nc,netstat,lsof 등  이다.

사용법은 다음과 같다.

nmap,nc,netstat 등을 이용해서 시스템의 열린 포트를 점검한다.

# nmap localhost -p 1-65535

# nc -w 3 -v -z localhost 1-65535

# netstat -ant | grep LISTEN

21/tcp     open        ftp

22/tcp     open        ssh

23/tcp     open        telnet

25/tcp     open        smtp

53/tcp     open        domain

80/tcp     open        http

3306/tcp   open        mysql

– 보안 패키지 설치 ( fcheck )

** 파일 무결성 체크 프로그램 (Fcheck 설치..)

지금까지의 시스템 설치후 기본 보안에 신경을 써야 할부분에 대해서 알아보았고

마지막으로 현재 기본 보안 처리된 시스템의 무결성에 대해 앞으로 감시해서 유지

해야 할것이다. 무결성 체크 프로그램으로는 대표적인게 Tripwire 가 있다.

하지만 여기서 소개하는 Fcheck 는 가볍고 간단하면서 Tripwire 의 역활을 충분히

할수 있다.

먼저 프로그램을 다운 받도록 하자.

http://www.geocities.com/fcheck2000/

가면 최신 프로그램이 있을것이다. 다운을 받고 /usr/local 및에 둔다.

압축을 풀고..fcheck,fcheck.cfg 파일의 설정값을 몇개 수정하자.

# tar xzvf FCheck_2.07.59.tar.gz

# cd fcheck

# vi fcheck

——————————————————————-

.

.

###############################################################

##############

#                                                                           #

#                 User modifiable variable definitions:                     #

#                                                                           #

###############################################################

##############

# This should be passed through the command line, but hard coding still works

$config=”/usr/local/fcheck/fcheck.cfg”;

—————————————– 이부분을 시스템 환경에 맞게 수정

——————————————————————-

# vi fcheck.cfg

——————————————————————-

Directory   = /etc/

Directory   = /bin/

Directory   = /usr/bin/

Directory   = /sbin/

Directory   = /usr/sbin/

Directory   = /usr/local/bin/

Directory   = /usr/local/sbin/

Directory   = /lib/

Directory   = /usr/lib/

Directory   = /usr/local/lib/

#

# Directory 설정은 fcheck 가 체크할 파일들이 들어 있는 디렉토리로 시스템에

# 중요한 명령어나 설정파일등이 있는 곳을 정해 주면 된다.

#

Exclusion      = /etc/passwd

Exclusion       = /etc/shadow

#

# Exclusion 설정은 Directory 설정에서 정한 디렉토리중 자주 변경이 되는 파일

# 이 있어서 체크때마다 걸리므로 체크 생략을 요하는 파일을 정해 주면 된다.

# 호스팅 업체나 기타 자주 사용자를 추가하는 서버라면 위와 같이 해주면 된다.

#

DataBase        = /usr/local/fcheck/data/data.dbf

#

# DataBase 설정은 리눅스 파일 정보를 DB 파일로 저장해서 다음 체크시 비교

# 분석할때 사용되어진다.

#

TimeZone        = GMT-9

#

# 한국 시간을 적용한다. GMT-9

#

#File   = /usr/local/admtools/logs/sol.dbf

File 설정은 필요 없으니 주석 처리 해준다.

기타 여러 설정값이 있으나 크게 작동하는데 영향을 주지 않는다.기본값을 적용

한다.

이와 같이 적용후 /usr/local/fcheck/data 디렉토리를 만들어 준다.

# mkdir /usr/local/fcheck/data

# /usr/local/fcheck/fcheck -ac

이와 같이 fcheck -ac 로 파일 무결성 체크를 시작한다. 그럼 data 디렉토리 안

에 data.dbf 파일이 생성되어 진다.

이제 Directory 설정에 해당하는 디렉토리 안에다가 파일을 하나 생성하고 재대

로 점검을 하는지 테스트를 하여 보자..

# touch /etc/test

# /usr/local/fcheck/fcheck -a

그럼 아마 아래와 같은 결과를 출력할것이다.

PROGRESS: validating integrity of /etc/

STATUS:

        ADDITION: [zzang911.net] /etc/test

        Inode   Permissons      Size    Created On

        19508   -rw-r–r–      0       Sep 19 20:13 2001

자 이제 이 명령어를 이용하여 주기적으로 시스템 파일 무결성을 체크하고 관리

자에게 통보하는 프로그램을 만들어 보도록 하자.

# vi fcheck.sh

————————————————————————-



#!/bin/sh

CHECK=`/usr/local/fcheck/fcheck -a | grep Inode`

HOSTNAME=`hostname`

if [ -n “$CHECK” ]

    then

    /usr/local/fcheck/fcheck -a > fcheck_result

    mail -s “$HOSTNAME File 무결성 체크 결과” admin@clunix.com < fcheck_result

    rm -f fcheck_result

fi

————————————————————————-

간단한 이정도 스크립터로 보다 효율적인 관리가 가능해 질것이다.

이제 cron 에 등록시켜 놓고..매일 파일 무결성 체크를 간단히 메일로 받아서 관리

할수 있게 된다. 만일 변화된 파일이 정당한 변화라면..

# /usr/local/fcheck/fcheck -ac

로 DBfile 를 업데이트 시켜 줘야 한다. 아님..계속 메일이 날아 오게 된다.

이로써 시스템 설치후 점검해야 할 보안 설정에 대해서 마치겠다. 시스템 보안은

초기의 보안 설정이 아주 큰 부분을 차지 하고 있다. 하지만..지속적은 감시와

관리역시 초기 보안 상태를 유지하는 가장 중요한 작업이라고도 할수 있다.

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

2 Responses

  1. 2022년 6월 22일

    2articulate

  2. 2023년 1월 27일

    1enervated

페이스북/트위트/구글 계정으로 댓글 가능합니다.