模拟木马程序病原体并让木马程序自动运行

模拟黑客修改系统命令,制作病原体,并将病原体脚本放入定时任务、开机自启

生成木马程序病原体

[root@fp-21 ~]# vim /usr/bin/tom 			# /usr/bin目录下
#!/bin/bash 	

touch /tmp/aaa.txt
while :
do
        echo `date` >> /tmp/date.txt	# 输出时间
        sleep 1		# 睡眠1秒钟,继续执行
done

简单的一个无限循环的脚本,不停的向文本中输入信息,当加上执行权限,在放在后台执行的话,不出一会就会 CPU 飙高

[root@fp-21 ~]# vim /usr/bin/tom
[root@fp-21 ~]# chmod +x !$
chmod +x /usr/bin/tom
[root@fp-21 ~]# tom &
[2] 66532

注:! $ 表示代表上一个命令以空格为分隔符的最后一个字段

​ & 表示后台执行

​ [2] 表示第二个后台执行的进程

​ 66532 进程号

使用计划任务crontab让木马自动运行

将我们刚写好的病毒体脚本写入 crontab 中,这样的话,就是发现了病毒体进城后,将它结束,过段时间,它还是会执行

[root@fp-21 ~]# crontab -e
* 2 * * *  /usr/bin/tom &

所以,我们可以时用 crontab -l 来查看定时任务

[root@fp-21 ~]# crontab -l
* 2 * * *  /usr/bin/tom &

但是也有比较聪明的黑客,他不在 root 的定时任务中写,他在某一个的定时任务中写,这样的话用 crontab -l 便查看不到

[root@fp-21 ~]# crontab -u bin -e
* 3 * * *  /usr/bin/tom &
[root@fp-21 ~]# crontab -l
no crontab for root

所以此时我们需要查看当前有计划任务的所有用户

[root@fp-21 ~]# ll /var/spool/cron/
total 4
-rw-------. 1 root root 47 Feb 11 22:20 bin

所以看到有不是我们自己创建的定时任务的用户,删除即可

扫描二维码关注公众号,回复: 9128677 查看本文章

在这里,还要跟大家介绍一个目录:系统级别的定时任务

[root@fp-21 ~]# ll /etc/ |grep cron
-rw-------.  1 root root    541 Aug  9  2019 anacrontab
drwxr-xr-x.  2 root root     36 Feb 11 21:57 cron.d
drwxr-xr-x.  2 root root     42 Feb 11 22:31 cron.daily
-rw-------.  1 root root      0 Aug  9  2019 cron.deny
drwxr-xr-x.  2 root root     22 Feb 11 21:57 cron.hourly
drwxr-xr-x.  2 root root      6 Jun 10  2014 cron.monthly
-rw-r--r--.  1 root root    451 Jun 10  2014 crontab
drwxr-xr-x.  2 root root      6 Jun 10  2014 cron.weekly
  • crontab #写具体时间的统级别的定时任务
  • cron.d/ #系统级别的定时任务
  • cron.daily/ #系统每天要执行计划任务
  • cron.hourly/ #系统每小时要执行计划任务
  • cron.monthly/ #系统每月要执行计划任务
  • cron.weekly/ #系统每周要执行计划任务

通过开机启动脚本运行木马

开机启动的脚本:/etc/rc.local

[root@fp-21 ~]# vim /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

黑客如果往脚本中添加许多空行,并在最后添加木马程序,再把光标移动到首行,而我们运维人员如果在检查的时候不够仔细,很容易就会跳过,认为文件很安全,没有被修改,此时我们可以使用去除空行的命令来检查文件

[root@fp-21 ~]# grep -v ^$ /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
echo "危险!!!"

通过去除空行,我们可以看到最后一行不是文件的,我们需要将其删除

排查方法总结

提前准备一个各文件都正常的服务器,做一个系统所有文件的MD5值得统计

再将需要检查的文件做一个MD5值得统计

两个文件做对比

[root@Fp-01 test]# md5sum /etc/rc.d/init.d/* > file.v1
[root@Fp-01 test]# vim /etc/rc.d/init.d/sshd 
……
echo "我是病毒体!"
[root@Fp-01 test]# md5sum /etc/rc.d/init.d/* > file.v2
[root@Fp-01 test]# diff file.v1 file.v2
43c43
< 3186224272e10496a2849d01c37a61ff  /etc/rc.d/init.d/sshd
---
> 7b3f4bc470efc06e1440a5f263079706  /etc/rc.d/init.d/sshd

此时,便可以清晰得看出,哪个文件被修改了

使用 rpm检查文件的完整性

安装一个apache的软件包做测试

[root@Fp-01 ~]# yum -y install httpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Determining fastest mirrors
……

在apache软件包中添加病毒体,并使用命令判断检查

[root@Fp-01 ~]# echo "我是病毒体!" > /usr/sbin/httpd
[root@Fp-01 ~]# rpm -V httpd
S.5....T.    /usr/sbin/httpd

rpm -V弹出的每列消息含意如下:

  • S file Size 大小不一致
  • MMode 模式不一致 (包括许可和文件类型)
  • 5 MD5 sum 校验和不一致
  • DDevice 主从设备号不匹配
  • L readLink(2) 路径不匹配
  • UUser 属主不一致
  • GGroup 所属组不一致
  • T mTime 修改时间不一致

系统命令被人替换

这里以最常用的 ls 命令为测试

[root@Fp-01 ~]# which ls
/bin/ls
[root@Fp-01 ~]# cp /bin/ls /bin/ls.bak
[root@Fp-01 ~]# vim /bin/ls
echo "wo shi bing du ti"
[root@Fp-01 ~]# ll ./
wo shi bing du ti

系统命令被植入病毒,想想都很可怕,一使用命令,就可能啥都没了

只有注入思想的博客才是好的博客

发布了10 篇原创文章 · 获赞 13 · 访问量 1517

猜你喜欢

转载自blog.csdn.net/xtlhxl/article/details/104281558