您的位置:首页 > 运维架构 > Linux

[系统管理] 当一台linux服务器入侵之后,排查系统故障及解决思路

2015-04-28 16:59 477 查看
大家都知道,互联网每时每刻都会存在攻击的可能性,(系统频繁发包,SYN攻击,等等)安全问题是系统管理员不可忽视的一个问题。当系统出现了问题,我们该如何下手,如何去排查系统问题呢?

正巧,今天公司一台线上的Linux系统出现了入侵的问题。(其实这已经困扰了我快一个月的问题了)(DDOS 系统频繁发包)我把我的处理思路分享给大家,如有哪一点说的不到位,请大家指出,并提出宝贵的意见,谢谢。勿喷。

由于是系统在内网发包,把我们的网络都堵塞了,以至于我不能远程登录到linux系统上,查看cacti流量图都查看不了。ping也全部丢包。这时去机房也不可能,所以,我只好等待发包不频繁的时机,趁此登录系统。功夫不负有心人,终于远程登录上系统了。

由于经历这样的问题不只一次,所以登录系统后,直接奔系统进程查看。查看结果如下:

# ps -ef (只显示可疑进程)
root 2013 1 0 10:01 ? 00:00:00 /boot/.IptabLex
root 5953 1 0 10:01 ? 00:00:00 /boot/.IptabLex
root 6035 1 0 10:01 ? 00:00:00 /boot/.IptabLes
root 24852 1 2 14:31 ? 00:04:29 /boot/.IptabLes
root 27322 1 3 15:08 ? 00:03:50 /boot/.IptabLes

由于程序还在发作,所以只保留唯一一个进程,剩下的进程全部kill掉,以便排查系统的根源在哪里

# kill -9 5953 6035 24852

查看打开的文件,及系统关联的文件都有哪些

# lsof -p 27322 ; lsof -p 2013
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
.IptabLes 27322 root cwd DIR 253,0 4096 2 /
.IptabLes 27322 root rtd DIR 253,0 4096 2 /
.IptabLes 27322 root txt REG 104,1 1103243 5905 /boot/.IptabLes
.IptabLes 27322 root 0u REG 253,0 5 98310 /.mylisthbS.pid
.IptabLes 27322 root 1u REG 253,0 5 98313 /.mylisthb.pid
.IptabLes 27322 root 2u sock 0,5 0t0 3442424 can't identify protocol
.IptabLes 27322 root 3u raw 0t0 3445564 00000000:00FF->00000000:0000 st=07
.IptabLes 27322 root 4u raw 0t0 3445565 00000000:00FF->00000000:0000 st=07
.IptabLes 27322 root 5u raw 0t0 3445566 00000000:00FF->00000000:0000 st=07
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
.IptabLex 2013 root cwd DIR 253,0 4096 2 /
.IptabLex 2013 root rtd DIR 253,0 4096 2 /
.IptabLex 2013 root txt REG 104,1 722580 5906 /boot/.IptabLex
.IptabLex 2013 root 0u REG 253,0 5 98309 /.mylisthbSx.pid
.IptabLex 2013 root 1uW REG 253,0 5 98311 /.mylisthbx.pid
.IptabLex 2013 root 2u IPv4 3479690 0t0 TCP 192.168.116.11:10038->59.63.167.168:1001 (ESTABLISHED)

经百度查看59.63.167.168的IP为江西省南昌市 电信

查看Cacti流量图。很遗憾,论坛现在上传图片上传不了。
显示的结果是 Output 300M 跑满了。

查看产生的可疑所有的文件。
# ll -a / (只显示可疑的文件)
-rw-r--r-- 1 root root 5 Jan 12 17:15 .mylisthb.pid
-rw-r--r-- 1 root root 5 Jan 12 10:01 .mylisthbS.pid
-rw-r--r-- 1 root root 5 Jan 12 10:01 .mylisthbSx.pid
-rw-r--r-- 1 root root 5 Jan 12 16:57 .mylisthbx.pid

查看/boot/分区下
# ll -a /boot/
-rw-r--r-- 1 root root 5 Jan 12 10:01 .IptabLes
-rw-r--r-- 1 root root 5 Jan 12 10:01 .IptabLex
-rw-r--r-- 1 root root 5 Jan 12 10:01 IptabLes -> /etc/rc.d/init.d/IptabLes
-rw-r--r-- 1 root root 5 Jan 12 10:01 IptabLex -> /etc/rc.d/init.d/IptabLex

