Skip to content

Bloat less stack

Here you are, lost in the middle of the forest (not that forbidden or secret, but scary all the same, because it's raining too, and it's cold, and there's wind, yikes, this really is not a friendly forest). Then you run into Totoro and the gang, who claim to be waiting for a cat-shaped bus? You need a ticket, but the ticket machine doesn't look very helpful, it just shows a strange message. Can we get a ticket?


The goal of the challenge is to force the player to use x86-64 assembly to read the flag file, which sits inside a directory.

To figure out that the page expected x86-64 assembly, you had to read its source code:

<!--

frontend fully vibecoded without respect for my fellows css enjoyer, gotta say it

so to make up for it: https://en.wikipedia.org/wiki/X86-64

really, you're welcome \ (^_^) /

-->

Or just submit anything, which triggers an error about "asm" files:

p.asm:1: error: parser: instruction expected
p.asm:2: error: label or instruction expected at start of line

So you need to:

  • list the contents of the current directory (code 1)

  • list the contents of the directory you found (code 1, slightly modified)

  • read the file inside that directory (code 2)

The write-up below shows the assembly programs cut down to the bare minimum needed to get the flag.

List the current directory

section .bss
    buf: resb 4096 ; buffer that will hold the data to print

section .text
    global _start

_start:
    push 0x2e ; the "." character, to read the current directory
    mov rax, 2 ; rax holds the syscall number, 2 = sys_open
    mov rdi, rsp ; rsp points to the top of the stack (".")
    xor rsi, rsi ; same as mov rsi, 0 but cheaper for the CPU
    syscall ; sys_open(rdi = ".", rsi = 0 = O_RDONLY), the fd is returned in rax

    mov rdi, rax
    mov rax, 217
    mov rsi, buf
    mov rdx, 4096
    syscall ; getdents64(fd, buf, 4096)

    ; the data is in buf, rax holds the number of bytes written to it
    ; rsi still points to buf

    mov rdx, rax 
    mov rax, 1
    mov rdi, 1
    syscall ; write(rdi = 1 = stdout, rsi = buf, rdx = number of bytes to print)

    mov rax, 60
    xor rdi, rdi
    syscall
��.r��..  �� ticketbox

Once we've found the directory, we run almost the same program again to list its contents.

List the discovered directory

; declare a data section to hold the path
; we didn't need one before since the path was a single character, so the stack was enough
section .data
    dir: db "ticketbox", 0

section .bss
    buf: resb 4096

section .text
    global _start

_start:
    mov rax, 2
    mov rdi, dir
    xor rsi, rsi
    syscall

    mov rdi, rax
    mov rax, 217
    mov rsi, buf
    mov rdx, 4096
    syscall

    mov rdx, rax
    mov rax, 1
    mov rdi, 1
    syscall

    mov rax, 60
    xor rdi, rdi
    syscall
��.��..��8free_ticket_for_totoro_friend.txt

Now that we have the file name, we can read it.

Read the flag

section .data
    path: db "ticketbox/free_ticket_for_totoro_friend.txt", 0

section .bss
    buf: resb 4096

section .text
    global _start

_start:
    ; open(path), the file descriptor (fd) goes into rax
    mov rax, 2
    mov rdi, path
    xor rsi, rsi
    syscall

    ; Copy the contents of the file behind fd into buf
    mov rdi, rax
    mov rax, 0
    mov rsi, buf
    mov rdx, 4096
    syscall ; read(fd, buf, 4096), the contents go into buf

    ; Print buf
    mov rdx, rax
    mov rax, 1
    mov rdi, 1
    syscall ; write(1, buf, rax)

    mov rax, 60
    xor rdi, rdi
    syscall
FLAG{LE_Chat-bus_ARRiVE_ATTenTION_AU_DEPaRT}