紧张声明
文中技术只可用于安全技术研究,任何非法用途与作者无关,请勿用在生产情况安装测试rootkit。
处置惩罚手段
发现问题要处置惩罚,遵循原则: 百分百确认黑白法文件,报备记载关停,摸棱两可找负责人确认,处置惩罚看沟通结果。
linux应急响应
开机启动项排查
陪同开机启动,一般生产服务器很少重启,但是为防止被控呆板失联部门木马会添加开机启动项作为复活手段。
/etc/rc.local
- #!/bin/sh -e
- #
- # rc.local
- #
- # This script is executed at the end of each multiuser runlevel.
- # Ensure that the script will "exit 0" on success or any other
- # value on error.
- #
- # To enable or disable this script, just change the execution
- # bits.
- #
- # By default, this script does nothing.
- # 下方为开机启动列表
- touch /root/1.txt
复制代码 /etc/rc.d/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
- touch /tmp/1.txt
复制代码 /etc/rc.d/init.d/
该目次下放了可执行脚本或者文件。
/etc/rc*.d/
- rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/ rcS.d/
复制代码 systemctl list-unit-files
重要关注enabld历程。
- ...
- ssh.service enabled enabled
- ssh@.service static enabled
- sshd.service enabled enabled
- sudo.service masked enabled
- syslog.service enabled enabled
- system-update-cleanup.service static enabled
- systemd-ask-password-console.service static enabled
- systemd-ask-password-plymouth.service static enabled
- systemd-ask-password-wall.service static enabled
- systemd-backlight@.service static enabled
- ...
复制代码 发现恶意服务,利用下面下令关停(以关闭 ufw.service 服务作为实例):
- sudo systemctl stop ufw.service # 停止服务
- sudo systemctl disable ufw.service # 删除开启启动
复制代码 关错了,避免尴尬偷偷启动服务>_O
- sudo systemctl start ufw.service # 启动服务
- sudo systemctl enable ufw.service # 添加开启启动
复制代码 情况变量设置文件
以下这些文件用于设置系情况变量或启动程序,每次Linux登入或切换用户都会触发这些文件,可以排查下面这些文件中有没有恶意文件路径存在。
- /etc/profile
- /etc/bashrc
- /etc/bash.bashrc
- ~/.bashrc
- ~/.profile
- ~/.bash_profile
复制代码 切换用户时也会触发情况变量文件。
~/.bash_logout
该文件在登出账户时触发。
- Ubuntu@test:~$ exit
- logout
- ~/.bash_logout
复制代码 威胁谍报
威胁谍报是识别和分析网络威胁的过程。威胁谍报平台可以查出一些域名和IP地址的威胁程度,一旦发现它们存在网络攻击痕迹迅速封禁。
- 微步在线
- VirusTotal
- 安恒威胁分析平台
- 深信服威胁谍报中心
- VenusEye威胁谍报中心
- 360威胁谍报中心
- Data Mining for Threat Intelligence
SSH
SSH(Secure Shell)是一种加密的网络传输协议,通常利用SSH来传输下令行界面和远程执行下令。
账户密码
- cat /etc/passwd
- root:x:0:0:root:/root:/bin/bash
- ...
- systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
- lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
- vulab:x:1000:1000::/home/vulab:/bin/bash
复制代码
[重要排查]账户可登录,登录后利用 /bin/bash 解释执行脚本
不可登录,不会有任何提示。
不可登录,拒绝用户登录。
密钥窜改
在此位置,攻击者可以对authorized_keys举行修改,改为本身的key即可免密登录,对这里也必要排查。
- cat authorized_keys
- ssh-rsa
- AAAAB3NzaC1yc2EAAAADAQABAAABgQDH9DeY9Ry/8FSlIEKEU/HH2yaPklCf36/ePIW9oS/9i7QklEqv
- vrPEfhpcSH0by98a+AjktEoUqt3TRLvM4IHtr7/KAP0m8cFyN0wlpvmY2rqwko3kPbaVm4sb8Qxc4IJo
- /0HjRvTAzNvTzzT7unWLaPZ8vUyrDVooRJWdjwbxpq0wtBvcNci7//145sTocddJDvsnwT7ulE/QIdBW
- HQdtclUr5zqToSZvslFZHOvoPx34+65R48CrBaucvdBPPslno6FFecQmc0Cy5CSVMr6VM67YdJp/E7RG
- Tyl5M8KlCwXHjEabA9dUaT9oMyoR1Jb1u2m1lZWjAx1PTZ86+22XtskCizG3+hZIdwsSvGwArAhBymnk
- AsNZso3zqHymbnsnJpZ22FCUs/Gb4YiDjFahC61WsAmfiag6eJwLApfe086QVAcVfSLZQ82ppFRZV79P
- M+wu2VU0sb1zmj5F97MaF7LbZB4+QPoL9mnpOcRY6Unbs+TFyp7Pp4W8+/HbI5U=
复制代码 重装覆盖
- ls -lt /usr/bin/ssh /usr/sbin/sshd # 不可靠,时间可以被篡改
- -rwxr-xr-x 1 root root 876328 Dec 2 2021 /usr/sbin/sshd
- -rwxr-xr-x 1 root root 789448 Dec 18 2015 /usr/bin/ssh
- sudo touch -a -m -t 201512180130.09 /usr/bin/ssh # 篡改ssh创建时间
- ssh -V
- 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文件或脚本。
- 下面这些都是检查重点对象
- /etc/cron.hourly/ 每小时执行一次
- /etc/cron.daily/ 每天执行一次
- /etc/cron.weekly/ 每周执行一次
- /etc/cron.monthly/ 每月执行一次
复制代码 扩展知识:
/etc/cron.allow 存放可创建定时使命账户,一行一个账户名,已创建的定时使命不受影响。
- sudo cat /etc/cron.allow
- root
- crontab -e
- You (vulab) are not allowed to use this program (crontab)
- See crontab(1) for more information
复制代码 /etc/cron.deny 存放不可创建定时使命账户,一行一个账户名,已创建的定时使命不受影响
- crontab -e
- You (vulab) are not allowed to use this program (crontab)
- See crontab(1) for more information
复制代码 参考:
定时使命
Rootkit
Rootkit是指其重要功能为:隐藏其他程序历程的软件,大概是一个或一个以上的软件组合。在本日,
Rootkit一词更多地是指被作为驱动程序,加载到操纵体系内核中的恶意软件。
- sudo python3 builder.py --config config.yml # 编译
- rootkit
- [sudo] password for vulab:
- ████ ████████ ████████ ██████████ █████ ███ █████
- ░░███ ███░░░░███ ███░░░░███░███░░░░███░░███ ░░░ ░░███
- ░███ ░░░ ░███░░░ ░███░░░ ███ ░███ █████ ████ ███████
- ░███ ██████░ ██████░ ███ ░███░░███ ░░███ ░░░███░
- ░███ ░░░░░░███ ░░░░░░███ ███ ░██████░ ░███ ░███
- ░███ ███ ░███ ███ ░███ ███ ░███░░███ ░███ ░███ ██
- █████░░████████ ░░████████ ███ ████ █████ █████ ░░█████
- ░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░
- LKM Rootkit Builder
- ...
- LD [M] /tmp/ItclNzX3O3hJUXQ3/project.ko
- make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-109-generic'
- === File /home/vulab/1337kit/project.ko created ===
- sudo insmod project.ko # 将rootkit安装到内核
- lsmod # 查看内核模块
- sudo rmmod project # 卸载内核模块
复制代码 检查体系是否被植入rootkit
- sudo apt install chkrootkit # 安装chkrootkit
- sudo chkrootkit
- [sudo] password for vulab:
- ROOTDIR is `/'
- Checking `amd'... not found
- Checking `basename'... not infected
- Checking `biff'... not found
- Checking `chfn'... not infected
- Checking `chsh'... not infected
- Checking `cron'... not infected
- ...
- Searching for suspect PHP files... nothing found
- Searching for anomalies in shell history files... nothing found
- Checking `asp'... not infected
- Checking `bindshell'... not infected
- Checking `lkm'... chkproc: nothing
- detected
- chkdirs: nothing detected
- Checking `rexedcs'... not found
- Checking `sniffer'... lo: not promisc and
- no packet ...
- Checking `w55808'... not infected
- Checking `wted'... chkwtmp: nothing
- deleted
- Checking `scalper'... not infected
- Checking `slapper'... not infected
- Checking `z2'... chklastlog: nothing
- deleted
- Checking `chkutmp'... chkutmp: nothing
- deleted
- Checking `OSX_RSPLUG'... not tested
复制代码- sudo apt install rkhunter # 安装rkhunter
复制代码
- sudo rkhunter --check
- [ Rootkit Hunter version 1.4.6 ]
- Checking system commands...
- Performing 'strings' command checks
- Checking 'strings' command [ OK ]
- Performing 'shared libraries' checks
- Checking for preloading variables [ None found ]
- Checking for preloaded libraries [ None found ]
- Checking LD_LIBRARY_PATH variable [ Not found ]
- ...
复制代码 隐藏的rootkit如何删除
Rootkit在内核模块里找不到,那么就存在删除不掉的大概,这时间必要将感染体系以文件挂载到其它Linux体系上,举行打扫操纵。
参考:
- rkhunter 官网
- chkrootkit 官网
- rootkit demo
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |