Advertisement
Madmouse

Detecting most hypervisors using time :D

Apr 14th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. // ------------------------------------------------------------------------------
  2. // THE BEER-WARE LICENSE (Revision 43):
  3. // <aaronryool@gmail.com> wrote this file. As long as you retain this notice you
  4. // can do whatever you want with this stuff. If we meet some day, and you think
  5. // this stuff is worth it, you can buy me a beer in return
  6. // ------------------------------------------------------------------------------
  7. // this is an original POC, if you steal it, I will know :P
  8. #include <unistd.h>
  9. #include <stdio.h>
  10.  
  11. inline unsigned long rdtsc(void)
  12. {
  13.     unsigned long x;
  14.     asm volatile ("rdtsc" : "=A" (x));
  15.     return x;
  16. }
  17.  
  18. unsigned long check_time(void* fun)
  19. {
  20.     static unsigned long StartingTime, EndingTime;
  21.    
  22.     StartingTime = rdtsc();
  23.     ((void(*)(void))fun)();
  24.     EndingTime = rdtsc();
  25.     return (EndingTime - StartingTime);
  26. }
  27.  
  28. void test(void)
  29. {
  30.     int i=0;
  31.     for(;i!=100;i++)
  32.     asm volatile (
  33.         "add eax, ecx\n"
  34.         "imul eax, ebx\n"
  35.         "sub eax, ebx\n"
  36.         "neg eax\n"
  37.         "sbb eax, ecx\n"
  38.     );
  39. }
  40.  
  41. int pass(void)
  42. {
  43.     int i=0;
  44.     unsigned long x;
  45.     for(;i!=10000;i++)
  46.     {
  47.         x=check_time(test);
  48.         if(x>15000) return 1;
  49.     }
  50.     return 0;
  51. }
  52.  
  53. int main()
  54. {
  55.     int i=0,x=0;
  56.     for(;i!=1000;i++)
  57.         x+=pass();
  58.    
  59.     if(x>200)
  60.         puts("matrix");
  61.     else
  62.         puts("realness");
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement