【Linux应急响应—上 】一文解明Linux应急响应(hw蓝队兄弟看这里):开机 ...

打印 上一主题 下一主题

主题 982|帖子 982|积分 2946

紧张声明

文中技术只可用于安全技术研究,任何非法用途与作者无关,请勿用在生产情况安装测试rootkit。
处置惩罚手段
发现问题要处置惩罚,遵循原则: 百分百确认黑白法文件,报备记载关停,摸棱两可找负责人确认,处置惩罚看沟通结果。
linux应急响应

开机启动项排查

陪同开机启动,一般生产服务器很少重启,但是为防止被控呆板失联部门木马会添加开机启动项作为复活手段。
/etc/rc.local

  1. #!/bin/sh -e
  2. #
  3. # rc.local
  4. #
  5. # This script is executed at the end of each multiuser runlevel.
  6. # Ensure that the script will "exit 0" on success or any other
  7. # value on error.
  8. #
  9. # To enable or disable this script, just change the execution
  10. # bits.
  11. #
  12. # By default, this script does nothing.
  13. # 下方为开机启动列表
  14. touch /root/1.txt
复制代码
/etc/rc.d/rc.local

  1. #!/bin/bash
  2. # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
  3. #
  4. # It is highly advisable to create own systemd services or udev rules
  5. # to run scripts during boot instead of using this file.
  6. #
  7. # In contrast to previous versions due to parallel execution during boot
  8. # this script will NOT be run after all other services.
  9. #
  10. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
  11. # that this script will be executed during boot.
  12. touch /var/lock/subsys/local
  13. touch /tmp/1.txt
复制代码
/etc/rc.d/init.d/

该目次下放了可执行脚本或者文件。
/etc/rc*.d/

  1. rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/ rcS.d/
复制代码
systemctl list-unit-files

重要关注enabld历程。
  1. ...
  2. ssh.service enabled enabled
  3. ssh@.service static enabled
  4. sshd.service enabled enabled
  5. sudo.service masked enabled
  6. syslog.service enabled enabled
  7. system-update-cleanup.service static enabled
  8. systemd-ask-password-console.service static enabled
  9. systemd-ask-password-plymouth.service static enabled
  10. systemd-ask-password-wall.service static enabled
  11. systemd-backlight@.service static enabled
  12. ...
复制代码
发现恶意服务,利用下面下令关停(以关闭 ufw.service 服务作为实例):
  1. sudo systemctl stop ufw.service # 停止服务
  2. sudo systemctl disable ufw.service # 删除开启启动
复制代码
关错了,避免尴尬偷偷启动服务>_O
  1. sudo systemctl start ufw.service # 启动服务
  2. sudo systemctl enable ufw.service # 添加开启启动
复制代码
情况变量设置文件

以下这些文件用于设置系情况变量或启动程序,每次Linux登入或切换用户都会触发这些文件,可以排查下面这些文件中有没有恶意文件路径存在。
  1. /etc/profile
  2. /etc/bashrc
  3. /etc/bash.bashrc
  4. ~/.bashrc
  5. ~/.profile
  6. ~/.bash_profile
复制代码
切换用户时也会触发情况变量文件。
  1. Ubuntu@test:~$ sudo su
复制代码
~/.bash_logout

该文件在登出账户时触发。
  1. Ubuntu@test:~$ exit
  2. logout
  3. ~/.bash_logout
复制代码
威胁谍报

威胁谍报是识别和分析网络威胁的过程。威胁谍报平台可以查出一些域名和IP地址的威胁程度,一旦发现它们存在网络攻击痕迹迅速封禁。


  • 微步在线
  • VirusTotal
  • 安恒威胁分析平台
  • 深信服威胁谍报中心
  • VenusEye威胁谍报中心
  • 360威胁谍报中心
  • Data Mining for Threat Intelligence
SSH

SSH(Secure Shell)是一种加密的网络传输协议,通常利用SSH来传输下令行界面和远程执行下令。
账户密码

  1. cat /etc/passwd
  2. root:x:0:0:root:/root:/bin/bash
  3. ...
  4. systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
  5. lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
  6. vulab:x:1000:1000::/home/vulab:/bin/bash
复制代码


  • /bin/bash
[重要排查]账户可登录,登录后利用 /bin/bash 解释执行脚本


  • /bin/false
不可登录,不会有任何提示。


  • /usr/sbin/nologin
不可登录,拒绝用户登录。
密钥窜改

在此位置,攻击者可以对authorized_keys举行修改,改为本身的key即可免密登录,对这里也必要排查。
  1. cat authorized_keys
  2. ssh-rsa
  3. AAAAB3NzaC1yc2EAAAADAQABAAABgQDH9DeY9Ry/8FSlIEKEU/HH2yaPklCf36/ePIW9oS/9i7QklEqv
  4. vrPEfhpcSH0by98a+AjktEoUqt3TRLvM4IHtr7/KAP0m8cFyN0wlpvmY2rqwko3kPbaVm4sb8Qxc4IJo
  5. /0HjRvTAzNvTzzT7unWLaPZ8vUyrDVooRJWdjwbxpq0wtBvcNci7//145sTocddJDvsnwT7ulE/QIdBW
  6. HQdtclUr5zqToSZvslFZHOvoPx34+65R48CrBaucvdBPPslno6FFecQmc0Cy5CSVMr6VM67YdJp/E7RG
  7. Tyl5M8KlCwXHjEabA9dUaT9oMyoR1Jb1u2m1lZWjAx1PTZ86+22XtskCizG3+hZIdwsSvGwArAhBymnk
  8. AsNZso3zqHymbnsnJpZ22FCUs/Gb4YiDjFahC61WsAmfiag6eJwLApfe086QVAcVfSLZQ82ppFRZV79P
  9. M+wu2VU0sb1zmj5F97MaF7LbZB4+QPoL9mnpOcRY6Unbs+TFyp7Pp4W8+/HbI5U=
