Skip to main content
Challenges Format-string vulnerability: writing to memory via %n
PWN Hard Format string Solves: 7

Format-string vulnerability: writing to memory via %n

Author: CyberSamSU
Points
80

%x only reads — but another printf specifier in C, %n, WRITES the number of characters outputted to the screen so far to the specified address (pointer!). This is a full arbitrary write primitive.

def printf_n_sim(fmt_parts, reg_args, stack_args, memory):
    """fmt_parts — [('literal', matn) | ('pad', N, argN) | ('n', argN)] ro'yxati."""
    chiqqan = 0
    for part in fmt_parts:
        if part[0] == 'literal':
            chiqqan += len(part[1])
        elif part[0] == 'pad':          # %<N>x, kengligi majburlangan
            chiqqan += part[1]
        elif part[0] == 'n':             # %<pos>$n
            pos = part[1]
            addr = reg_args[pos-1] if pos <= 5 else stack_args[pos-6]
            memory[addr] = chiqqan       # <-- YOZISH!

Your format string first outputs a known text (literal) consisting of 31 characters. After that, you place %<W>x (width-forced hex output, outputs W characters, regardless of its value), and then you write with %<N>$n.

The memory address where the "verification code" (for example, the authorization flag) is located inside the program is equal to ONE OF the arguments given in the table below — but you must know which one is a pointer and which one is simply register/stack garbage:

N (6+i)Value
66333003
71774609
82768853
9660287
105762165
113425080
121585436
13484564

In this system, real memory addresses (pointers) are always located in the range 0x00600000–0x0060FFFF (the ".data" segment). Other values — simply smaller numbers (register garbage) — never fall into this range.

You must write exactly the value 5035 to this address (the program will only continue executing with this value).

Calculate two things: (1) the required width W for %x (such that prefix_len + W = maqsad qiymat), (2) the argument number N holding the pointer (from the table above).

Submit the answer in the format BAYROQ{PWN_WRITE_W<W>_N<N>} (for example W12_N7).

Theory: learn the topic
Hints 3
Opening a hint reduces the points you get for solving this challenge.
Hint 1 −8 pts Log in
Hint 2 −16 pts Log in
Hint 3 −24 pts Log in
To submit a flag, log in.

First solvers

1. W.o.X 17.09.2026
2. testrejim 09.10.2026
3. 𝖛𝖊𝖑𝖐𝖆𝖓 24.10.2026
4. Mirjaxon Qaxxarov 27.10.2026
5. Odam 05.11.2026
6. Furqat Turayev 10.11.2026
7. arcanum 11.11.2026