Linux伺服器被黑客攻擊,安全檢查方法
阿新 • • 發佈:2018-11-01
一、檢查系統密碼檔案,檢視檔案修改日期
# ls -l /etc/passwd
二、檢視 passwd 檔案中有哪些特權使用者
# awk -F: '$3==0 {print $1}' /etc/passwd
三、檢視系統裡有沒有空口令帳戶
# awk -F: 'length($2)==0 {print $1}' /etc/shadow
四、檢查系統守護程序
# cat /etc/xinetd.conf | grep -v "^#" #這個程序在centos7以上沒有了
五、檢查網路連線和監聽埠
# netstat –an # netstat –rn # ifconfig –a
六、檢視正常情況下登入到本機的所有使用者的歷史記錄
# last
七、檢查系統中的 core 檔案
# find / -name core -exec ls -l {} \;
八、檢查系統檔案完整性
# rpm -Vf /bin/ls
# rpm -Vf /usr/sbin/sshd
# rpm -Vf /sbin/ifconfig
# rpm -Vf /usr/sbin/lsof
# md5sum –b 檔名
# md5sum –t 檔名
九、查詢是否有後門
# cat /etc/crontab # ls /var/spool/cron/ ; crontab -l #檢視定時任務是否被修改 # cat /etc/rc.d/rc.local # ls /etc/rc.d # ls /etc/rc3.d # find / -type f -perm 4000 #檢視是否為管理員增加或者修改
十、檢視臨時目錄是否存在攻擊者入侵時留下的殘餘檔案
#tail -n 100 ~/.bash_history | more
#是否存在.c .py .sh為字尾的檔案或者2進位制elf檔案
ls -la /tmp
ls -la /var/tmp
find / -name \*.elf | xargs ls -l
十一、在web目錄下執行
#檢視是否有木馬 grep -r "getRuntime" ./ #執行的時候被連線或者被任何程式呼叫 find . -type f -name "*.jsp" | xargs grep -i "getRuntime" #返回ip地址字串 find . -type f -name "*.jsp" | xargs grep -i "getHostAddress" #建立WshShell物件可以執行程式、操作登錄檔、建立快捷方式、訪問系統資料夾、管理環境變數 find . -type f -name "*.jsp" | xargs grep -i "wscript.shell" #gethostbyname()返回對應於給定主機名的包含主機名字和地址資訊的hostent結構指標 find . -type f -name "*.jsp" | xargs grep -i "gethostbyname" #呼叫系統命令提權 find . -type f -name "*.jsp" | xargs grep -i "bash" #Jsp木馬預設名字 find . -type f -name "*.jsp" | xargs grep -i "jspspy" #檢查是否有非授權訪問管理日誌 find . -type f -name "*.jsp" | xargs grep -i "getParameter" #要進中介軟體所在日誌目錄執行命令 fgrep –R "admin_index.jsp" 20170702.log > log.txt #遞迴地讀取每個目錄下的所有檔案 #檢視是否出現對應的記錄 fgrep –R "and1=1" *.log > log.txt fgrep –R "select " *.log > log.txt fgrep –R "union " *.log > log.txt fgrep –R "../../" *.log > log.txt fgrep –R "Runtime" *.log > log.txt fgrep –R "passwd" *.log > log.txt #檢視是否有shell攻擊 fgrep –R "uname -a" *.log > log.txt fgrep –R "id" *.log > log.txt fgrep –R "ifconifg" *.log> log.txt fgrep –R "ls -l" *.log > log.txt
十二、安裝chrootkit,檢查是否有rootkit
rootkit是入侵者經常使用的工具,這類工具可以隱祕、令使用者不易察覺的建立了一條能夠總能夠入侵系統或者說對系統進行實時控制的途徑。
yum install -y glibc-static
mkdir chrootkit
cd chrootkit/
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
tar zxvf chkrootkit.tar.gz
cd chkrootkit-0.52/
make sense #編譯
./chkrootkit #檢測命令,若出現INFECTED那就要小心了(./chkrootkit | grep INFECTED)
檢測指令碼,放到定時任務裡面即可
#!/bin/bash
#sript name:chkrootkit.sh
TOOLKITSPATH=/usr/local
[email protected]
file_chkrootkit_log=chkrootkitcron.log
servername=`hostname`
date=`date +%Y-%m-%d`
cd ${TOOLKITSPATH}/chkrootkit
./chkrootkit > ${file_chkrootkit_log}
[ ! -z "$(grep INFECTED ${file_chkrootkit_log})" ] && \
grep INFECTED ${file_chkrootkit_log} | mail -s "[chkrootkit] report in ${servername} ${date}" ${MAILUSER}
備註:登入的時候提示資訊在 /etc/motd 檔案裡面
十三、bash shell 漏洞
1、測試程式碼,有問題的
[[email protected] ~]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable
this is a test
2、修復(下面是參考網上的東西,不知道效果怎麼樣)
[[email protected] ~]# yum -y install yum-downloadonly
[[email protected] ~]# yum -y install bash-4.1.2-33.el6_7.1.x86_64.rpm
3、重新測試
[[email protected] ~]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
this is a test
#備註
當我們輸入 env x='() { :;}; echo vulnerable'; bash -c "echo this is a test" 又可以出來不一樣的效果
十四、完成後做了如下措施
修改了root賬號密碼
修改了sshd預設埠
修改Nginx使用者nologin
發現系統伺服器存在bash嚴重漏洞、破殼漏洞(Shellshock)並修復