Safe Opener 2

~# cat Question

What can you do with this file? I forgot the key to my safe but this file is supposed to help me with retrieving the lost key. Can you help me unlock my safe?

FILE: SafeOpener.class

This was another very straight foward reverse engineering challenge. We can use file to see what type file this is. Since it is a complied Java class file, we need to decompile it to see the code.

┌──(tev㉿kali)-[~/pico]
└─$ file SafeOpener.class
SafeOpener.class: complied Java class data, version 52.0 (Java 1.8)

We can use many open-source tools that decompile Java class code. Since this is a simple challenge, I just used a online Java Decomplier. From the decomplied code, we will get the flag.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Base64;
import java.util.Base64.Encoder;
        
public class SafeOpener {
    public static void main(String[] args) throws IOException {
        BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
        Encoder encoder = Base64.getEncoder();
        String encodedkey = "";
        String key = "";
        
        for(int i = 0; i < 3; ++i) {
            System.out.print("Enter password for the safe: ");
            key = keyboard.readLine();
            encodedkey = encoder.encodeToString(key.getBytes());
            System.out.println(encodedkey);
            boolean isOpen = openSafe(encodedkey);
            if (isOpen) {
                break;
            }
        
            System.out.println("You have  " + (2 - i) + " attempt(s) left");
        }
        
    }
        
    public static boolean openSafe(String password) {
        String encodedkey = "picoCTF{SAf3_0p3n3rr_y0u_solv3d_it_0e57c117}";
        if (password.equals(encodedkey)) {
            System.out.println("Sesame open");
            return true;
        } else {
            System.out.println("Password is incorrect
");
            return false;
        }
    }
}

Flag: picoCTF{SAf3_0p3n3rr_y0u_solv3d_it_0e57c117}

Last updated