C:\Seyi\Portfolio\writeups\safe_opener_ Y:0000PX
...\writeups\safe_opener Y:0000PX

< back to write-ups

CTF // MEDIUM safe_opener.md

// Safe Opener

Reverse Engineering · Medium · CyLab Security Academy (picoCTF)

// Summary

A Java program asks for a password and checks it against a value stored in its own . That value is only -encoded, not locked, so decoding it gives the password. Like a lock with its combination taped to it in a code anyone can read.

// Objective

Given: SafeOpener.java, source code.
Asked: the password the program accepts, as academy{...}.
Type: stated.

// Recon

Running the program — Prompts for a password. Guessing gets nowhere.
cat SafeOpener.java — The program reads input, encodes it with Base64.getEncoder(), and compares the result to a string written into openSafe().

// Deduction

  1. The program compares the encoded input to a fixed string → that string is the encoded password → decode it instead of guessing.
  2. The code calls Base64.getEncoder() and the string uses only letters, digits, + and / → it is Base64 → reverse it with a Base64 decoder.
  3. Base64 is → no key is needed to reverse it.

// Solve

  1. Open SafeOpener.java, find openSafe(), copy the string.
    Result: the encoded key.
  2. → Magic, paste the string.
    Result: Magic detects Base64 and shows the decoded password.
  3. Wrap the password as academy{...}.
    Result: the flag.

// Answer

Plain: the password was stored inside the program in a form that looks scrambled but isn't protected. A free tool unscrambles it.
Technical: openSafe() compares Base64(input) to a constant. Base64 is reversible without a key, so decoding the constant gives the accepted password.

// Dead ends

Running the program and trying passwords — The source shows the check, so guessing is unnecessary.
CyberChef's From Base64 recipe — Gave unreadable output. Cause not confirmed; Magic decoded the same string.

// Root cause

Skill tested: reading source code to find the check, and recognizing Base64.
Real-world use: hard-coded secrets in source code are a common finding in code reviews and leaked repositories. Encoding them doesn't protect them.

// Transfer

  • A program checks a password → find the comparison, then decode whatever the input is compared to.
  • A string of A–Z, a–z, 0–9, +, /, length a multiple of 4, sometimes ending in = → try Base64 first.

// Index

  1. 1Source codeThe human-readable instructions a program is written in.
  2. 2Base64A way to write any data using 64 ordinary characters. Reversible by anyone.
  3. 3JavaA programming language; .java files are its source code.
  4. 4Encoding vs. encryptionEncoding changes format and needs no key to undo. Encryption needs a key.
  5. 5Hard-codedWritten directly into the code instead of supplied at run time.
  6. 6CyberChefA free web tool for decoding, encoding and converting data. Magic guesses the format.