← all posts

· 5 min read · by Eav Puthcambo

Making a syscall when syscalls are banned

A RISC-V golf challenge bans the one instruction that can make a syscall. The way through is to borrow one the kernel already mapped into the process for you.

Golfing, LYKN CTF 2026 (pwn / RISC-V)

You connect and get one line:

Send your RISC-V ELF (base64):

The service takes a RISC-V executable, runs a battery of checks on it, boots it inside a QEMU guest, and shows you whatever it prints. The flag is in /flag.txt. The checks are the whole challenge:

  • the ELF has to be tiny
  • its .text section is capped at 113 bytes
  • no ecall bytes anywhere in the file
  • no ebreak either, in either the normal or the compressed 16-bit form

That ecall ban is the cruel part. On RISC-V, ecall is the instruction that makes a system call. There is no other one. Ban it from the file you send, and it looks like you simply can't ask the kernel to open or read the flag.

The idea: the ban is only on your file

Here's the loophole. ecall has to be absent from your ELF. It does not have to be absent from the process.

Every Linux process gets a VDSO mapped in by the kernel: a small, real, executable chunk of kernel-supplied code. It's there to make certain calls fast, and it is genuinely part of your address space at runtime. The challenge's scanner only looks at the bytes of your file, and the VDSO was never in your file, so it never gets inspected.

And somewhere inside that VDSO sits exactly the gadget I need:

ecall
ret

If I jump into that with a jalr, it makes the syscall and the ret sends control right back to my code. That's a callable syscall function the validator can't see, because its bytes never touch my file.

Finding the VDSO with no syscalls of my own

To use the gadget I need its address, which means finding where the VDSO is mapped. Normally you'd ask libc, but there's no libc here, just raw shellcode dropped at the entry point. No syscalls allowed yet either, so I can't ask the kernel directly.

The answer is already on the stack when the program starts. When the kernel hands a fresh process control, the stack looks like this from the top:

argc
argv[]     (pointers, NULL-terminated)
envp[]     (NULL-terminated)
auxv[]     (pairs of {type, value}, terminated by AT_NULL)

That last one, the auxiliary vector, is the kernel telling the new process facts about itself without any syscalls: page size, user id, CPU features, and the one I want, AT_SYSINFO_EHDR (type 33), whose value is the VDSO's base address.

So the shellcode just walks the stack: skip argc, step past argv to its NULL, past envp to its NULL, then scan the auxv pairs until it finds type 33 and takes that value. Add a fixed offset to reach the ecall; ret gadget (found once by disassembling the VDSO ahead of time), and from that point on every syscall is: load the argument registers and jalr into the gadget.

Reading the flag

With syscalls available, the flag is three of them, RISC-V numbers 56 / 63 / 64:

openat(AT_FDCWD, "/flag.txt", O_RDONLY, 0)   → fd
read(fd, buffer, 0x100)                        → length
write(1, buffer, length)

One small trap cost me time here: I first read 0x40 (64) bytes and the flag came back cut off, because it's longer than 64 bytes. The output wasn't wrong, just truncated, which is an easy thing to stare past. Bumping the read size to 0x100 fixed it.

Fitting it in 113 bytes

The .text cap is tight enough that this has to be hand-assembled; there's no room for a compiler's calling-convention overhead. The payload lands at 88 bytes: find AT_SYSINFO_EHDR, compute the gadget address, run the three syscalls, with the literal "/flag.txt" string packed onto the end of the same blob, since there's no spare data section.

That shellcode goes into the smallest ELF64 that will still load: a hand-built header and two program segments. One is read-execute and holds the headers plus the shellcode. The other is read-write, zero bytes on disk but 4 KB in memory, to serve as the scratch buffer for read without storing any buffer in the file.

My solve.py builds that ELF byte by byte, checks it against the same limits the server enforces (including a sneaky extra rule: no run of four identical bytes anywhere), base64-encodes it, and sends it:

$ python3 solve.py 15.235.202.47 9002
[+] text size : 88 bytes
[+] ELF size  : 456 bytes
Send your RISC-V ELF (base64): …
<FLAG>LYKNCTF{...::#RISC!@2026%_^~}

The whole exploit is just binary layout and a socket. No disassembler, because the shellcode was written straight to bytes. The clever part was never the code; it was realising that "no ecall in your file" and "no ecall in your process" are two very different rules, and the kernel already handed me the second one.

📂 Full writeup and the solve.py that builds the ELF: ctf-writeups/pwn/…/Golfing

Thanks for reading! Questions or corrections? Ping me on GitHub.

Read more

all posts →