Skip to content

Instantly share code, notes, and snippets.

@muratdemirtas
Last active August 18, 2024 07:12
Show Gist options
  • Select an option

  • Save muratdemirtas/31b46c459c9c2e285ed71b159a89480c to your computer and use it in GitHub Desktop.

Select an option

Save muratdemirtas/31b46c459c9c2e285ed71b159a89480c to your computer and use it in GitHub Desktop.
call userspace application from kernel module
#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);
@loneicewolf
Copy link

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);

@muratdemirtas
Copy link
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