Fresh Java

Challenge Overview

Can you get the flag?

Reverse engineer this Java program.

Solution

https://artifacts.picoctf.net/c/199/KeygenMe.class

If you cat the file you can see the flag (it is most recognizable near the end).

cat KeygenMe.class

image

However it seems to be reversed.

Since this is a class file and we know it is a Java progam we can use jd-gui to decompile the file.

sudo apt install jd-gui

Then run jd-gui in the command line.

image

Once there I used "open file" to open the correct file. This then gave the decompiled Java code, however I'd prefer to view this in the command line so I then saved the file as "KeygenMe.java" in the correct directory.

image

In the Java file we can see the same thing that it is looking at the flag charater by charater in reverse.

image

Since every line there is a part of the flag there is "str.charAt()", I used grep to look for "str.char".

cat KeygenMe.java | grep str.char

image

Now to get just the letters themselves I used cut to look at the ' delimiter and the second field.

image

cat KeygenMe.java | grep str.char | cut -d "'" -f2

Each charater was on a newline so I used tr to look at the \n (newline) delimiter and delete it.

image

Now I used "rev" to reverse the output.

cat KeygenMe.java | grep str.char | cut -d "'" -f2 | tr -d "\n" | rev

This gives the flag successfully.

Flag: picoCTF{700l1ng_r3qu1r3d_2bf...}