2016年11月17日 15:52:33 UpUpUpUpUpUpUp 閱讀數 3359linux
版權聲明:本文爲博主原創文章,未經博主容許不得轉載。 https://blog.csdn.net/u012599988/article/details/53201212redis
記錄一次查詢清除木馬過程
木馬名稱:安全
Linux.BackDoor.Gates.5
連接:https://forum.antichat.ru/threads/413337/bash
前兩天服務器被掃描後,出現莫名進程,清理後重啓,也把原來的SSH密碼登錄改成公鑰,僅僅過去兩天,一早登錄服務器發現一個進程直接懵了,清掉我ROOT全部文件。服務器
這是/etc/profile文件,發現!!!運維
這明顯是前天我沒有清理乾淨,又被攻擊了。ssh
那就開始排查,戰鬥!工具
先清理可疑程序,如:
spa
明顯不認識吶,個人服務器跑了什麼我還不知道?.net
幹掉!咦,幹掉本身起來。明顯是自啓!!! 查,/etc/rc.local
進程殺了又起來,文件刪了又自動生成,無奈之下只好想了一個怪招,把/bin/bash重命名一下
再查詢基礎命令是否被掉包:
對比下其餘在正常服務器的顯示以下:
怒了有沒有!明顯換了。換成程序大小爲1.2M的了。
那就刪掉被更改的,從其餘同配置服務器拷貝一份。
記的拷貝過來要給予755 權限。
分析了一下,這些木馬程序名字變着花樣來,但萬變不離其宗,名字都寫
在/etc/rc.d/init.d/DbSecuritySpt和/etc/rc.d/init.d/selinux裏面,並且名字和正常的服務很像。
注意rm命令也被掉包了,須要更換!
有:
/usr/bin/bsd-port/getty、/usr/bin/dpkgd/ps /usr/bin/.sshd
哈哈,清理了這些服務器CPU立馬從100%下來了。
簡單判斷有無木馬 有無下列文件 cat /etc/rc.d/init.d/selinux cat /etc/rc.d/init.d/DbSecuritySpt ls /usr/bin/bsd-port ls /usr/bin/dpkgd 查看大小是否正常 ls -lh /bin/netstat ls -lh /bin/ps ls -lh /usr/sbin/lsof ls -lh /usr/sbin/ss
刪除以下目錄及文件 rm -rf /usr/bin/dpkgd (ps netstat lsof ss) rm -rf /usr/bin/bsd-port (木馬程序) rm -f /usr/local/zabbix/sbin/zabbix_AgentD (木馬程序) rm -f /usr/local/zabbix/sbin/conf.n rm -f /usr/bin/.sshd rm -f /usr/bin/sshd rm -f /root/cmd.n rm -f /root/conf.n rm -f /root/IP rm -f /tmp/gates.lod rm -f /tmp/moni.lod rm -f /tmp/notify.file 程序 rm -f /tmp/gates.lock 進程號 rm -f /etc/rc.d/init.d/DbSecuritySpt(啓動上述描述的那些木馬變種程序) rm -f /etc/rc.d/rc1.d/S97DbSecuritySpt rm -f /etc/rc.d/rc2.d/S97DbSecuritySpt rm -f /etc/rc.d/rc3.d/S97DbSecuritySpt rm -f /etc/rc.d/rc4.d/S97DbSecuritySpt rm -f /etc/rc.d/rc5.d/S97DbSecuritySpt rm -f /etc/rc.d/init.d/selinux(默認是啓動/usr/bin/bsd-port/getty) rm -f /etc/rc.d/rc1.d/S99selinux rm -f /etc/rc.d/rc2.d/S99selinux rm -f /etc/rc.d/rc3.d/S99selinux rm -f /etc/rc.d/rc4.d/S99selinux rm -f /etc/rc.d/rc5.d/S99selinux
如:
而後找出下列程序進程號並殺死:
/root/ps aux |grep -i jul29(主要是最近開啓的進程)
/root/ps aux |grep -i jul30
/root/ps aux |grep -i jul31
/root/ps aux |grep sshd
/root/ps aux |grep ps
/root/ps aux |grep getty
/root/ps aux |grep netstat
/root/ps aux |grep lsof
/root/ps aux |grep ss
/root/ps aux |grep zabbix_Agetntd
/root/ps aux |grep .dbus
如:
注意若是kill後刪除後還會再出現就這樣操做(破壞木馬程序)
/usr/bin/dpkgd/ps && /root/chattr +i /usr/bin/dpkgd/ps
/usr/bin/bsd-port/getty && /root/chattr +i /usr/bin/bsd-port/getty
刪除含木馬命令並從新安裝(或者把上傳的正常程序複製過去也行)
ps
/root/chattr -i -a /bin/ps && rm /bin/ps -f
yum reinstall procps -y
或
cp /root/ps /bin
netstat
/root/chattr -i -a /bin/netstat && rm /bin/netstat -f
yum reinstall net-tools -y
或
cp /root/netstat /bin
lsof
/root/chattr -i -a /bin/lsof && rm /usr/sbin/lsof -f
yum reinstall lsof -y
或
cp /root/lsof /usr/sbin
chattr && lsattr
yum -y reinstall e2fsprogs
ss
/root/chattr -i -a /usr/sbin/ss && rm /usr/sbin/ss -f
yum -y reinstall iproute
或
cp /root/ss /usr/sbin
修改下面兩個程序的權限,這個是意外發現有的改了這兩個程序的權限,讓你發現了木馬既不能下載正常程序也不能殺進程
/usr/bin/killall /usr/bin/wget
另外他們還修改了DNS怕咱們識別不了有的域名吧,想得很周到。
cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
——————————————————————
工具掃描
安裝殺毒工具
安裝
yum -y install clamav*
啓動
service clamd restart
更新病毒庫
freshclam
掃描方法
clamscan -r /etc –max-dir-recursion=5 -l /root/etcclamav.log
clamscan -r /bin –max-dir-recursion=5 -l /root/binclamav.log
clamscan -r /usr –max-dir-recursion=5 -l /root/usrclamav.log
clamscan -r –remove /bin/
clamscan -r –remove /usr/bin/
查看日誌發現
/bin/netstat: Linux.Trojan.Agent FOUND爲病毒
grep FOUND /root/usrclamav.log
/usr/bin/.sshd: Linux.Trojan.Agent FOUND
/usr/sbin/ss: Linux.Trojan.Agent FOUND
/usr/sbin/lsof: Linux.Trojan.Agent FOUND 如: 「`
增強自身安全
可是此時還不知道系統入侵的緣由,只能從兩個方面考慮:暴力破解和系統及服務漏洞
a、yum update 更新系統(特別是bash、openssh和openssl)
b、關閉一些沒必要要的服務
c、設置ssh普通用戶登錄並用hosts.all、hosts.deny限制登錄的網段
d、記錄登錄系統後操做的命令
在平常運維中,咱們須要清楚服務器上每一個用戶登陸後都作了哪些操做,咱們須要記錄下每一個用戶的操做命令。
下面的內容設置能夠實如今Linux下全部用戶,無論是遠程仍是本地登錄,在本機的全部操做都會記錄下來,並生成包含「用戶/IP/時間」的文件存放在指定位置。
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]" USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` HISTDIR=/var/log/.hist if [ -z $USER_IP ] then USER_IP=`hostname` fi if [ ! -d $HISTDIR ] then mkdir -p $HISTDIR chmod 777 $HISTDIR fi if [ ! -d $HISTDIR/${LOGNAME} ] then mkdir -p $HISTDIR/${LOGNAME} chmod 300 $HISTDIR/${LOGNAME} fi export HISTSIZE=4096 DT=`date +%Y%m%d_%H%M%S` export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT" chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null
獲得的結果,永久保存,每一個用戶的命令記錄分目錄保存
ls -l /var/log/.hist/root/
-rw——- 1 root root 546 2006-05-26 10:00 218.82.245.54.hist.20060526_092458
-rw——- 1 root root 243 2006-05-28 13:28 218.82.245.54.hist.20060528_114822
-rw——- 1 root root 10 2006-05-28 12:18 218.82.245.54.hist.20060528_121605查看命令記錄
export HISTFILE=/var/log/.hist/root/xx04.hist.208_152551[root@demoredis_171 root]# history 1 2016-11-17 15:41:40 ll 2 2016-11-17 15:41:42 cd /data/ 3 2016-11-17 15:41:42 ll 4 2016-11-17 15:41:47 cd /var/log/.hist/ 5 2016-11-17 15:41:47 ll 6 2016-11-17 15:41:48 cd root/ 7 2016-11-17 15:41:48 ll 10 2016-11-17 15:42:18 export HISTFILE=18—.hist.20161117_154054 11 2016-11-17 15:42:21 history