0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF 2019 writeup vault-door-3

0
Last updated at Posted at 2025-12-02

vault-door-3 (Reverse Engineering)

This vault uses for-loops and byte arrays. The source code for this vault is here: VaultDoor3.java

添付ファイル
・VaultDoor3.java

ソースコードを確認する。

import java.util.*;

class VaultDoor3 {
    public static void main(String args[]) {
        VaultDoor3 vaultDoor = new VaultDoor3();
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter vault password: ");
        String userInput = scanner.next();
	String input = userInput.substring("picoCTF{".length(),userInput.length()-1);
	if (vaultDoor.checkPassword(input)) {
	    System.out.println("Access granted.");
	} else {
	    System.out.println("Access denied!");
        }
    }

    // Our security monitoring team has noticed some intrusions on some of the
    // less secure doors. Dr. Evil has asked me specifically to build a stronger
    // vault door to protect his Doomsday plans. I just *know* this door will
    // keep all of those nosy agents out of our business. Mwa ha!
    //
    // -Minion #2671
    public boolean checkPassword(String password) {
        if (password.length() != 32) {
            return false;
        }
        char[] buffer = new char[32];
        int i;
        for (i=0; i<8; i++) {
            buffer[i] = password.charAt(i);
        }
        for (; i<16; i++) {
            buffer[i] = password.charAt(23-i);
        }
        for (; i<32; i+=2) {
            buffer[i] = password.charAt(46-i);
        }
        for (i=31; i>=17; i-=2) {
            buffer[i] = password.charAt(i);
        }
        String s = new String(buffer);
        return s.equals("jU5t_a_sna_3lpm18g947_u_4_m9r54f");
    }
}

標準入力をfor文で並べ替え、"jU5t_a_sna_3lpm18g947_u_4_m9r54f"と一致するかを確認している。
並べ換えの処理は以下の通り。

  • 0 ~ 7:0文字目から順に8文字分
  • 8 ~ 15:15文字目から逆順で8文字分
  • 16以降の偶数:30文字目から逆順かつ偶数番で8文字分
  • 17以降の奇数:17文字目から正順かつ奇数番で8文字分

この処理に従い、並べ換え後が"jU5t_a_sna_3lpm18g947_u_4_m9r54f"となるようにし、前後にpicoCTF{}を追加する。

フラグが得られた。

picoCTF{jU5t_a_s1mpl3_an4gr4m_4_u_79958f}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?