root@linux-szge:/var/spool/cron # cd tabs/ total 8 -rw-r--r-- 1 root root 3467 Feb 16 11:39 root -rw-r--r-- 1 root root 3467 Jan 17 10:58 xiaofei
所有用戶的計划任務,都會在這個目錄下產生對應的文件
黑客:通過crontab , 篡改一個系統級別的計划任務
root@linux-szge:/var/spool/cron/tabs # ls /etc/cron cron.d/ cron.daily/ cron.deny cron.hourly/ cron.monthly/ cron.weekly/ crontab
注:
cron.d 系統級別的定時任務
cron.daily 系統每天要執行的計划任務
cron.hourly 系統每小時要執行的計划任務
cron.monthly 系統每月要執行的計划任務
cron.weekly 系統每周要執行的計划任務
測試:
[root@linux-szge ~]# vim /etc/cron.daily/tmpwatch
#! /bin/sh flags=-umc /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \ -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \ -X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' \ -X '/tmp/pymp-*' 10d /tmp /usr/sbin/tmpwatch "$flags" 30d /var/tmp for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do if [ -d "$d" ]; then /usr/sbin/tmpwatch "$flags" -f 30d "$d" fi done echo test #添加一行
[root@linux-szge ~]# /etc/cron.daily/tmpwatch test
注:說明添加木馬成功了
排查篡改木馬的方式:
使用md5值去排查 (通過對比md5值去判斷文件是否修改)
修改前 [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch 5dcd732b139638ed23a0e6dd7ca7a784 /etc/cron.daily/tmpwatch
修改后 [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch 5acb09733d49c4befaf0b0ef382eed67 /etc/cron.daily/tmpwatch
對/etc/cron*下所有文件都生成md5值,記錄到/usr/share/file_md5.v1文件中,方便發現問題時去對比
[root@linux-szge ~]# find /etc/cron* -type f -exec md5sum {} \; > /usr/share/file_md5.v1 [root@linux-szge ~]# cat /usr/share/file_md5.v1 367636170f3ac44df6a117e3cbf7e4ba /etc/cron.d/raid-check 4b98b6b029e76aa6e0fa3fde2ec5572a /etc/cron.d/0hourly b904bdae184e1d37d52b04dd28bd4ea6 /etc/cron.d/sysstat 5acb09733d49c4befaf0b0ef382eed67 /etc/cron.daily/tmpwatch 723dc41aa3e09723762b7d6c5966414b /etc/cron.daily/mlocate.cron 55735e2ab5f2052f7e885bca1230332e /etc/cron.daily/logrotate 54d753840882c7ec71313fe6bfba1225 /etc/cron.daily/cups d05fe6bf89faa69ffc11a8aab2519f15 /etc/cron.daily/readahead.cron de7d9c2df94e20af5aa401e708c3119d /etc/cron.daily/prelink 79937e0e1cb83fad092c4f8252827225 /etc/cron.daily/makewhatis.cron d41d8cd98f00b204e9800998ecf8427e /etc/cron.deny 0033096afd5c735bc99821f847bd61a2 /etc/cron.hourly/0anacron 2b843bf5238314a659b51ea6061ca611 /etc/cron.monthly/readahead-monthly.cron 4f2aaa54c48dda350f75da151f79ae57 /etc/crontab
對比方式(當感覺出現問題時,記錄新的md5值到/usr/share/file_md5.v2文件中):
#! /bin/sh flags=-umc /usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \ -x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \ -X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' \ -X '/tmp/pymp-*' 10d /tmp /usr/sbin/tmpwatch "$flags" 30d /var/tmp for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do if [ -d "$d" ]; then /usr/sbin/tmpwatch "$flags" -f 30d "$d" fi done echo test echo test2 #再次修改文件,方便對比效果 ~
[root@linux-szge ~]# /etc/cron.daily/tmpwatch test test2 [root@linux-szge ~]# md5sum /etc/cron.daily/tmpwatch 36abcd1a234e1c50185734627bd6e1b5 /etc/cron.daily/tmpwatch
開始對比,可以發現md5值發生變化
[root@linux-szge ~]# find /etc/cron* -type f -exec md5sum {} \; > /usr/share/file_md5.v2 #新的md5記錄到文件 [root@linux-szge ~]# diff /usr/share/file_md5.v1 /usr/share/file_md5.v2 4c4 < 5acb09733d49c4befaf0b0ef382eed67 /etc/cron.daily/tmpwatch --- > 36abcd1a234e1c50185734627bd6e1b5 /etc/cron.daily/tmpwatch
查看開機啟動進程:
/etc/rc.local 這個是開機啟動腳本
[root@linux-szge ~]# vim /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local echo tt #插入這個內容
排查方式:(有些黑客會在文件中打出很多空行以至於你看不出來黑客所添加的內容)
那么我們怎么去排查呢?(使用grep)
[root@linux-szge ~]# grep -v ^$ /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local echo tt
利用開機啟動的服務器腳本來加載木馬程序,把木馬程序腳本寫到已經存在的開機啟動服務中。例如:http(apache web 服務器啟動腳本等)
[root@linux-szge ~]# cp /etc/init.d/network /etc/init.d/test [root@linux-szge ~]# vim !$ #! /bin/bash # # network Bring up/down networking # # chkconfig: 2345 10 90 # description: Activates/Deactivates all network interfaces configured to \ # start at boot time. # ### BEGIN INIT INFO # Provides: $network # Should-Start: iptables ip6tables # Short-Description: Bring up/down networking # Description: Bring up/down networking ### END INIT INFO # Source function library. touch /tmp/txt #刪除原來腳本內容,寫成自己的木馬程序
排查方法
方法1:對比其他服務器的配置文件,利用MD5值進行對比
方法2:查看被黑當天生成或修改的文件
查看被前一天到現在修改的文件 [root@linux-szge ~]# find /etc/cron.daily/* -mtime -1 /etc/cron.daily/tmpwatch
方法3:使用rpm檢查文件完整性
語法:rpm -V 軟件包的名字 #使用rpm檢查這個軟件包所生成的文件的完整性
語法:rpm -Vf 命令的絕對路徑 #使用rpm檢查命令的完整性