문서의 이전 판입니다!
리눅스 서버에 해킹에의한 바이러스 감염으로 개고생 수기…
갑자기 서버가 늦어져서 top 을 통해 본 결과 이상한 프로세스가 cpu 사용을 99% 하고 있었다.
우선 99%를 차지하는 프로세스를 kill 했으나 또 다시 다른 형태로 살아남 (갑자기 심각해짐…)
find 명령으로 해당 프로세스이름을 찾아보니 /boot 경로에 위치해 있음 해당 프로그램을 삭제했으나 다른 프로그램으로 복제되어 다시 생성됨 (머리 아파지기 시작함)
cron 에 뭔가 등록되어 있을것 같아서 crontab을 확인해 보니 내가 지정하지 않은 프로세스가 마지막에 돌고 있는것 확인 해당 항목을 crontab 에서 삭제했는데 잠시후에 다시 생겨남 (짜증이 올라옴)
바이러스 감지툴인 clamAV 를 yum 으로 설치하여 점검해보니 몇가지 파일들이(netstat, ps 등등) 변경되어 있는것 확인됨 해당 파일을 rm 으로 삭제해보니 삭제가 안됨
다시 rkhunter 를 설치하여 바이러스 다시 확인해 보니 clamAV에서 찾지 못한 다양한 형태의 경고가 등장함
감염된 파일을 살펴본 결과 등록되느 않은 사용자와 그룹으로 만들어져 있고 해당 파일들의 속성에 stiky bit 가 설정되어 있어 삭제할 수 없었음
우선 다른 pc에 VMWare 상에 해당 버전의 리눅스를 설치함 (파일을 비교해 보기 위해서…)
리눅스를 cd로 부팅하여 rescue 모드로 진입 (원래 파일들은 /mnt/sysimages 경로에 마운트 된다.)
해당 파일들을 개별로 속성를 변경해주다가 몇가지 파일을 비교해 보던중 찾던중 아래의 쉘파일을 찾게됨…
다음 쉘을 돌리던지 개별로 작업하든하면 해결됨.
이상 개고생 끝.
추신: 몇가지 .h 파일등도 변경된 내용이 있고 init.d 및 rc?.d 경로아래에 수없이 많은 사항들이 있느니 찾아서 삭제해줘야 함
#!/bin/bash echo "SHV Rootkit checker by alex [at] evilcoder.net" if [ $# -ne 1 ] then echo "This is a SHV5 rootkit remover" echo "This script is released as it is and i can't be held responsable for any damages" echo "This script has been tested on Debian , Ubuntu and CentOS servers " echo "You must agree with that" echo "Usage : $0 yes" exit 1 fi if [ "$1" != "yes" ]; then echo "You should agree" exit 1 elif [ "$1" == "yes" ]; then echo "Thanks" fi #checking Linux type OS=`cat /etc/issue|cut -d " " -f 1 | head -1` if [ -d "/usr/lib/libsh" ]; then echo "We have SHV rootkit" else echo "You don't have shv5 installed" exit 1 fi echo "System Check" if [ "$OS" == "Debian" ]; then echo "We have Debian" echo "Removing immutable from infected files" chattr -sia /bin/dir chattr -sia /usr/bin/find chattr -sia /sbin/ifconfig chattr -sia /bin/ls chattr -sia /usr/bin/lsof chattr -sia /usr/bin/md5sum chattr -sia /bin/netstat chattr -sia /bin/ps chattr -sia /usr/bin/pstree chattr -sia /usr/bin/top chattr -sia /lib/libsh.so chattr -sia /usr/lib/libsh chattr -sia /usr/lib/libsh/* chattr -sia /etc/sh.conf chattr -sia /sbin/ttymon chattr -sia /sbin/ttyload echo "Deleting rootkit folders" rm -rf /lib/libsh.so rm -rf /usr/lib/libsh/ rm -rf /etc/sh.conf rm -rf /sbin/ttyload rm -rf /sbin/ttymon echo "Reinstall new files" apt-get update >>/dev/null apt-get -y install --reinstall coreutils binutils net-tools psmisc lsof procps findutils >>/dev/null echo "Killing Rootkit" killall -9 ttymon echo "You should reboot to finish cleaning" elif [ "$OS" == "Ubuntu" ];then echo "We have Ubuntu" echo "Removing immutable from Ubuntu known infected files" chattr -sia /bin/dir chattr -sia /usr/bin/find chattr -sia /sbin/ifconfig chattr -sia /bin/ls chattr -sia /usr/bin/lsof chattr -sia /usr/bin/md5sum chattr -sia /bin/netstat chattr -sia /bin/ps chattr -sia /usr/bin/pstree chattr -sia /usr/bin/top chattr -sia /lib/libsh.so chattr -sia /usr/lib/libsh chattr -sia /usr/lib/libsh/* chattr -sia /etc/sh.conf chattr -sia /sbin/ttymon chattr -sia /sbin/ttyload echo "Deleting rootkit folders" rm -rf /lib/libsh.so rm -rf /usr/lib/libsh/ rm -rf /etc/sh.conf rm -rf /sbin/ttyload rm -rf /sbin/ttymon echo "Reinstall new files" apt-get update >>/dev/null apt-get -y install --reinstall coreutils binutils net-tools psmisc lsof procps findutils >>/dev/null echo "Killing Rootkit" killall -9 ttymon echo "You should reboot to finish cleaning" elif [ "$OS" == "CentOS" ];then echo "We got CentOS" echo "Removing immutable flag from CentOS known infected files" chattr -sia /usr/bin/dir chattr -sia /usr/bin/find chattr -sia /sbin/ifconfig chattr -sia /bin/ls chattr -sia /usr/sbin/lsof chattr -sia /usr/bin/md5sum chattr -sia /bin/netstat chattr -sia /bin/ps chattr -sia /usr/bin/pstree chattr -sia /usr/bin/top chattr -sia /lib/libsh.so chattr -sia /usr/lib/libsh chattr -sia /usr/lib/libsh/* chattr -sia /etc/sh.conf chattr -sia /sbin/ttymon chattr -sia /sbin/ttyload echo "Deleting rootkit folders" rm -rf /lib/libsh.so rm -rf /usr/lib/libsh/ rm -rf /etc/sh.conf rm -rf /sbin/ttyload rm -rf /sbin/ttymon echo "Reinstall new files" yum -y reinstall coreutils binutils net-tools psmisc lsof procps findutils >>/dev/null echo "Killing Rootkit" killall -9 ttymon echo "You should reboot to finish cleaning" fi fi