复制代码
重装覆盖

  1. ls -lt /usr/bin/ssh /usr/sbin/sshd # 不可靠,时间可以被篡改
  2. -rwxr-xr-x 1 root root 876328 Dec 2 2021 /usr/sbin/sshd
  3. -rwxr-xr-x 1 root root 789448 Dec 18 2015 /usr/bin/ssh
  4. sudo touch -a -m -t 201512180130.09 /usr/bin/ssh # 篡改ssh创建时间
  5. ssh -V
  6. OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f 31 Mar 2020
复制代码
参考:


  • openssh-backdoor
  • ssh服务是如何挟制密码
定时使命排查

定时定点执行Linux程序或脚本。
crontab
定时使命计划下令,下面几个是创建使命后保存的路径。


  • /var/spool/cron/ 目次里的使命以用户命名
  • /etc/crontab 调理管理维护使命
  • /etc/cron.d/ 这个目次用来存放任何要执行的crontab文件或脚本。
  • 下面这些都是检查重点对象
  1. /etc/cron.hourly/ 每小时执行一次
  2. /etc/cron.daily/ 每天执行一次
  3. /etc/cron.weekly/ 每周执行一次
  4. /etc/cron.monthly/ 每月执行一次
复制代码
扩展知识:
/etc/cron.allow 存放可创建定时使命账户,一行一个账户名,已创建的定时使命不受影响。
  1. sudo cat /etc/cron.allow
  2. root
  3. crontab -e
  4. You (vulab) are not allowed to use this program (crontab)
  5. See crontab(1) for more information
复制代码
/etc/cron.deny 存放不可创建定时使命账户,一行一个账户名,已创建的定时使命不受影响
  1. crontab -e
  2. You (vulab) are not allowed to use this program (crontab)
  3. See crontab(1) for more information
复制代码
参考:
定时使命
Rootkit

Rootkit是指其重要功能为:隐藏其他程序历程的软件,大概是一个或一个以上的软件组合。在本日,
Rootkit一词更多地是指被作为驱动程序,加载到操纵体系内核中的恶意软件。

  1. sudo python3 builder.py --config config.yml # 编译
  2. rootkit
  3. [sudo] password for vulab:
  4. ████ ████████ ████████ ██████████ █████ ███ █████
  5. ░░███ ███░░░░███ ███░░░░███░███░░░░███░░███ ░░░ ░░███
  6. ░███ ░░░ ░███░░░ ░███░░░ ███ ░███ █████ ████ ███████
  7. ░███ ██████░ ██████░ ███ ░███░░███ ░░███ ░░░███░
  8. ░███ ░░░░░░███ ░░░░░░███ ███ ░██████░ ░███ ░███
  9. ░███ ███ ░███ ███ ░███ ███ ░███░░███ ░███ ░███ ██
  10. █████░░████████ ░░████████ ███ ████ █████ █████ ░░█████
  11. ░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░
  12. LKM Rootkit Builder
  13. ...
  14. LD [M] /tmp/ItclNzX3O3hJUXQ3/project.ko
  15. make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-109-generic'
  16. === File /home/vulab/1337kit/project.ko created ===
  17. sudo insmod project.ko # 将rootkit安装到内核
  18. lsmod # 查看内核模块
  19. sudo rmmod project # 卸载内核模块
复制代码
检查体系是否被植入rootkit

  1. sudo apt install chkrootkit # 安装chkrootkit
  2. sudo chkrootkit
  3. [sudo] password for vulab:
  4. ROOTDIR is `/'
  5. Checking `amd'... not found
  6. Checking `basename'... not infected
  7. Checking `biff'... not found
  8. Checking `chfn'... not infected
  9. Checking `chsh'... not infected
  10. Checking `cron'... not infected
  11. ...
  12. Searching for suspect PHP files... nothing found
  13. Searching for anomalies in shell history files... nothing found
  14. Checking `asp'... not infected
  15. Checking `bindshell'... not infected
  16. Checking `lkm'... chkproc: nothing
  17. detected
  18. chkdirs: nothing detected
  19. Checking `rexedcs'... not found
  20. Checking `sniffer'... lo: not promisc and
  21. no packet ...
  22. Checking `w55808'... not infected
  23. Checking `wted'... chkwtmp: nothing
  24. deleted
  25. Checking `scalper'... not infected
  26. Checking `slapper'... not infected
  27. Checking `z2'... chklastlog: nothing
  28. deleted
  29. Checking `chkutmp'... chkutmp: nothing
  30. deleted
  31. Checking `OSX_RSPLUG'... not tested
复制代码
  1. sudo apt install rkhunter # 安装rkhunter
复制代码

  1. sudo rkhunter --check
  2. [ Rootkit Hunter version 1.4.6 ]
  3. Checking system commands...
  4. Performing 'strings' command checks
  5. Checking 'strings' command [ OK ]
  6. Performing 'shared libraries' checks
  7. Checking for preloading variables [ None found ]
  8. Checking for preloaded libraries [ None found ]
  9. Checking LD_LIBRARY_PATH variable [ Not found ]
  10. ...
复制代码
隐藏的rootkit如何删除

Rootkit在内核模块里找不到,那么就存在删除不掉的大概,这时间必要将感染体系以文件挂载到其它Linux体系上,举行打扫操纵。
参考:


  • rkhunter 官网
  • chkrootkit 官网
  • rootkit demo

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

千千梦丶琪

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表