1.1 实验环境
序号 | 主机IP | 主机系统 | 主机角色 |
1 | 192.168.10.180 | Kali | 攻击机 |
2 | 192.168.10.80 | Centos 7.9 64位 | 被攻击机 |
1.2 模拟木马程序自动运行
1.2.1 木马自动运行方法
- 计划任务:crontab
- 开机启动
- 系统命令被人替换,定一个触发事件
1.2.2 编写木马模拟程序
[root@test ~]# vim /usr/bin/muma #!/bin/bash touch /tmp/date.txt while true do echo `date` >> /tmp/date.txt sleep 1 done [root@test ~]# chmod +x /usr/bin/muma
1.2.3 让木马无法被root删除
[root@test ~]# chattr +i /usr/bin/muma [root@test ~]# rm -f /usr/bin/muma rm: cannot remove ‘/usr/bin/muma’: Operation not permitted [root@test ~]# lsattr /usr/bin/muma ----i----------- /usr/bin/muma [root@test ~]# lsattr /usr/bin/muma
1.3 定时任务运行木马方式排查
1.3.1 创建定时任务
1.3.1.1 crontab命令创建定时任务
【root用户定时任务】:
[root@test ~]# crontab -e 1 2 * * * /usr/bin/muma &
【普通用户定时任务】:
[root@test ~]# crontab -u bin -e 1 2 * * * /usr/bin/muma &
1.3.1.2 常见系统级别定时任务
【方式一】:
[root@test ~]# echo "1 2 * * * root /usr/bin/muma &" >> /etc/crontab
【方式二】:
[root@test ~]# vim /etc/cron.daily/logrotate 1 #!/bin/sh 2 3 /usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf 4 EXITVALUE=$? 5 if [ $EXITVALUE != 0 ]; then 6 /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" 7 fi 8 /usr/bin/muma & 9 exit 0
1.3.2 定时任务排查
1.3.2.1 查看crontab命令生成的定时任务
所有用户的计划任务都会在/var/spool/cron/下产生对应的文件,只要看一下这个目录下的文件,就知道哪些用户生成了计划任务:
[root@test ~]# ll -h /var/spool/cron/ total 8.0K -rw------- 1 root root 26 Jul 27 11:01 bin -rw------- 1 root root 26 Jul 27 10:56 root
1.3.2.2 查看系统级别的计划任务
[root@test ~]# ll -h /etc/cron cron.d/ cron.daily/ cron.deny cron.hourly/ cron.monthly/ crontab cron.weekly/
【目录分析】:
- crontab:写具体时间的系统级别的定时任务
- d/:系统级别的定时任务
- daily/:系统每天要执行的计划任务
- hourly/:系统每小时要执行的计划任务
- monthly/:系统每月要执行的计划任务
- weekly/:系统每周要执行的计划任务
1.4 开机启动运行木马方式排查
1.4.1 创建开机启动任务
1.4.1.1 追加到开机启动脚本中
echo "/usr/bin/muma" >> /etc/rc.local
1.4.1.2 追加到开机启动服务的启动脚本中
[root@test ~]# vim /etc/init.d/network 17 . /etc/init.d/functions 18 /usr/bin/muma 19 if [ ! -f /etc/sysconfig/network ]; then
1.4.1.3 自己编写开机启动服务脚本
[root@test ~]# vim /etc/init.d/muma #!/bin/sh # chkconfig: 12345 90 90 # description: muma ### END INIT INFO case $1 in start) /usr/bin/muma & ;; stop) ;; *) /usr/bin/muma & ;; esac [root@test ~]# chmod +x /etc/init.d/muma [root@test ~]# chkconfig --add muma [root@test ~]# service muma start
1.4.2 开机启动排查
1.4.2.1 开机启动脚本排查
注意:很多人vim打开一个文件看到文档的后面是一片空白就认为达到文件的最后了,所以黑客在/etc/rc.local中添加很多空行,然后在文档最后添加木马程序也可以躲避一些运维人员的视线,达到隐藏木马的目的。
[root@test ~]# egrep -v "^$|#" /etc/rc.local # 使用egrep过滤空行防止上述问题发生 touch /var/lock/subsys/local /usr/bin/muma
1.4.2.2 自己编写开机脚本排查
【查看木马启动脚本】:
[root@test ~]# ll /etc/rc*/* | grep muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc0.d/K90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc1.d/S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc2.d/S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc3.d/S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc4.d/S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc5.d/S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 /etc/rc6.d/K90muma -> ../init.d/muma -rwxr-xr-x 1 root root 156 Jul 27 15:07 muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 K90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 S90muma -> ../init.d/muma lrwxrwxrwx 1 root root 14 Jul 27 15:11 K90muma -> ../init.d/muma
【删除木马启动脚本】:
[root@test ~]# chkconfig --del muma [root@test ~]# rm -rf /etc/init.d/muma
1.5 排查命令被修改
1.5.1 检查单个命令是否被修改
1.5.1.1 未被修改情况
[root@test bin]# rpm -Vf /usr/bin/w
1.5.1.2 被修改情况
[root@test bin]# echo aaaa >> /usr/bin/w [root@test bin]# rpm -Vf /usr/bin/w S.5....T. /usr/bin/w
rpm -V 弹出的每列消息含义如下:
- S:文件大小不一致
- M:模式不一致(包括许可和文件类型)
- 5:MD5 sum校验和不一致
- D:Device主从设备号不匹配
- L:readLink(2)路径不匹配
- U:User属主不一致
- G:Group所属组不一致
- T:mTime修改时间不一致
1.5.2 检查所有rpm安装的命令是否别修改
[root@test ~]# rpm -Va > /tmp/rpm_check.txt [root@test ~]# cat /tmp/rpm_check.txt S.5....T. /usr/bin/w S.5....T. c /etc/ssh/sshd_config SM5....T. c /etc/rc.d/rc.local S.5....T. /etc/rc.d/init.d/network S.5....T. c /etc/crontab ....L.... c /etc/pam.d/fingerprint-auth ....L.... c /etc/pam.d/password-auth ....L.... c /etc/pam.d/postlogin ....L.... c /etc/pam.d/smartcard-auth ....L.... c /etc/pam.d/system-auth S.5....T. c /etc/security/limits.conf S.5....T. c /etc/my.cnf S.5....T. c /etc/chrony.conf S.5....T. c /etc/php.ini S.5....T. c /etc/httpd/conf/httpd.conf .....UG.. /var/www/html S.5....T. c /etc/issue S.5....T. c /etc/issue.net S.5....T. c /etc/yum.repos.d/CentOS-Base.repo missing /var/run/abrt S.5....T. c /etc/sysconfig/authconfig .......T. c /etc/cron.daily/logrotate
1.6 排查木马方法总结
- 对比其他服务器完好的配置文件,利用MD5值做对比
- 利用find命令查找下最近被修改过的文件,一般情况下命令文件都很久之前被修改的:
[root@test ~]# find /etc/init.d/ -mtime -1 /etc/init.d/ /etc/init.d/network
- 被入侵后检测所有rpm -Va生成的文件是否被改动过
温馨提示:本文最后更新于
转载请注明本文链接:https://blog.leonshadow.cn/763482/2862.html
2022-12-20 20:57:33
,已超过345
天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!转载请注明本文链接:https://blog.leonshadow.cn/763482/2862.html
© 版权声明
THE END