Perplexed

https://play.picoctf.org/practice/challenge/458?category=3&page=1

Challenge Overview

We were provided with a binary named perplexed. Our task was to reverse engineer it, understand its password validation logic, and extract the correct input that would pass the check.


Step 1: Initial Reconnaissance

We begin by inspecting the binary with the file command:

The output confirms:

  • It's a 64-bit ELF binary

  • It is dynamically linked

  • It's not stripped (we may see symbol info)

We give it execute permissions and then run it

Step 2: Static Analysis using Binary Ninja

Opening the binary in Binary Ninja, we find two main functions:

  1. main() – handles input/output

  2. check() – performs validation of the input

Decompiled Code

Step 3:Understanding the check Function Logic

  • It validates the bitstream of the 27-byte password (0x1b = 27).

  • A hardcoded 23-byte array is used as a bitmask reference.

  • The user input is treated bit by bit (not byte-by-byte).

  • It compares 184 bits from the user input (23×8) against this hardcoded bitstream.

Example:

Let’s say the first character of input is 'p'.

  • 'p' → ASCII 112 → Binary: 01110000

  • The function compares certain bits of 'p' to the first bits of the hardcoded array.

Step 4: Map bits → reverse the check

For each bit in the stored 23-byte sequence:

  1. Decide which bit position in the result buffer it maps to.

  2. Remember:

    • You skip bit 0 (MSB)

    • You fill bits 1 through 7 of each byte

    • After reaching 7 bits, move to next byte

  3. So the filling order for result[0] will be bits 6 → 0 (because you're filling from MSB down, but skipping 7th bit)

Repeat this for 184 bits.

After running the script we got out flag

Last updated