Pwntools 是由 Gallopsled 开发的一款专用于 CTF Exploit 的 Python 库,包含了本地执行、远程连接读写、shellcode 生成、ROP 链的构建、ELF 解析、符号泄漏等众多强大功能,可以说把 EXP 繁琐的过程变得简单起来。(1)项目地址:https://github.com/Gallopsled/pwntools;(2)官方文档:http://docs.pwntools.com/en/latest/。这里只简单介绍一下它的部分 API 使用:借助 pwntools 编写的 exp 脚本示例:from pwn import * coon = remote('111.200.241.244',65238) #连接远程IP和端口 coon.recv() #接收远程发来的内容 payload = b'a'*4 + p64(1853186401) #构建溢出攻击的payload coon.sendline(payload) #向远程发送我们的payload
一、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节,但是文件中并没有对应的数据。在程序
%后加的字母 代表的含义 %d 打印整型十进制数据 %c 打印字符格式数据 %f 打印float浮点数据 %p 打印地址数据 %x 打印十六进制数据 %s 打印字符串 %lf
ANSI C/C++基本数据类型 Type Size 数值范围 无值型void 0 byte 无值域 布尔型bool 1 byte true false 有符号短整型short [int] /signed short [int] 2 byte -32768~32767 无符号短整型unsigned sho
随着 NX 保护的开启,以往直接向栈或者堆上直接注入代码的方式难以继续发挥效果。攻击者们也提出来相应的方法来绕过保护,目前主要的是 ROP(Return Oriented Programming),其主要思想是在栈缓冲区溢出的基础上,利用程序中已有的小片段 (gadgets) 来改变某些寄存器或者变量的值,从而控制程序的执行流程。所谓 gadgets 就是以 ret 结尾的指令序列,通过这些指令序列,我们可以修改某些地址的内容,方便控制程序的执行流程。之所以称之为 ROP,是因为核心在于利用了指令集中的 ret 指令,改变了指令流的执行顺序。ROP 攻击一般得满足如下条件程序存在溢出,并且可以控制返回地址。可以找到满足条件的 gadgets 以及相应 gadgets 的地址。如果 gadgets 每次的地址是不固定的,那我们就需要想办法动态获取对应的地址了。1.ret2text原理 ret2text 即控制程序执行程序本身已有的的代码 (.text)。其实,这种攻击方法是一种笼统的描述。我们控制执行程序已有的代码的时候也可以控制程序执行好几段不相邻的程序已有的代码 (也就是 gadge
Norman1z