【Linux应急响应—上 】一文解明Linux应急响应(hw蓝队兄弟看这里):开机启动项排查、环境变量配置文件排查、威胁情报获取、ssh排查、定时任务排查、Rootkit排查

重要声明

文中技术只可用于安全技术研究,任何非法用途与作者无关,请勿用在生产环境安装测试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

切换用户时也会触发环境变量文件。

Ubuntu@test:~$ sudo su

~/.bash_logout

该文件在登出账户时触发。

Ubuntu@test:~$ exit
logout
~/.bash_logout

威胁情报

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

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

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

  • /bin/false

不可登录,不会有任何提示。

  • /usr/sbin/nologin

不可登录,拒绝用户登录。

密钥篡改

在此位置,攻击者可以对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

参考:

定时任务排查

定时定点执行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系统上,进行清除操作。
参考:

  • 23
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

webfker from 0 to 1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值