Guest User

Untitled

a guest
Apr 1st, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. #define uint32_t unsigned long
  2.  
  3. int main(int argc, char** argv)
  4. {
  5.     uint32_t peb = 0;
  6.     char *base;
  7.     const char *module = "KERNEL32.DLL";
  8.     const char *fname1 = "GetStdHandle";
  9.     uint32_t func1;
  10.     const char *fname2 = "WriteConsoleA";
  11.     uint32_t func2;
  12.     uint32_t *curr;
  13.     uint32_t *end;
  14.     uint32_t i;
  15.     int written;
  16.  
  17. #ifdef __GNUC__
  18.     __asm__ __volatile__(
  19.         "movl %%fs:0x30, %0"
  20.         :"=r"(peb)
  21.         );
  22. #else
  23.     __asm
  24.     {
  25.         mov ebx, fs:[0x30]
  26.         mov peb, ebx
  27.     }
  28. #endif
  29.     curr = (uint32_t*)(*(uint32_t*)((*(uint32_t*)(peb + 12)) + 0x4*5));
  30.     end = (uint32_t*)(*(uint32_t*)((*(uint32_t*)(peb + 12)) + 0x4*6));
  31.     do
  32.     {
  33.         char temp = 0;
  34.         uint32_t i = 0;
  35.         do
  36.         {
  37.             temp = ((char*)*(curr + 10))[i*2];
  38.             if(temp >= 'a' && temp <= 'z')
  39.                 temp -= ' ';
  40.  
  41.             if(temp != module[i])
  42.                 goto next;
  43.  
  44.             if(!module[i])
  45.                 break;
  46.             i++;
  47.         }while(temp != 0);
  48.         base = *(char**)(curr + 0x4);
  49.         break;
  50. next:
  51.         curr = (uint32_t*)*curr;
  52.     }while(end != curr);
  53.  
  54.     if(!base)
  55.         return 1;
  56.  
  57. #define GetProc(_name, _len, _func)\
  58.     if(len == _len)\
  59.     {\
  60.     for(j = 0; j < _len; j++)\
  61.     if(name[j] != _name[j])\
  62.     goto errf1;\
  63.     _func = (uint32_t)base + ((uint32_t*)(base + *(uint32_t*)((*(uint32_t*)(base + *((uint32_t*) base + 0xF) + 0x78) + base) + 0x1C)))[((short*)(base + *(uint32_t*)((*(uint32_t*)(base + *((uint32_t*) base + 0xF) + 0x78) + base) + 0x24)))[i]];\
  64.     }
  65.  
  66.     for(i = 0; i < *(uint32_t*)((*(uint32_t*)(base + *((uint32_t*) base + 0xF) + 0x78) + base) + 0x18); i++)
  67.     {
  68.         char *name = ((char**)(base + *(uint32_t*)((*(uint32_t*)(base + *((uint32_t*) base + 0xF) + 0x78) + base) + 0x20)))[i] + (uint32_t)base;
  69.         uint32_t len;
  70.         uint32_t j;
  71.         for(len = 0; len < 0xFFFF; len++)
  72.             if(name[len] == 0)
  73.                 break;
  74.         GetProc(fname1, 12, func1);
  75.         GetProc(fname2, 13, func2);
  76. errf1:        
  77.         continue;
  78.     }
  79. #undef GetProc
  80.     ((int (__stdcall*)(void*, const void *, int, int*, void*))func2)(((void* (__stdcall*)(int))func1)(-11), "Hello World!", 12, &written, 0);
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment