計算目錄下的md5值,用於檔案被篡改後對比

來源:互聯網
上載者:User

標籤:軟體   伺服器   檢測   樣本   local   

計算/etc目錄下的md5值,用於檔案被篡改後對比,命令如下:

find /etc/ -maxdepth 1 -type f | xargs -n1 md5sum> /root/etc_sum-$(date +%F).log

同樣的道理,

我們可以將/usr/bin  /usr/sbin/ /usr/local/bin /root/bin 等等重要的目錄下面的檔案校正和都計算一遍,這樣的話定期執行一下該命令,產生一份最新的校正和,通過diff命令將產生的log檔案和原始的md5sum.log比較.

如果發現有變化的,則伺服器有可能被入侵,需要及時查毒(查毒的話,可以使用clamav這個軟體,epel源裡面有這個rpm包)


下面是我自己寫的檢測檔案是否發生變化的指令碼,先產生一份原始的md5校正和作為樣本,如下:

find /bin -maxdepth 1 -type f | xargs -n1 md5sum > /home/sum/bin_sum_ori.log find /sbin -maxdepth 1 -type f | xargs -n1 md5sum > /home/sum/sbin_sum_ori.log



然後,編寫/home/scripts/chkmd5sum.sh指令碼,下面指令碼中我只對/sbin和/bin下的檔案MD5sum做了校正,其他的可以參照補充:

#!/bin/bashBIN_SUM_LOG="/home/sum/bin_sum-$(date +%F).log"SBIN_SUM_LOG="/home/sum/sbin_sum-$(date +%F).log"find /bin -maxdepth 1 -type f | xargs -n1 md5sum > $BIN_SUM_LOGfind /sbin -maxdepth 1 -type f | xargs -n1 md5sum > $SBIN_SUM_LOGif ! diff $BIN_SUM_LOG  /home/sum/bin_sum_ori.log > /dev/null ;thenecho "Some file‘s md5sum is changed in /bin,please check"|mail -s "Warning, /bin Checksum not matched" [email protected]fiif ! diff $SBIN_SUM_LOG  /home/sum/sbin_sum_ori.log > /dev/null ;thenecho "Some file‘s md5sum is changed in /sbin,please check"|mail -s "Warning, /sbin Checksum not matched" [email protected]fi


然後,我們添加個cron計劃任務(如下),每天0點30檢查執行該指令碼,檢測下檔案是否變化即可。

 echo ‘30 0 * * * /bin/bash /home/scripts/chkmd5sum.sh > /dev/null 2>&1‘ >> /var/spool/cron/root


當然,Linux下還有個軟體叫做tripwire,它的功能更強大,有興趣的可以自己百度下。

計算目錄下的md5值,用於檔案被篡改後對比

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.