Skip to content

Instantly share code, notes, and snippets.

@xcellerator
Created September 12, 2020 11:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcellerator/d3a75b0e20d7bf0cab0c521838116ac2 to your computer and use it in GitHub Desktop.
Save xcellerator/d3a75b0e20d7bf0cab0c521838116ac2 to your computer and use it in GitHub Desktop.
Kernel Linked List Example
obj-m += rootkit.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("TheXcellerator");
MODULE_DESCRIPTION("Linked Lists Example");
MODULE_VERSION("0.01");
static int __init rootkit_init(void)
{
printk(KERN_INFO "rootkit: Loaded >:-)\n");
struct list_head *next_position = (&THIS_MODULE->list)->next;
struct list_head *prev_position = (&THIS_MODULE->list)->prev;
struct module *next_ptr = NULL;
struct module *prev_ptr = NULL;
next_ptr = list_entry( next_position, struct module, list);
prev_ptr = list_entry( prev_position, struct module, list);
printk(KERN_DEBUG "rootkit: next kernel module = %s\n", next_ptr->name);
printk(KERN_DEBUG "rootkit: prev kernel module = %s\n", prev_ptr->name);
return 0;
}
static void __exit rootkit_exit(void)
{
printk(KERN_INFO "rootkit: Unloaded :(\n");
}
module_init(rootkit_init);
module_exit(rootkit_exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment