24
2025
04
20:56:04

记录一次与Linux病毒的斗争过程

记录一次与Linux病毒的斗争过程

记录一次与Linux病毒的斗争过程


症状

前阵子我的Centos7服务器(10.0.0.5)出问题了,表现如下:

使用下列命令查看当前运行着哪些进程

ps -elf

结果发现了几个奇怪的进程比如

.sshd
/tmp/gitlab


使用以下命令查看最近被修改过的文件,以及大小

[root@damogame dpkgd]# ls -alt /usr/bin | head -n 30
总用量 392772
dr-xr-xr-x.  5 root root       36864 12月 24 17:34 .
-rwxr-xr-x   1 root root     1223123 12月 24 17:20 ps
-rwxr-xr-x   1 root root     1223123 12月 24 17:20 netstat
-rwxr-xr-x   1 root root     1223123 12月 24 17:20 .sshd

[root@damogame dpkgd]# ls -alt /usr/sbin | head -n 30
总用量 221768
-rwxr-xr-x   1 root root     1223123 12月 24 17:20 ss
-rwxr-xr-x   1 root root     1223123 12月 24 17:20 lsof
dr-xr-xr-x.  2 root root       16384 12月 10 10:50 .
-rwxr-xr-x   1 root root       23680 12月  1 03:01 gss-server
-rwxr-xr-x   1 root root       11232 12月  1 03:01 sim_server
-rwxr-xr-x   1 root root       15328 12月  1 03:01 uuserver
-rwxr-xr-x   1 root root       40416 11月 16 23:21 kpartx
-rwxr-xr-x   1 root root       11368 11月  9 22:57 intel-microcode2ucode
-rwxr-xr-x   1 root root       40112 9月  21 21:29 eventlogadm
-rwxr-xr-x   1 root root      255048 9月  21 21:29 nmbd
-rwxr-xr-x   1 root root       94048 9月  21 21:29 smbd
-rwxr-xr-x   1 root root     1189728 9月  21 21:29 winbindd

发现ps, netstat, ss, lsof明显变大

这些文件正常大小只有100K,比如ps文件正常大小应该如下所示:

[root@damogame ~]# stat /bin/ps
  文件:"/bin/ps"
  大小:100112          块:200        IO 块:4096   普通文件
设备:fd00h/64768d      Inode:4600        硬链接:1
权限:(0755/-rwxr-xr-x)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2022-12-31 22:42:19.170302454 +0800
最近更改:2022-12-24 22:17:58.844450878 +0800
最近改动:2022-12-24 22:17:58.844450878 +0800
创建时间:-
[root@damogame ~]#


使用以下命令查看网络连接状况

netstat -lnptcp        0      0 10.0.0.5:40444          45.61.185.238:25000     ESTABLISHED 2388/gitlab         
tcp        0      1 10.0.0.5:37512          205.185.118.26:6001     SYN_SENT    2520/getty

结果发现有几个奇怪的连接连出去了,是gitlab进程,可是我并没有装gitlab

发现手工删除了gitlab文件,这个文件又自动出现了

所以确定机器肯定中病毒了


解决方法与步骤

现在的问题是linux系统文件被篡改,如何恢复?考虑到我的软路由是一个ESXi的虚拟机,那就在这个虚拟机上再装一个一模一样版本的Centos7,

先确认下版本,使用这个命令:

[root@damogame ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@damogame ~]# cat /proc/version
Linux version 3.10.0-1127.18.2.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Sun Jul 26 15:27:06 UTC 2020

发现是64位版本的Centos7.9.2009

下载安装,设定好ip地址(10.0.0.7)


使用scp文件把10.0.0.7上的对应文件覆盖到10.0.0.5上

scp -r root@10.0.0.7:/bin/ps /bin
scp -r root@10.0.0.7:/sbin/lsof /sbin
scp -r root@10.0.0.7:/sbin/netstat /sbin
scp -r root@10.0.0.7:/sbin/ss /sbin
scp -r root@10.0.0.7:/bin/ps /bin/dpkgd
scp -r root@10.0.0.7:/sbin/lsof /bin/dpkgd
scp -r root@10.0.0.7:/sbin/netstat /bin/dpkgd
scp -r root@10.0.0.7:/sbin/ss /bin/dpkgd

然后重启,竟然发现没用,还是被感染状态。

只好重新拷贝,然后把路由器断网,重启,好了


使用反病毒软件ClamAV,方法可以参考下这个链接

https://cloud.tencent.com/developer/article/2059604


查下来,发现之前安装的一个kms服务有病毒,已经把kms删了,反正也不需要

仔细想了下安装kms的确有些大意了,来源不是很干净,还开放了一个1688端口出去,这不是害人么?也算是给了自己一个教训。

观察到现在,再也没出现过问题,可以认为问题已经解决


额外的安全措施

1.确保root账户只能在本机登录,不能在远程登录。

2.有sudo权限的账户密码修改成复杂密码。

3.在服务器上定时跑secure脚本,尝试破解这台机器密码的ip会在失败10次之后进入黑名单(hosts.deny),以后它就永远也连不上来了,这个secue脚本的地址如下:

https://github.com/yongxin-ms/secure_ssh

4.修改以下配置文件为只读

[root@damogame ~]# chmod -w /etc/crontab
[root@damogame ~]# ll /etc/crontab
-r-------- 1 root root 810 2022-12-13 16:30 /etc/crontab[root@damogame ~]# chmod -w /etc/rc.d/rc.local
[root@damogame ~]# ll /etc/rc.d/rc.local
-r-x--x--x 1 root root 768 2022-12-25 19:23 /etc/rc.d/rc.local*

5.路由器上关闭不需要的端口映射,只开放一个最小范围。


总结

  • 这个病毒感染了ps, netstat等进程,每当你执行ps, netstat这种命令的时候都会感染一下你的机器,所以你需要在断网的状态下去恢复这些文件,这个很重要。

  • 中病毒了,一般的推荐是重装系统,但是我认为不能在没有搞明白是什么原因的情况下就简单的重装系统,这样可能会让问题重新出现。而且我这台机器重装系统的代价太高,所以最好还是找到病根。

  • 保持一个系统的备份还是有必要的,推荐用虚拟机

  • 多做一些额外的安全措施很有必要。




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://hqyman.cn/post/10863.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: