KITCTFCTF 2022 Writeup

この大会は2022/12/10 3:00(JST)~2022/12/11 9:00(JST)に開催されました。
今回もチームで参戦。結果は216点で228チーム中118位でした。
自分で解けた問題をWriteupとして書いておきます。

Insanity Check (misc)

Discordに入り、#rulesチャネルのトピックを見ると、フラグが書いてあった。

Website: https://ctf.kitctf.me/
 
KCTF{Welcome_to_KITCTFCTF111!!!!34675837}
KCTF{Welcome_to_KITCTFCTF111!!!!34675837}

One Trick Pony (boomer crypto)

$ nc kitctf.me 12345
This is my message to you: 33AE0C532293259809A0DBC89A928D235CAB3AD86F8082AD15355C0D56EDE9F207412DC64431D73F053B6461379B3FB6C7D7EDA9FFD0273F2ED61C28521DB1EE17814A8124808E091E7811E2CAAF04FBEA183F4285C048DB46C01C279879A928226D973793C08A71B87D979D76544CE119BCE109BD8F39E4DDEA3CF1EEDFAEC036DC937D

$ nc kitctf.me 12345
This is my message to you: 33AE0C532293259809A0DBC89A928D235CAB3AD86F8082AD15355C0D56EDE9F207412DC64431D73F053B6461379B3FB6C7D7EDA9FFD0273F2ED61C28521DB1EE17814A8124808E091E7811E2CAAF04FBEA183F4285C048DB46C01C279879A928226D973793C08A71B87D979D76544CE119BCE109BD8F39E4DDEA3CF1EEDFAEC036DC937D

rand()で、元のメッセージの長さ分XORしているが、何回暗号化しても同じなので、rand()の鍵は決まっているはず。C言語で鍵を生成するコードを使い、復号する。

$ cat solve.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main() {
    char h_enc[] = "33AE0C532293259809A0DBC89A928D235CAB3AD86F8082AD15355C0D56EDE9F207412DC64431D73F053B6461379B3FB6C7D7EDA9FFD0273F2ED61C28521DB1EE17814A8124808E091E7811E2CAAF04FBEA183F4285C048DB46C01C279879A928226D973793C08A71B87D979D76544CE119BCE109BD8F39E4DDEA3CF1EEDFAEC036DC937D";
    char enc[256];
    char secret_msg[256];
    int len;
    unsigned int x;

    len = strlen(h_enc);
    for (int i=0; i<len; i+=2) {
        sscanf((char *)(h_enc + i), "%02x", &x);
        enc[i/2] = x;
    }

    unsigned char* random_bytes = malloc(len/2);
    for (size_t i = 0; i < len/2; i++) {
        random_bytes[i] = rand();
    }

    for (size_t i = 0; i < len/2; i++) {
        secret_msg[i] = enc[i] ^ random_bytes[i];
    }

    printf("%s\n", secret_msg);
}
$ gcc solve.c -o solve
$ ./solve
The slot machine in the corner has quite favorable odds. This might earn you some chips to start with: KCTF{sh0uld_h4ve_us3d_4_s33d}
KCTF{sh0uld_h4ve_us3d_4_s33d}