// 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 source code1. That value is only Base642-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, Java3 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
- The program compares the encoded input to a fixed string → that string is the encoded password → decode it instead of guessing.
- The code calls
Base64.getEncoder()and the string uses only letters, digits,+and/→ it is Base64 → reverse it with a Base64 decoder. - Base64 is encoding, not encryption4 → no key is needed to reverse it.
// Solve
- Open
SafeOpener.java, findopenSafe(), copy the hard-coded5 string.
Result: the encoded key. - CyberChef6 → Magic, paste the string.
Result: Magic detects Base64 and shows the decoded password. - 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
- 1Source codeThe human-readable instructions a program is written in.
- 2Base64A way to write any data using 64 ordinary characters. Reversible by anyone.
- 3JavaA programming language;
.javafiles are its source code. - 4Encoding vs. encryptionEncoding changes format and needs no key to undo. Encryption needs a key.
- 5Hard-codedWritten directly into the code instead of supplied at run time.
- 6CyberChefA free web tool for decoding, encoding and converting data. Magic guesses the format.