본문 바로가기
CTF

[b01lers CTF] I Love Java

by skyepodium 2022. 6. 6.

1. 개요

디컴파일, 리버싱 문제

 

2. 풀이

1) 확인

CrackMe.class 파일을 받습니다.

2) decompile

IntelliJ ultimate의 decompile 기능을 사용했습니다.

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.util.Random;
import java.util.Scanner;

public class CrackMe {
    public CrackMe() {
    }

    public static void main(String[] var0) {
        Scanner var1 = new Scanner(System.in);
        System.out.println("What is the flag?");
        String var2 = var1.nextLine();
        if (var2.length() != 22) {
            System.out.println("Not the flag :(");
        } else {
            char[] var3 = new char[var2.length()];

            int var4;
            for(var4 = 0; var4 < var2.length(); ++var4) {
                var3[var4] = var2.charAt(var4);
            }

            for(var4 = 0; var4 < var2.length() / 2; ++var4) {
                char var5 = var3[var2.length() - var4 - 1];
                var3[var2.length() - var4 - 1] = var3[var4];
                var3[var4] = var5;
            }

            int[] var10 = new int[]{19, 17, 15, 6, 9, 4, 18, 8, 16, 13, 21, 11, 7, 0, 12, 3, 5, 2, 20, 14, 10, 1};
            int[] var11 = new int[var3.length];

            for(int var6 = var10.length - 1; var6 >= 0; --var6) {
                var11[var6] = var3[var10[var6]];
            }

            Random var12 = new Random();
            var12.setSeed(431289L);
            int[] var7 = new int[var2.length()];

            for(int var8 = 0; var8 < var2.length(); ++var8) {
                var7[var8] = var11[var8] ^ var12.nextInt(var8 + 1);
            }

            String var13 = "";

            for(int var9 = 0; var9 < var7.length; ++var9) {
                var13 = var13 + var7[var9] + ".";
            }

            System.out.println("\nYOUR FLAG: " + var13);
            if (var13.equals("116.122.54.50.93.66.98.117.75.51.97.78.104.119.90.53.94.36.105.84.40.69.")) {
                System.out.println("Congrats! You got the flag!");
            } else {
                System.out.println("Not the flag :(");
            }

        }
    }
}

3) 복호화

import java.util.Random;

class Main {
    public static void main(String[] args) {
        // 1. init
        int n = 22;

        // 2. split
        String var13 = "116.122.54.50.93.66.98.117.75.51.97.78.104.119.90.53.94.36.105.84.40.69.";
        String[] var7 = var13.split("\\.");

        // 3. random xor
        Random var12 = new Random();
        var12.setSeed(431289L);
        int[] randomArr = new int[n];
        for(int i=0; i<n; i++) {
            randomArr[i] = var12.nextInt(i + 1);
        }

        int[] var11 = new int[22];

        for(int i=0; i<n; i++) {
            var11[i] = Integer.parseInt(var7[i]) ^ randomArr[i];
        }

        // 4. index change
        int[] var10 = new int[]{19, 17, 15, 6, 9, 4, 18, 8, 16, 13, 21, 11, 7, 0, 12, 3, 5, 2, 20, 14, 10, 1};

        int[] var3 = new int[n];
        for(int i=0; i<n; i++) {
            var3[var10[i]] = var11[i];
        }

        // 5. reverse
        for(int i=0; i<(n/2); i++) {
            int temp = var3[i];
            var3[i] = var3[n-i-1];
            var3[n-i-1] = temp;
        }

        // 6. print
        for(int i=0; i<n; i++) {
            System.out.print((char)var3[i]);
            // bctf{J4V4_I$_th3_G04T}
        }

    }
}

3. flag

bctf{J4V4_I$_th3_G04T}

'CTF' 카테고리의 다른 글

[b01lers CTF] gambler_overflow  (0) 2022.06.06
[b01lers CTF] gambler baby  (0) 2022.06.06
[NahamCon_CTF_2022] extravagant  (0) 2022.06.06
[NahamCon_CTF_2022] personnel  (0) 2022.06.06
[Patriot CTF] Spongebob  (0) 2022.06.06