实时警报通知:微信告警通知的重要性解析
764
2023-03-18
一次ssh被植入后门的经历及解决方案
昨天发现服务器上面很多程序被挂马了,跟开发一起处理了挂马文件,今早发现游戏后台又打不开了,上服务器发现后台程序的入口文件都被删了,恢复了index.php、admin.php后才能正常访问,晚上谁也没上过服务器,可以判定服务器已经被入侵了,开始排查:
1.首先查看安全日志,指定命令如下:
代码:more /var/log/secure |grep Accepted
代码:more /var/log/secure |grep Accepted
通过对命令输出的查看,下面几条记录令人怀疑:
代码: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
代码: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.开始查看历史命令,发现了问题:
通过上面的历史记录可以发现攻击者在服务器上安装了ssh后门,关于ssh后门的文章我也查询了几篇,感兴趣的朋友可以看看:
按照上面文章中说的,攻击者已经修改了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再次查看版本是否正确
开发同事也帮忙查找代码中的木马,使用脚本如下:
发表评论
暂时没有评论,来抢沙发吧~