阿里云服务器被挖矿

背景

部署在服务器上的项目很卡很卡,相应很慢或者无响应了;

去看cpu占用情况,发现有个未知程序占用满了;

top命令


  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                                             
    1 root      20   0   43376   3720   2552 S  99.9  0.2   0:00.62 [kswapd0]                                                                                          
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd                                                                                            
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.01 ksoftirqd/0                                                                                         
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H                                                                                        
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kworker/u4:0                                                                                        
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0                                                                                         
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh                                                                                              
    9 root      20   0       0      0      0 S  0.0  0.0   0:00.15 rcu_sched                                                                                           
   10 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 lru-add-drain                                                                                       
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs                                                                                           
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns                                                                                               
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 khungtaskd                                                                                          
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback                                                                                           
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd                                                                                         
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                                                                                              
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                                                                                              
   20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                                                                                              
   21 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd                                                                                             
   22 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md                                                                                                  
   23 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 edac-poller 

​ 直接使用 kill -9 无法直接停止掉,因为一般挖矿木马都会自动启动、或者定时器

查询挖矿程序所在的文件路径

ps aux|grep [kswapd0]

root       841  0.0  0.9 573920 17068 ?        Ssl  10:43   0:00 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root       844  0.0  0.2 598632  4312 ?        Ssl  10:43   0:00 /usr/sbin/rsyslogd -n
root       856  0.0  0.0  10728   688 ?        S    10:43   0:00 bioset
root       864  0.0  0.0 110104   872 ttyS0    Ss+  10:43   0:00 /sbin/agetty --keep-baud 115200,38400,9600 ttyS0 vt220
root       865  0.0  0.0 110104   860 tty1     Ss+  10:43   0:00 /sbin/agetty --noclear tty1 linux
root       951  0.0  0.2 112864  4304 ?        Ss   10:43   0:00 /usr/sbin/sshd -D
root       967  0.0  0.3 157260  5892 ?        Ss   10:43   0:00 sshd: root@pts/0
root       981  0.0  0.1 115440  1992 pts/0    Ss   10:43   0:00 -bash
root      1006  0.0  0.1 161884  2196 pts/0    S+   10:43   0:00 top
root      1008  0.0  0.3 157260  5892 ?        Ss   10:44   0:00 sshd: root@pts/1
root      1010  0.0  0.1 115440  1996 pts/1    Ss   10:44   0:00 -bash
root      1072  0.0  0.2  39084  5260 ?        Ss   10:45   0:00 /usr/lib/systemd/systemd-journald
root      1076 99.7  0.1 537728  2744 ?        SNsl 10:45  11:43 /var/tmp/.copydie/[kswapd0] --config=/var/tmp/.copydie/[kswapd0].pid
root      1088  0.0  0.1 191768  2368 pts/1    S    10:51   0:00 su root
root      1089  0.0  0.1 115440  2040 pts/1    S    10:51   0:00 bash
root      1101  0.0  0.0 155360  1880 pts/1    R+   10:57   0:00 ps aux

找到查询结果中包含 [kswapd0]的文件

cd /var/tmp/.copydie

直接根据目录

rm -r [kswapd0]

rm -r [kswapd0].sh

rm -r [kswapd0].pid

问题分析

查了好多同样情况的,看了很多大佬说可能是redis服务端口开放的原因,大部分木马都是通过redis漏洞进入的;

推荐:

1.服务器的远程访问用户密码设置的高级一点;

2.redis连接密码也设置的高级一点;

3.常用端口记得修改;比如远程ssh登录的22端口,改为其他、redis的默认端口、不用的端口统统关闭;

ssh登录端口修改

阿里云的ssh配置端口一般在 /etc/ssh/sshd_config 文件中

#Port 22     -- 原代码,默认注释掉的,默认22
Port 8888    -- 新增一行,ssh登录端口改为8888

如上操作;

后重启ssh服务 /etc/init.d/sshd restart

或者直接重启服务器;

阿里云端口关闭

阿里云服务器 --> 云服务器 --> 网络与安全 --> 安全组 --> 配置规则 --> 授权策略 --> 不需要的全都拒绝:留一个远程登录服务器的不常用的端口,如8888;

posted @ 2022-01-19 11:55  窃窃私语QAQ  阅读(284)  评论(0编辑  收藏  举报