一、ELF文件结构Linux下的可执行文件格式为ELF(Executable and Linkable Format),类似Windows的PE格式。ELF文件格式比较简单,PWN参赛者最需要了解的是ELF头、Section(节)、Segment(段)的概念。ELF头必须在文件开头,表示这是个ELF文件及其基本信息。ELF头包括ELF的magic code、程序运行的计算机架构、程序入口等内容,可以通过“readelf-h”命令读取其内容,一般用于寻找一些程序的入口。ELF文件由多个节(Section)组成,其中存放各种数据。描述节的各种信息的数据统一存放在节头表中。ELF中的节用来存放各种各样不同的数据,主要包括:❖ .text节——存放一个程序的运行所需的所有代码。❖ .rdata节——存放程序使用到的不可修改的静态数据,如字符串等。❖ .data节——存放程序可修改的数据,如C语言中已经初始化的全局变量等。❖ .bss节——用于存放程序的可修改数据,与.data不同的是,这些数据没有被初始化,所以没有占用ELF空间。虽然在节头表中存在.bss节,但是文件中并没有对应的数据。在程序
随着 NX 保护的开启,以往直接向栈或者堆上直接注入代码的方式难以继续发挥效果。攻击者们也提出来相应的方法来绕过保护,目前主要的是 ROP(Return Oriented Programming),其主要思想是在栈缓冲区溢出的基础上,利用程序中已有的小片段 (gadgets) 来改变某些寄存器或者变量的值,从而控制程序的执行流程。所谓 gadgets 就是以 ret 结尾的指令序列,通过这些指令序列,我们可以修改某些地址的内容,方便控制程序的执行流程。之所以称之为 ROP,是因为核心在于利用了指令集中的 ret 指令,改变了指令流的执行顺序。ROP 攻击一般得满足如下条件程序存在溢出,并且可以控制返回地址。可以找到满足条件的 gadgets 以及相应 gadgets 的地址。如果 gadgets 每次的地址是不固定的,那我们就需要想办法动态获取对应的地址了。1.ret2text原理 ret2text 即控制程序执行程序本身已有的的代码 (.text)。其实,这种攻击方法是一种笼统的描述。我们控制执行程序已有的代码的时候也可以控制程序执行好几段不相邻的程序已有的代码 (也就是 gadge
Norman1z