Option A: pwntools shellcraft + asm
pwntoolscan generate and assemble shellcode for you.shellcraftis a library of ready-made snippets;asm()assembles raw assembly to bytes.
from pwn import *
context.arch = 'amd64' # target architecture
# Ready-made execve("/bin/sh") shellcode:
sc = asm(shellcraft.sh())
print(len(sc), "bytes")
print(enhex(sc)) # inspect the byte string
# Assemble your own snippet:
mine = asm('xor rax, rax; mov al, 59; syscall')
Key Takeaway
shellcraft.sh() plus asm() is the fastest way to get correct, tested bytes for lab exercises.