查看/etc/rc.d/init.d/IptabLex和/etc/rc.d/init.d/IptabLes文件内容
# cat /etc/rc.d/init.d/IptabLex
#!/bin/sh
/boot/.IptabLex
exit 0
# cat /etc/rc.d/init.d/IptabLes
#!/bin/sh
/boot/.IptabLes
exit 0
查看两个文件的文件类型,可知是32位的可执行文件
# file /boot/.IptabLex
.IptabLex: sticky ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, not stripped
# file /boot/.IptabLes
.IptabLes: sticky ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, not stripped
查看message信息
# cat /var/log/message
Jan 12 11:36:24 localhost kernel: .IptabLes[12688]: segfault at 0000000000000000 rip 000000000804e837 rsp 00000000ffeb1fb0 error 4
Jan 12 11:36:39 localhost kernel: .IptabLes[12706]: segfault at 0000000000000000 rip 000000000804e837 rsp 00000000ffeb1fb0 error 4
Jan 12 11:36:54 localhost kernel: .IptabLes[12723]: segfault at 0000000000000000 rip 000000000804e837 rsp 00000000ffeb1fb0 error 4
Jan 12 11:37:10 localhost kernel: .IptabLes[12739]: segfault at 0000000000000000 rip 000000000804e837 rsp 00000000ffeb1fb0 error 4
Jan 12 11:37:46 localhost kernel: .IptabLes[12756]: segfault at 0000000000000000 rip 000000000804e837 rsp 00000000ffeb1fb0 error 4

处理方法,删除关联的文件
# rm -f /.mylisthb* 产生的pid文件
# rm -f /boot/.IptabLex
# rm -f /boot/..IptabLes 编译后的二进制文件
# rm -f /etc/rc.d/init.d/IptabLex
# rm -f /etc/rc.d/init.d/IptabLes

因为这个文件发包基于什么协议,或者基于什么系统命令发包尚未清楚,所以在iptables这无法断定基于什么协议或者基于什么端口进行限制。待大家给一些宝贵的意见。

评论:
(1)是Tomcat自身出的问题, Tomcat6和7都有这样的问题。大家不用升级了。
我现在的处理办法是写脚本在后台监控执行的。
脚本如下:
# cat /home/jason/script/monitorIp.sh
#!/bin/bash
# Author : Jason
# Moniting IptabLex And IptabLes Process
while :
do
num=`ps -ef | grep IptabLe | wc -l`
if [ $num -gt 0 ] ; then
pid=`ps -ef | grep IptabLe | awk '{print $2}'`
kill -9 $pid
echo "`date +%F_%H:%M` IptabLe* kill" >> /var/log/IptabLexkill.log
fi
sleep 5
done
执行:
# nohup /home/jason/script/monitorIp.sh &
# echo "nohup /home/jason/script/monitorIp.sh &" >> /etc/rc.local
你们先暂时防止一下吧。大家一起想想办法。随时关注下自己的服务器。
顺便写一下iptables规则。
(2)
是Struts2漏洞导致服务器遭受IptabLex,IptabLes入侵,请及时更新补厅
Apache团队紧急发布了Struts 2.3.15.1安全更新版本,可升级到此版本来解决上述问题。
(3)
解决struts2最新s2-016代码执行漏洞–CVE-2013-2251
今天接到外界报告struts2框架存在任意命令执行漏洞,可直接执行任意系统命令。 详细见官方说明:http://struts.apache.org/release/2.3.x/docs/s2-016.html
漏洞版本:
Apache Struts 2.0.0 – Apache Struts 2.3.15
漏洞描述:
CVE-2013-225. Struts2 是第二代基于Model-View-Controller (MVC)模型的java企业级web应用框架。它是WebWork和Struts社区合并后的产物;
Apache Struts2的action:、redirect:和redirectAction:前缀参数在实现其功能的过程中使用了Ognl表达式,并将用户通过URL提交的内容拼接入Ognl表达式中,从而造成攻击者可以通过构造恶意URL来执行任意Java代码,进而可执行任意命令;
redirect:和redirectAction:此两项前缀为Struts默认开启功能,目前Struts 2.3.15.1以下版本均存在此漏洞
目前Apache Struts2已经在2.3.15.1中修补了这一漏洞。强烈建议Apache Struts2用户检查您是否受此问题影响,并尽快升级到最新版本
< 参考 1. http://struts.apache.org/release/2.3.x/docs/s2-016.html >
测试方法:
@Sebug.net dis 本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

由于Apache Struts2 在最新修补版本2.3.15.1中已经禁用了重定向参数,因此只要重定向功能仍然有效,则说明受此漏洞影响: http://host/struts2-showcase/employee/save.action?redirect: href="http://www.yahoo.com/" target=_blank>http://www.yahoo.com/
如果页面重定向到www.yahoo.com,则表明当前系统受此漏洞影响。
验证表达式解析和命令执行: http://host/struts2-showcase/employee/save.action?redirect:%25{3*4}
http://host/struts2-showcase/employee/save.action?redirect:%25{(new+java.lang.ProcessBuilder(new+java.lang.String[]{'command','goes','here'})).start()}`

Sebug安全建议:
厂商状态:
厂商已经发布Apache Struts 2.3.15.1以修复此安全漏洞,建议Struts用户及时升级到最新版本。
厂商安全公告:S2-01. 链接:http://struts.apache.org/release/2.3.x/docs/s2-016.html
软件升级页面:http://struts.apache.org/download.cgi#struts23151
目前存在漏洞的公司
乌云上,已经发布了快60个struts的这个漏洞问题,包括腾讯,百度,网易,京东等国内各大互联网公司。(http://www.wooyun.org/bugs/new_submit/
(4)
漏洞害死人啊,为了这个问题,我系统都重安装了,才发现是程序漏洞!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: