Linux伺服器被黑遭敲詐,3小時緊急逆襲!
作者介紹
陳浩,北信源研發工程師,五年Linux運維工作經驗,熱衷運維技術研究、實踐和團隊分享。
1.起因
本來在家正常休息了,我們放在上海託管機房的線上伺服器突然崩了遠端不了,服務啟動不了,然後讓上海機房重啟了一次,還是直接掛了,一直到我遠端上才行。
2.現象
遠端伺服器發現出現這類資訊
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
登入資訊,然後翻牆去了國外網站檢視
這個意思大概是:
問候,
你的伺服器被黑客攻擊和你的檔案已經被刪除了。
他們被刪除之前,我們支援我們的伺服器控制。
你必須傳送總共3 BTC地址:1 b1ou6edreyffif3*******
不這麼做將導致檔案被刪除後5天。
我們也可能洩露你的檔案。你可以通過電子郵件與[email protected]聯絡。我們不會提供任何檔案之前付款。
再見!
3.開始排查
首先檢查日誌,以前做過安全運維,所以寫過類似於檢查命令和工具,開始一一排查。
#檢視是否為管理員增加或者修改 find / -type f -perm 4000 #顯示檔案中檢視是否存在系統以外的檔案 rpm -Vf /bin/ls rpm -Vf /usr/sbin/sshd rpm -Vf /sbin/ifconfig rpm -Vf /usr/sbin/lsof #檢查系統是否有elf檔案被替換 #在web目錄下執行 grep -r “getRuntime” ./ #檢視是否有木馬 find . -type f -name “*.jsp” | xargs grep -i “getRuntime” #執行的時候被連線或者被任何程式呼叫 find . -type f -name “*.jsp” | xargs grep -i “getHostAddress” #返回ip地址字串 find . -type f -name “*.jsp” | xargs grep -i “wscript.shell” #建立WshShell物件可以執行程式、操作登錄檔、建立快捷方式、訪問系統資料夾、管理環境變數 find . -type f -name “*.jsp” | xargs grep -i “gethostbyname” #gethostbyname()返回對應於給定主機名的包含主機名字和地址資訊的hostent結構指標 find . -type f -name “*.jsp” | xargs grep -i “bash” #呼叫系統命令提權 find . -type f -name “*.jsp” | xargs grep -i “jspspy” #Jsp木馬預設名字 find . -type f -name “*.jsp” | xargs grep -i “getParameter” fgrep – R “admin_index.jsp” 20120702.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 #檢視是否出現對應的記錄 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 #檢視是否有shell攻擊 #以root許可權執行 cat /var/log/secure #檢視是否存在非授權的管理資訊 tail -n 10 /var/log/secure last cat /var/log/wtmp cat /var/log/sulog #檢視是否有非授權的su命令 cat /var/log/cron #檢視計劃任務是否正常 tail -n 100 ~./bash_history | more 檢視臨時目錄是否存在攻擊者入侵時留下的殘餘檔案 ls -la /tmp ls -la /var/tmp #如果存在.c .py .sh為字尾的檔案或者2進位制elf檔案。
Apr 17 03:14:56 localhost sshd[11499]: warning: /etc/hosts.deny, line 14: missing “:” separator Apr 17 03:15:01 localhost sshd[11499]: Address 46.214.146.198 maps to 46-214-146-198.next-gen.ro, but this does not map back to the address – POSSIBLE BREAK-IN ATTEMPT! Apr 17 03:15:01 localhost sshd[11499]: Invalid user ubnt from 46.214.146.198 Apr 17 03:15:01 localhost sshd[11500]: input_userauth_request: invalid user ubnt Apr 17 03:15:01 localhost sshd[11499]: pam_unix(sshd:auth): check pass; user unknown Apr 17 03:15:01 localhost sshd[11499]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=46.214.146.198 Apr 17 03:15:01 localhost sshd[11499]: pam_succeed_if(sshd:auth): error retrieving information about user ubnt Apr 17 03:15:03 localhost sshd[11499]: Failed password for invalid user ubnt from 46.214.146.198 port 34989 ssh2 Apr 17 03:15:03 localhost sshd[11500]: Connection closed by 46.214.146.198
歷史記錄和相關訪問日誌已經被刪除,痕跡清除。
安裝chrootkit檢查是否有rootkit mkdir chrootkit cd chrootkit/ wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz tar zxvf chkrootkit.tar.gz cd chkrootkit-0.50/ ls yum install -y glibc-static make sense ./chkrootkit
開啟 vi /etc/motd 發現
[[email protected] ~]# vi /etc/motd Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files! Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files! Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files! Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files! Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files! Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
發現一條命令讓我好奇,GET /cgi-bin/center.cgi?id=20 HTTP/1.1。
並且有點異常
發現像目前最流行的bash shell 漏洞,測試一下,果然存在漏洞。
4.修復升級命令
yum -y install yum-downloadonly
yum -y install bash-4.1.2-33.el6_7.1.x86_64.rpm
[[email protected] tmp]# yum -y install bash-4.1.2-33.el6_7.1.x86_64.rpm
已載入外掛:fastestmirror,security
設定安裝程序
診斷 bash-4.1.2-33.el6_7.1.x86_64.rpm: bash-4.1.2-33.el6_7.1.x86_64
bash-4.1.2-33.el6_7.1.x86_64.rpm 將作為 bash-4.1.2-15.el6_4.x86_64 的更新
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.skyshe.cn
* updates: ftp.sjtu.edu.cn
解決依賴關係
–> 執行事務檢查
—> Package bash.x86_64 0:4.1.2-15.el6_4 will be 升級
—> Package bash.x86_64 0:4.1.2-33.el6_7.1 will be an update
–> 完成依賴關係計算
依賴關係解決
================================
總檔案大小:3.0 M
下載軟體包:
執行 rpm_check_debug
執行事務測試
事務測試成功
執行事務
正在升級 : bash-4.1.2-33.el6_7.1.x86_64
清理 : bash-4.1.2-15.el6_4.x86_64
Verifying : bash-4.1.2-33.el6_7.1.x86_64
Verifying : bash-4.1.2-15.el6_4.x86_64
更新完畢:
bash.x86_64 0:4.1.2-33.el6_7.1
完畢!
重新測試
[[email protected] tmp]# env x='() { :;}; echo vulnerable’ bash -c “echo this is a test”
this is a test
5.完成後做了如下措施
- 修改了系統賬號密碼;
- 修改了sshd埠為2220;
- 修改Nginx使用者nologin;
- 發現系統伺服器存在bash嚴重漏洞 破殼漏洞(Shellshock)並修復;
- 更新完成後沒有發現被入侵或者伺服器自動宕機現象。
6.漏洞被利用過程
我傳送GET請求–>目標伺服器cgi路徑
目標伺服器解析這個get請求,碰到UserAgent後面的引數,Bash直譯器就執行了後面的命令。
7.Shellshock介紹
Shellshock,又稱Bashdoor,是在Unix中廣泛使用的Bash shell中的一個安全漏洞,首次於2014年9月24日公開。許多網際網路守護程序,如網頁伺服器,使用bash來處理某些命令,從而允許攻擊者在易受攻擊的Bash版本上執行任意程式碼。這可使攻擊者在未授權的情況下訪問計算機系統。