linux-rootkit

Feature-rich interactive rootkit that targets Linux kernel 4.19, accompanied by a dynamic kernel memory analysis GDB plugin for in vivo introspection (e.g. using QEMU)
git clone git://git.deurzen.net/linux-rootkit
Log | Files | Refs

commit 325cd1c69b15721347a9007202ae9b470ebc9f2a
parent c33c65e54388ecc98af64cf09b961cd93f829dfe
Author: deurzen <m.deurzen@tum.de>
Date:   Fri, 20 Nov 2020 12:34:24 +0100

implements solution to part 1

Diffstat:
Msrc/g7.c | 35++++++++++++++++++++++-------------
Msrc/ioctl.c | 12+++++++++---
Msrc/ioctl.h | 13+++++--------
3 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/src/g7.c b/src/g7.c @@ -5,6 +5,7 @@ #include <linux/mutex.h> #include <linux/proc_fs.h> #include <linux/uaccess.h> +#include <linux/printk.h> #include "ioctl.h" @@ -39,37 +40,44 @@ static struct file_operations g7_fops = static int g7_open(struct inode *inode, struct file *file) { - printk(KERN_INFO "g7_open\n"); - return 0; + mutex_lock(&lock); + pr_info("g7_open\n"); + return 0; } static int g7_release(struct inode *inode, struct file *file) { - printk(KERN_INFO "g7_release\n"); - return 0; + pr_info("g7_release\n"); + mutex_unlock(&lock); + return 0; } static ssize_t -g7_read(struct file *filp, char __user *buf, size_t len, loff_t *off) +g7_read(struct file *file, char __user *buf, size_t len, loff_t *off) { - printk(KERN_INFO "g7_read\n"); - return 0; + pr_info("g7_read\n"); + return 0; } static ssize_t -g7_write(struct file *filp, const char __user *buf, size_t len, loff_t *off) +g7_write(struct file *file, const char __user *buf, size_t len, loff_t *off) { - printk(KERN_INFO "g7_write\n"); - return 0; + pr_info("g7_write\n"); + return 0; } static long -g7_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +g7_ioctl(struct file *_file, unsigned int cmd, unsigned long arg) { + pr_notice("g7_ioctl %#10x\n", cmd); + + if (!(const char *)arg) + return -ENOTTY; + switch (cmd) { case G7_PING: handle_ping(arg); break; - default: break; + default: return -ENOTTY; } return 0; @@ -82,7 +90,7 @@ g7_init(void) mutex_init(&lock); proc_create_data(G7_DEVICE, S_IRUSR | S_IWUSR, 0, &g7_fops, buf); - printk(KERN_INFO "g7 initialized\n"); + pr_info("g7_init " KERN_ALERT "%#lx\n", G7_PING); return 0; } @@ -90,6 +98,7 @@ g7_init(void) static void g7_exit(void) { + pr_info("g7_exit\n"); remove_proc_entry(G7_DEVICE, 0); } diff --git a/src/ioctl.c b/src/ioctl.c @@ -1,14 +1,20 @@ #include <linux/kernel.h> #include <linux/module.h> +#include <linux/uaccess.h> #include "ioctl.h" +#define BUFLEN 4096 + +static char buf[BUFLEN]; + void handle_ping(unsigned long arg) { - if (!strcmp("PING", (const char *)arg)) { - printk(KERN_INFO "caught PING\n"); - printk(KERN_INFO "sending PONG\n"); + copy_from_user(buf, (const char *)arg, BUFLEN); + if (!strcmp("PING", buf)) { + buf[1] = 'O'; + copy_to_user((char *)arg, buf, BUFLEN); } } diff --git a/src/ioctl.h b/src/ioctl.h @@ -1,18 +1,15 @@ -#ifndef _GROUP7_CHARDEV_H -#define _GROUP7_CHARDEV_H +#ifndef _GROUP7_IOCTL_H +#define _GROUP7_IOCTL_H #include <linux/ioctl.h> #define G7_MAGIC_NUMBER '@' -#define G7_DEVICE "G7RKP" +#define G7_DEVICE "g7rkp" -#define G7_PING _IOWR(G7_MAGIC_NUMBER, 0x0, char *) - -#define G7_WRITE _IOW(G7_MAGIC_NUMBER, 0x1, char *) -#define G7_READ _IOW(G7_MAGIC_NUMBER, 0x2, char *) +#define G7_PING _IOWR(G7_MAGIC_NUMBER, 0x0, char *) void handle_ping(unsigned long); -#endif//_GROUP7_CHARDEV_H +#endif//_GROUP7_IOCTL_H