linux(x86) exploit 开发系列4:使用return2libc绕过NX

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux(x86) exploit 开发系列4:使用return2libc绕过NX相关的知识,希望对你有一定的参考价值。

What is NX Bit?

Its an exploit mitigation technique which makes certain areas of memory non executable and makes an executable area, non writable. Example: Data, stack and heap segments are made non executable while text segment is made non writable.

 

列出一个elf程序的头信息

readelf -l vuln
 

How to bypass NX bit and achieve arbitrary code execution?

NX bit can be bypassed using an attack technique called “return-to-libc”. Here return address is overwritten with a particular libc function address (instead of stack address containing the shellcode). For example if an attacker wants to  spawn a shell, he overwrites return address with system() address and also sets up the appropriate arguments required by system() in the stack, for its successful invocation.

 

使用ldd命令可以查看目标程序调用的so库。

 

防止程序获得root权限

//vuln_priv.c
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]) {
 char buf[256];
 seteuid(getuid()); /* Temporarily drop privileges */  strcpy(buf,argv[1]);
 printf("%s\n",buf);
 fflush(stdout);
 return 0;
}
 
对于这种程序,我们可以通过如下调用获取root
  • seteuid(0)
  • system(“sh”)
  • exit()

以上是关于linux(x86) exploit 开发系列4:使用return2libc绕过NX的主要内容,如果未能解决你的问题,请参考以下文章

linux(x86) exploit 开发系列3:off-by-one

SploitFun Linux x86 Exploit 开发系列教程

linux(x86) exploit 开发系列6:使用return-to-plt绕过ASLR

linux(x86) exploit 开发系列5:使用ret2libc链绕过NX

Linux (x86) Exploit 开发系列教程之六(绕过ASLR - 第一部分)

Linux (x86) Exploit系列之三 Off-By-One 漏洞 (基于栈)