보안 도구 · 6 min read · Jan 30, 2026
Chkrootkit-Portsentry-Howto
Chkrootkit-Portsentry-Howto
버전 1.0
저자: Falko Timme
이 문서는 chkrootkit과 portsentry를 설치하는 방법을 설명합니다. 모든 *nix 운영 체제에서 작동해야 합니다 (경로 등과 관련하여 약간의 변경이 있을 수 있습니다).
Chkrootkit “은 루트킷의 징후를 로컬에서 확인하는 도구입니다” (http://www.chkrootkit.org에서 발췌).
“Sentry 도구는 Unix 플랫폼에 대한 호스트 수준 보안 서비스를 제공합니다. PortSentry, Logcheck/LogSentry 및 HostSentry는 포트 스캔으로부터 보호하고, 로그 파일 감사 자동화 및 의심스러운 로그인 활동을 지속적으로 감지합니다” (http://sourceforge.net/projects/sentrytools/에서 발췌).
이 문서는 실용적인 가이드를 목적으로 하며, 이론적 배경은 다루지 않습니다. 이론적 배경은 웹의 많은 다른 문서에서 다루어집니다.
이 문서는 어떤 종류의 보증 없이 제공됩니다!
1 소스 가져오기
다음 소프트웨어가 필요합니다: chkrootkit, portsentry 및 logcheck. 우리는 /tmp 디렉토리에서 소프트웨어를 설치할 것입니다.
cd /tmp
wget –passive-ftp ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
wget http://heanet.dl.sourceforge.net/sourceforge/sentrytools/portsentry-1.2.tar.gz
wget http://heanet.dl.sourceforge.net/sourceforge/sentrytools/logcheck-1.1.1.tar.gz
2 Chkrootkit 설치
mv chkrootkit.tar.gz /usr/local/
cd /usr/local/
tar xvfz chkrootkit.tar.gz
ln -s chkrootkit-0.43/ chkrootkit (여기서 0.43을 올바른 버전 번호로 교체) cd chkrootkit/ make sense*
이제 chkrootkit 프로그램을 /usr/local/chkrootkit에서 찾을 수 있습니다. 다음과 같이 입력하여 실행합니다:
cd /usr/local/chkrootkit/ && ./chkrootkit
출력은 다음과 비슷하게 보일 것입니다:
| ROOTDIR is `/` Checking `amd`... not found Checking `basename`... not infected Checking `biff`... not infected Checking `chfn`... not infected Checking `chsh`... not infected Checking `cron`... not infected Checking `date`... not infected Checking `du`... not infected Checking `dirname`... not infected Checking `echo`... not infected Checking `egrep`... not infected Checking `env`... not infected Checking `find`... not infected Checking `fingerd`... not found Checking `gpm`... not found Checking `grep`... not infected Checking `hdparm`... not found Checking `su`... not infected Checking `ifconfig`... not infected Checking `inetd`... not infected Checking `inetdconf`... not infected Checking `identd`... not found Checking `init`... not infected Checking `killall`... not infected Checking `ldsopreload`... not infected Checking `login`... not infected Checking `ls`... not infected Checking `lsof`... not infected Checking `mail`... not infected Checking `mingetty`... not found Checking `netstat`... not infected Checking `named`... not infected Checking `passwd`... not infected Checking `pidof`... not infected Checking `pop2`... not found Checking `pop3`... not found Checking `ps`... not infected Checking `pstree`... not infected Checking `rpcinfo`... not infected Checking `rlogind`... not found Checking `rshd`... not found Checking `slogin`... not infected Checking `sendmail`... not infected Checking `sshd`... not infected Checking `syslogd`... not infected Checking `tar`... not infected Checking `tcpd`... not infected Checking `tcpdump`... not infected Checking `top`... not infected Checking `telnetd`... not found Checking `timed`... not found Checking `traceroute`... not found Checking `vdir`... not infected Checking `w`... not infected Checking `write`... not infected Checking `aliens`... no suspect files Searching for sniffer's logs, it may take a while... nothing found Searching for HiDrootkit's default dir... nothing found Searching for t0rn's default files and dirs... nothing found Searching for t0rn's v8 defaults... nothing found Searching for Lion Worm default files and dirs... nothing found Searching for RSHA's default files and dir... nothing found Searching for RH-Sharpe's default files... nothing found Searching for Ambient's rootkit (ark) default files and dirs... nothing found Searching for suspicious files and dirs, it may take a while... /usr/lib/perl/5.6.1/auto/Test/Harness/.packlist /usr/lib/perl/5.6.1/auto/DB_File/.packlist Searching for LPD Worm files and dirs... nothing found Searching for Ramen Worm files and dirs... nothing found Searching for Maniac files and dirs... nothing found Searching for RK17 files and dirs... nothing found Searching for Ducoci rootkit... nothing found Searching for Adore Worm... nothing found Searching for ShitC Worm... nothing found Searching for Omega Worm... nothing found Searching for Sadmind/IIS Worm... nothing found Searching for MonKit... nothing found Searching for Showtee... nothing found Searching for OpticKit... nothing found Searching for T.R.K... nothing found Searching for Mithra... nothing found Searching for OBSD rk v1... nothing found Searching for LOC rootkit ... nothing found Searching for Romanian rootkit ... nothing found Searching for Suckit rootkit ... nothing found Searching for Volc rootkit ... nothing found Searching for Gold2 rootkit ... nothing found Searching for TC2 Worm default files and dirs... nothing found Searching for Anonoying rootkit default files and dirs... nothing found Searching for ZK rootkit default files and dirs... nothing found Searching for ShKit rootkit default files and dirs... nothing found Searching for AjaKit rootkit default files and dirs... nothing found Searching for zaRwT rootkit default files and dirs... nothing found Searching for anomalies in shell history files... nothing found Checking `asp`... not infected Checking `bindshell`... not infected Checking `lkm`... nothing detected Checking `rexedcs`... not found Checking `sniffer`... eth0: not promisc and no PF_PACKET sockets eth0:0: not promisc and no PF_PACKET sockets eth0:1: not promisc and no PF_PACKET sockets eth0:2: not promisc and no PF_PACKET sockets eth0:3: not promisc and no PF_PACKET sockets eth0:4: not promisc and no PF_PACKET sockets Checking `w55808`... not infected Checking `wted`... nothing deleted Checking `scalper`... not infected Checking `slapper`... not infected Checking `z2`... nothing deleted
웜, 루트킷 등이 발견되면 INFECTED (대문자로)라는 문자열로 표시됩니다.
chkrootkit의 출력을 매일 오전 3시에 이메일로 받고 싶다면, root의 크론 파일에 다음 줄을 추가할 수 있습니다 (위치에 따라 다를 수 있습니다; Debian에서는 /var/spool/cron/crontabs/root에 있습니다; /var/spool/cron/tabs/root 또는 비슷한 곳에서도 찾을 수 있습니다):
0 3 (cd /usr/local/chkrootkit; ./chkrootkit 2>&1 | mail -s “chkrootkit output” [email protected])*
그런 다음 실행합니다:
chmod 600 /var/spool/cron/crontabs/root
/etc/init.d/cron restart
3 Portsentry 설치
cd /tmp
tar xvfz portsentry-1.2.tar.gz
cd portsentry_beta/
make linux
make install
Portsentry는 /usr/local/psionic/portsentry/에 설치됩니다.
/usr/local/psionic/portsentry/portsentry.conf를 편집하고 portsentry가 보호할 포트를 지정합니다:
| # 정말로 세심하다면 주석을 제거하세요: #TCP_PORTS="1,7,9,11,15,70,79,80,109,110,111,119,138,139,143,512,513,514,515,540,635,1080,1524,2000,[...]" #UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,31335,[...]" # # 단순히 인지하고 싶다면 사용하세요: TCP_PORTS="1,11,15,79,111,119,143,540,635,1080,1524,2000,5742,6667,12345,12346,20034,27665,31337,[...]" UDP_PORTS="1,7,9,69,161,162,513,635,640,641,700,37444,34555,31335,32770,32771,32772,32773,32774,[...]" # # 최소한의 기본만 사용하세요 #TCP_PORTS="1,11,15,110,111,143,540,635,1080,1524,2000,12345,12346,20034,32771,32772,32773,32774,[...]" #UDP_PORTS="1,7,9,69,161,162,513,640,700,32770,32771,32772,32773,32774,31337,54321"
시스템에서 사용되지 않는 포트여야 합니다. 예를 들어, 서버에서 IMAP (포트 143 TCP)을 사용하는 경우 위 목록에서 143을 제거해야 합니다. portsentry.conf의 나머지 부분은 잘 주석 처리되어 있지만, 일반적으로 기본값이 작동해야 합니다.
이제 portsentry를 위한 init 스크립트를 생성해야 합니다 (/etc/init.d/portsentry). 우리는 포트 스캔을 감지하는 가장 강력한 방법인 고급 스텔스 모드에서 portsentry를 실행할 것입니다:
| #!/bin/bash case "$1" in start) echo "Portsentry 시작 중..." ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry -atcp' | grep -iv 'grep' > /dev/null if [ $? != 0 ]; then /usr/local/psionic/portsentry/portsentry -atcp fi ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry -audp' | grep -iv 'grep' > /dev/null if [ $? != 0 ]; then /usr/local/psionic/portsentry/portsentry -audp fi echo "Portsentry가 이제 실행 중입니다!" ;; stop) echo "Portsentry 종료 중..." array=(`ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry' | grep -iv 'grep' | awk '{print $1}' | cut -f1 -d/ | tr ' ' ' '`) element_count=${#array[@]} index=0 while [ "$index" -lt "$element_count" ] do kill -9 ${array[$index]} let "index = $index + 1" done echo "Portsentry가 중지되었습니다!" ;; restart) $0 stop && sleep 3 $0 start ;; *) echo "사용법: $0 {start|stop|restart}" exit 1 esac exit 0
chmod 755 /etc/init.d/portsentry
부팅 시 portsentry를 시작하려면 다음을 수행합니다:
ln -s /etc/init.d/ portsentry /etc/rc2.d/S20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc3.d/S20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc4.d/S20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc5.d/S20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc0.d/K20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc1.d/K20 portsentry
ln -s /etc/init.d/ portsentry /etc/rc6.d/K20 portsentry*
이제 portsentry를 시작합니다:
/etc/init.d/portsentry start
참고: portsentry를 실행하면 chkrootkit이 감염된 바인드쉘에 대해 불평할 수 있습니다:
Checking bindshell… INFECTED (PORTS: 31337)
이는 정상이며 걱정할 필요가 없습니다.
4 Logcheck 설치
cd /tmp
tar xvfz logcheck-1.1.1.tar.gz
cd logcheck-1.1.1/systems/
이제 logcheck.sh에서 변수 SYSADMIN을 변경합니다. SYSADMIN은 logcheck의 출력을 이메일로 받을 사람입니다 (이메일 주소나 logcheck를 설치하는 시스템의 사용자일 수 있습니다):
| [...] # 구성 섹션 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin # Logcheck는 대부분의 BSD 유사 시스템에서 작동하도록 미리 구성되어 있지만, # 다소 단순한 프로그램이므로 다른 시스템에서 작동하려면 약간의 도움이 필요할 수 있습니다. # 다음 명령 경로가 올바른지 확인하십시오. # 로그 활동을 보낼 사람. [email protected] # 로그테일 프로그램의 전체 경로. # 이 프로그램은 이 스크립트를 실행하는 데 필요하며 패키지와 함께 제공됩니다. LOGTAIL=/usr/local/bin/logtail [...]
cd ../../
mkdir -p /usr/local/etc/tmp
make
이렇게 하면 logcheck가 /usr/local/etc에 설치됩니다.
이제 logcheck를 주기적으로 실행하기 위해 크론 작업을 생성해야 합니다. root의 크론 파일을 편집합니다 (예: /var/spool/cron/crontabs/root, 섹션 2 “Chkrootkit 설치“ 참조) 및 다음 줄을 입력합니다:
0 3 /usr/local/etc/logcheck.sh*
그런 다음 실행합니다:
chmod 600 /var/spool/cron/crontabs/root
/etc/init.d/cron restart
이렇게 하면 매일 오전 3시에 logcheck가 호출됩니다. 이제 비정상적인 시스템 이벤트, 보안 위반, 시스템 공격 등에 대해 알려줄 것입니다. 시스템이 인터넷에 직접 노출되어 있다면 인터넷에서 많은 악의적인 활동이 있다는 것을 알게 될 것이며, 보안이 매우 중요한 이유를 느낄 수 있을 것입니다.
링크
Chkrootkit: http://www.chkrootkit.org/
Portsentry: http://sourceforge.net/projects/sentrytools/
이 문서의 원본 위치:
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.