Reverse

Published: April 26, 2023

Description

A stripped binary named ret hides a password in plain sight. Retrieve it via static inspection.

Download the ELF and examine it with strings or a disassembler.

Search for picoCTF inside the binary output.

wget https://artifacts.picoctf.net/c/270/ret
strings ret | grep pico

Solution

  1. Step 1Rely on strings
    Despite the challenge name, the binary embeds the flag literally. strings ret provides the answer immediately.
    Learn more

    Static analysis examines a binary without executing it. The simplest static analysis tool is strings, which extracts sequences of printable characters (minimum length 4 by default) from a binary file. Because C string literals are stored verbatim in the binary's .rodata (read-only data) section, any hard-coded passwords, URLs, error messages, or flags appear directly in the strings output.

    A stripped binary has had its symbol table and debug information removed (via strip or a compiler flag like -s). This hides function names, variable names, and source file information, making disassembly harder - but it does not affect string literals stored in the data section. That is why strings still works: the flag is a string constant that the linker places in .rodata regardless of whether the binary is stripped.

    For challenges where the flag is not stored as a plain string, the next steps are: Ghidra (free NSA tool) or IDA for disassembly and decompilation, and ltrace/strace or gdbfor dynamic analysis. The challenge name "reverse" is intentionally misleading here - recognizing when brute-force reversal is unnecessary and strings suffices is itself a skill.

    The strings command accepts a -n flag to set the minimum string length (default 4). Increasing this value, e.g., strings -n 8 binary, filters out noise and focuses on longer strings that are more likely to be meaningful. You can also specify an encoding with -e: -e l for 16-bit little-endian (common in Windows binaries) and -e b for 16-bit big-endian. On PE (Windows) executables, the strings command from Sysinternals (strings.exe) handles Unicode strings natively.

    When strings doesn't reveal a flag, the binary may be obfuscating it: XOR-encrypting the string constant and decoding it at runtime, building the string character-by-character on the stack, or deriving it from a hash. These techniques are common in malware to evade static string analysis. The appropriate counter-tool in that case is dynamic analysis: run the binary under gdb and set a breakpoint just before the comparison, then read the decoded value from memory.

    file and checksec are useful first commands on any unfamiliar binary. file binary reports the architecture, bitness (32 vs 64), and whether the binary is stripped. checksec --file=binary lists security mitigations in place: ASLR, stack canaries, NX (No-eXecute), PIE (position-independent executable), and RELRO. This triage determines the difficulty of any dynamic exploitation attempt even if, as in this challenge, no exploitation is required.

Flag

picoCTF{3lf_r...f62bc8}

No reversing tools beyond strings are required for this warm-up.

Want more picoCTF 2023 writeups?

Useful tools for Reverse Engineering

Related reading

What to try next