Last active
August 18, 2024 07:12
-
-
Save muratdemirtas/31b46c459c9c2e285ed71b159a89480c to your computer and use it in GitHub Desktop.
call userspace application from kernel module
This file contains hidden or 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/kmod.h> | |
| #include <linux/kernel.h> | |
| // char pointer arrays for environment and arguments | |
| char * envp[] = { "HOME=/","PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; | |
| char * argv[] = { "pathofyour executable", NULL }; | |
| //module settings | |
| MODULE_LICENSE("GPL"); | |
| MODULE_AUTHOR("MURAT DEMIRTAS"); | |
| //initial callback | |
| static int __init example_init(void) | |
| { | |
| int ret = 0; | |
| printk("module loaded\n"); | |
| ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); | |
| if (ret != 0) | |
| printk("error in call to usermodehelper: %i\n", ret); | |
| else { | |
| printk("ok\n"); | |
| return 0; | |
| } | |
| return 0; | |
| } | |
| //exit callback | |
| static void __exit example_exit(void) | |
| { | |
| printk("module removed\n"); | |
| } | |
| //set callback functions | |
| module_init(example_init); | |
| module_exit(example_exit); | |
Author
typo:
rintk("module removed\n");printk("module removed\n");also, question:
Why is it called
linux_keylogger?module_init(linux_keylogger_init); module_exit(linux_keylogger_exit);
typo fixed, thank you.,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
typo:
also, question:
Why is it called
linux_keylogger?