一个为乐趣而非恶意编写的简单 Linux 内核 rootkit。
该 rootkit 可以实现以下功能:
该 rootkit 已在 Ubuntu 10.04.4 LTS 和 Ubuntu 16.04 LTS 提供的 Linux 内核 2.6.32-38 和 4.4.0-22 上测试通过,但应该很容易移植到介于两者之间的内核版本以及更新的版本。
rootkit 中包含一些特定于架构的代码,这些代码仅针对 x86 和 x86-64 架构实现。 这些代码用于查找系统调用表、禁用写保护内存以及两种函数挂钩方法之一。 将其移植到新架构应该非常容易,而且其中部分代码并非 rootkit 运行所必需的,例如不可移植的挂钩方法可以剥离掉,不过如果你愿意放弃那种通过覆盖目标内核函数的机器码来调用我们的挂钩函数的乐趣,那你一定是个非常无趣的人。
该 rootkit 仅在 1 个 CPU 核心上测试过,因此在多核系统上可能无法正常工作。 它很可能无法在多核系统上良好运行,因为该 rootkit 的编写假设任意时刻只有 1 个线程在执行代码,因此它缺少针对链表数据结构的原子写入/读取和互斥锁。
启动你选择的虚拟机。
获取并安装所需的 Ubuntu 镜像:
| 内核 / 架构 | x86 | x86-64 |
|---|---|---|
| 2.6.32 | Ubuntu 10.04.4 i386 (694M) [torrent] [iso] | Ubuntu 10.04.4 amd64 (681M) [torrent] [iso] |
| 4.4.0 | Ubuntu 16.04 i386 (647M) [torrent] [iso] | Ubuntu 16.04 amd64 (655M) [torrent] [iso] |
对于 Ubuntu 10.04,请修补软件包仓库地址:
sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
安装编译器、Linux 头文件以及构建 rootkit 所需的其他所有内容:
apt-get update
apt-get install build-essential
确保不要执行 apt-get upgrade,因为它会更新内核,而该 rootkit 仅在预装的内核版本上测试过。
make
加载 rootkit:
insmod rootkit.ko
使用 rootkit:
$ ./client --help
Usage: ./client [OPTION]...
Options:
--root-shell Grants you root shell access.
--hide-pid=PID Hides the specified PID.
--unhide-pid=PID Unhides the specified PID.
--hide-file=FILENAME Hides the specified FILENAME globally.
Must be a filename without any path.
--unhide-file=FILENAME Unhides the specified FILENAME.
--hide Hides the rootkit LKM.
--unhide Unhides the rootkit LKM.
--help Print this help message.
--protect Protects the rootkit from rmmod.
--unprotect Disables the rmmod protection.
卸载 rootkit:
./client --unhide
./client --unprotect
rmmod rootkit.ko
并非如此,网上有很多关于如何编写 Linux rootkit 的文章并附带了完整源代码,更不用说数不胜数的 GitHub 仓库了。
编写此 rootkit 时使用了以下资料:
本项目采用 GPLv2 许可证。