[root@localhost ~]# top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26559 root 20 0 2441716 4524 2384 S 199.7 0.1 726:50.68 xmrig
[root@localhost ~]# ps -ef | grep xmrig
root 26559 1 99 01:34 ? 12:17:49 /root/xmrig-6.21.1/xmrig --donate-level 1 -o 3.0.103.157:3333 --rig-id woker-pool-3 -o 43.128.29.152:3333 --rig-id woker-pool-4
[root@localhost .ssh]# pstree -up
(略
├─sshd(1217)───sshd(27978)───bash(27997)───pstree(29086)
├─sysetmd(819)───{sysetmd}(836)
├─systemd-journal(505)
├─systemd-logind(829)
├─systemd-udevd(531)
└─xmrig(26559)─┬─{xmrig}(26560)
├─{xmrig}(26561)
├─{xmrig}(26562)
├─{xmrig}(26563)
├─{xmrig}(26564)
├─{xmrig}(26842)
├─{xmrig}(26843)
├─{xmrig}(26844)
└─{xmrig}(26845)
[root@localhost .ssh]# ls -l /proc/26559
lrwxrwxrwx 1 root root 0 3月 19 01:34 exe -> /root/xmrig-6.21.1/xmrig
(略
[root@localhost ~]#
find / -name xmrig
rm -rf /root/xmrig*
kill -9 26559
病毒文件在前一天晚上10点57生成,cpu在前一天晚上11点57异常升高
使用pstree -up
命令,对比正常的服务器找出了4个多余进程 逐个检查后发现有2个进程异常
sysetmd:[root@localhost ~]# systemctl status 813
● sysetmd.service - sysetmd service
Loaded: loaded (/etc/systemd/system/sysetmd.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2024-03-20 23:05:52 CST; 6 days ago
Main PID: 813 (sysetmd)
CGroup: /system.slice/sysetmd.service
└─813 /opt/sysetmd 8765 481.081.651.421
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: < ok
3月 27 15:22:32 localhost sysetmd[813]: once
[root@localhost ~]# systemctl status 818
● A_li_yun_Duns.service - AliyunDuns service node
Loaded: loaded (/etc/systemd/system/A_li_yun_Duns.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2024-03-20 23:05:52 CST; 6 days ago
Main PID: 818 (A_li_yun_Duns)
CGroup: /system.slice/A_li_yun_Duns.service
└─818 /opt/A_li_yun_Duns &
3月 20 23:05:52 localhost systemd[1]: Started AliyunDuns service node.
有修改的opt正是存放异常进程执行文件的文件夹
还有一堆病毒文件
[root@localhost ~]# cd /
[root@localhost /]# ls -lt | head -n 30
总用量 184
drwxrwxrwt. 11 root root 4096 3月 27 15:34 tmp
drwxr-xr-x 23 root root 660 3月 27 15:26 run
drwxr-xr-x. 78 root root 4096 3月 27 15:26 etc
dr-xr-xr-x 13 root root 0 3月 27 13:49 sys
-rwxrwxrwx 1 root root 25871 3月 27 13:30 tcp
-rwxrwxrwx 1 root root 30191 3月 27 13:30 udp
-rwxrwxrwx 1 root root 27079 3月 27 13:23 OVH-NFO-CLOUDFLARE
-rw-r--r-- 1 root root 9315 3月 27 12:53 OVH-VIP.c
-rw-r--r-- 1 root root 9875 3月 27 09:11 tcp_syn.c
drwxr-xr-x 19 root root 2980 3月 22 10:09 dev
dr-xr-x---. 11 root root 4096 3月 21 16:55 root
-rw-r--r-- 1 root root 98 3月 20 23:05 libhv.20240320.log
dr-xr-xr-x 122 root root 0 3月 20 23:05 proc
drwxr-xr-x. 20 root root 4096 3月 20 17:19 var
lrwxrwxrwx 1 root root 8 3月 18 21:35 sbin -> usr/sbin
lrwxrwxrwx 1 root root 10 3月 18 21:35 lib64 -> usr/lib64/
lrwxrwxrwx 1 root root 7 3月 18 21:35 lib -> usr/lib
lrwxrwxrwx 1 root root 8 3月 18 21:35 bin -> usr/bin/
drwxr-xr-x. 2 root root 4096 3月 17 12:27 opt
/bin/bash 允许用户登录并执行命令,而 /sbin/nologin 阻止了用户登录
根据对比有数条新用户 nologin先忽略
禁用passwd -l 用户名
解锁passwd -u 用户名
删除userdel 用户名
[root@localhost run]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
(略
tcpdump:x:72:72::/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nginx:x:997:995:Nginx web server:/var/lib/nginx:/sbin/nologin
x99:x:0:0::/root:/bin/bash
[root@localhost run]# passwd -l x99
锁定用户 x99 的密码 。
passwd: 操作成功
//删除失败 查看原因
[root@localhost /]# userdel x99
userdel: user x99 is currently used by process 1
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 43412 3840 ? Ss 13:53 0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
[root@localhost ~]# ls -l /proc/1
lrwxrwxrwx 1 root root 0 3月 27 15:26 exe -> /usr/lib/systemd/systemd
//显示系统进程瞬间的运行状态
[root@localhost ~]# ps -u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 986 0.0 0.0 110108 648 tty1 Ss+ 13:51 0:00 /sbin/agetty --noclear tty1 linux
root 987 0.0 0.0 110108 644 ttyS0 Ss+ 13:51 0:00 /sbin/agetty --keep-baud 115200,38400,9600 ttyS0 vt220
root 4922 0.0 0.1 115528 2156 pts/0 Ss 15:02 0:00 -bash
root 11232 0.0 0.1 126452 2124 pts/0 S+ 17:09 0:00 vi /etc/passwd
root 11372 0.0 0.1 115448 2056 pts/1 Ss 17:11 0:00 -bash
root 11625 0.0 0.0 155372 1876 pts/1 R+ 17:16 0:00 ps -u
//强制删除
[root@localhost ~]# chattr -i /etc/passwd
[root@localhost ~]# chattr -i /etc/shadow
[root@localhost ~]# userdel -f x99
userdel: user x99 is currently used by process 1
[root@localhost ~]# kill -9 1
[root@localhost ~]# userdel -f x99
userdel:用户“x99”不存在
[root@localhost run]# last -a -w
root pts/2 Wed Mar 27 15:03 still logged in 具体IP
root pts/0 Wed Mar 27 14:22 - 14:23 (00:00) 具体IP
root pts/0 Wed Mar 27 13:56 - 14:21 (00:25) 具体IP
reboot system boot Wed Mar 27 13:53 - 16:25 (02:31) 3.10.0-1160.83.1.el7.x86_64
root pts/0 Wed Mar 20 23:09 - 01:02 (01:52) 具体IP
reboot system boot Wed Mar 20 23:07 - 16:25 (6+17:17) 3.10.0-1160.83.1.el7.x86_64
chmod 700 /usr/sbin/crond
chmod 700 /usr/bin/yum
chmod 700 /usr/bin/wget
chmod 700 /usr/bin/curl
chmod 700 /usr/bin/ping
无痕迹
[root@localhost cron]# crontab -l
no crontab for root
[root@localhost ~]# cd /var/spool/cron
[root@localhost cron]# ls -al
总用量 8
drwx------. 2 root root 4096 8月 9 2019 .
drwxr-xr-x. 9 root root 4096 4月 26 2020 ..
没有痕迹
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ls -al
总用量 8
drwx------ 2 root root 4096 3月 18 14:47 .
dr-xr-x---. 8 root root 4096 3月 19 15:57 ..
新增SSH端口——>重启sshd服务——>添加防火墙规则——>尝试新端口登陆——>关闭原先的22端口——>增加ip白名单
新增SSH端口
vim /etc/ssh/sshd_config
找到Port 22这行,将前面的注释去掉,再加一行Port 45,防止新端口登陆不上,老端口也不能用
重启sshd服务
systemctl restart sshd
查看端口是否生效
systemctl status sshd
去阿里云安全组设置里同步开放45端口
使用新端口号登陆成功
ssh -p 45 root@IP
重复步骤关闭端口22 并前往阿里云同步删除22
控制台会自动断开之前使用端口22产生的连接
[root@localhost ~]# packet_write_wait: Connection to 具体IP port 22: Broken pipe
//进去打开22端口并增加45端口
[root@localhost ~]# vim /etc/ssh/sshd_config
[root@localhost ~]# systemctl restart sshd
[root@localhost ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2024-03-19 12:59:00 CST; 21s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 21931 (sshd)
CGroup: /system.slice/sshd.service
└─21931 /usr/sbin/sshd -D
3月 19 12:59:00 localhost systemd[1]: Stopped OpenSSH server daemon.
3月 19 12:59:00 localhost systemd[1]: Starting OpenSSH server daemon...
3月 19 12:59:00 localhost sshd[21931]: Server listening on 0.0.0.0 port 45.
3月 19 12:59:00 localhost sshd[21931]: Server listening on 0.0.0.0 port 22.
3月 19 12:59:00 localhost systemd[1]: Started OpenSSH server daemon.
//进去注释22端口
[root@localhost ~]# vim /etc/ssh/sshd_config
[root@localhost ~]# systemctl restart sshd
[root@localhost ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since 二 2024-03-19 15:57:50 CST; 4s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 30780 (sshd)
CGroup: /system.slice/sshd.service
└─30780 /usr/sbin/sshd -D
3月 19 15:57:50 localhost systemd[1]: Starting OpenSSH server daemon...
3月 19 15:57:50 localhost sshd[30780]: Server listening on 0.0.0.0 port 45.
3月 19 15:57:50 localhost systemd[1]: Started OpenSSH server daemon.
修改ecs实例中root账户的密码不生效
lsattr /etc/passwd /etc/shadow
chattr -i /etc/shadow
chattr -i /etc/passwd
重启实例后重启各项服务
//开启tomcat、nacos、py.ini、nginx 关闭firewall 启动iptables
[root@localhost ~]# cd nacos/bin
[root@localhost bin]# sh startup.sh -m standalone
[root@localhost ~]# find -name uwsgi.ini
./www/System/uwsgi.ini
[root@localhost ~]# cd ./www/System
[root@localhost System]# uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
[root@localhost sbin]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz
[root@localhost System]# cd /usr/sbin/
[root@localhost sbin]# ./nginx
[root@localhost sbin]# systemctl stop firewalld.service
[root@localhost sbin]# systemctl disable firewalld
[root@localhost sbin]# service iptables restart
阿里云操作 删除一些不必要的开放端口
删除:自定义 TCP 目的:3389/3389 源:0.0.0.0/0
chmod 700 /usr/sbin/crond
chmod 700 /usr/bin/yum
chmod 700 /usr/bin/wget
chmod 700 /usr/bin/curl
chmod 700 /usr/bin/ping
https://www.yuanxue365.com/wakuang_967930
https://blog.csdn.net/dabao87/article/details/81302991