0%

TFCCTF2024-writeup

前言

最近加入了朋友的隊伍 Archetype,之後可能會以這支隊名參賽,其次才是之前常用的 TLT 了。

忘記截 CTF 平台的圖片,只好用 ctftime 來代替

這次排名扣除只解 welcome 的隊伍,大約是 101/638(15.83%)

本次排名

Write up

這次我主要是在 Crypto 的部分

Crypto

CCCCC

CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC CCCCC

CCCCC CCCCC CCCCC

題目有給一個 ccccc.txt 的文字檔,資料看起來像是 hex 的,嘗試將他轉換為 ASCII 就可以得到 flag

1
2
3
4
5
6
7
8
hex_data = "5c4c4c6c4c3c4c3c5c4c4c6c7cbc6c3c7c3c6c8c6cfc7c5c7c4c5cfc6c3c6cfc7c5c7c4c5cfc6c3c7c4c3c0c5cfc6c3c6cdc7c9c5cfc6c3c6c2c3c0c7c9c5cfc6c3c3c4c6cec6c4c5cfc6c3c6cdc7c9c5cfc6c3c6c4c6cfc6c7c5cfc6c3c6c1c6cec6c4c5cfc6c3c6cdc7c9c5cfc6c3c6c3c3c4c3c7c7cdc0ca"

# 移除所有 'c' 和 'C',並用空格替換
cleaned_hex_data = hex_data.replace('c', ' ').replace('C', ' ').replace(' ', '')

decoded_cleaned_data = bytes.fromhex(cleaned_hex_data).decode('latin1')
decoded_cleaned_data
# TFCCTF{cshout_cout_ct0_cmy_cb0y_c4nd_cmy_cdog_cand_cmy_cc47}\n

GENETICS

I just took a quick look at my DNA. I feel like I was created for this CTF.

CCCA CACG CAAT CAAT CCCA CACG CTGT ATAC CCTT CTCT ATAC CGTA CGTA CCTT CGCT ATAT CTCA CCTT CTCA CGGA ATAC CTAT CCTT ATCA CTAT CCTT ATCA CCTT CTCA ATCA CTCA CTCA ATAA ATAA CCTT CCCG ATAT CTAG CTGC CCTT CTAT ATAA ATAA CGTG CTTC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dna_sequence = "CCCA CACG CAAT CAAT CCCA CACG CTGT ATAC CCTT CTCT ATAC CGTA CGTA CCTT CGCT ATAT CTCA CCTT CTCA CGGA ATAC CTAT CCTT ATCA CTAT CCTT ATCA CCTT CTCA ATCA CTCA CTCA ATAA ATAA CCTT CCCG ATAT CTAG CTGC CCTT CTAT ATAA ATAA CGTG CTTC"

# 移除空格
dna_sequence = dna_sequence.replace(" ", "")


dna_to_binary = {'A': '00', 'C': '01', 'G': '10', 'T': '11'}

# 將 DNA 序列轉換為二進制
binary_string = ''.join(dna_to_binary[base] for base in dna_sequence)


byte_array = bytearray(int(binary_string[i:i+8], 2) for i in range(0, len(binary_string), 8))


decoded_text = byte_array.decode('ascii', errors='ignore')

decoded_text

# TFCCTF{1_w1ll_g3t_th1s_4s_4_t4tt00_V3ry_s00n}

CONWAY

Sequences… Sequences sequences… Sequences sequences sequences…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import hashlib
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad

def generate_next_key(sequence):
result = []
i = 0
while i < len(sequence):
count = 1
while i + 1 < len(sequence) and sequence[i] == sequence[i + 1]:
i += 1
count += 1
result.append(str(count) + sequence[i])
i += 1
return ''.join(result)

initial = '311311222113111231131112132112311321322112111312211312111322212311322113212221'

initial = generate_next_key(initial)
print(f'Generated sequence: {initial}')

h = hashlib.sha256()
h.update(initial.encode())
key = h.digest()

# output.txt
ciphertext_hex = 'f143845f3c4d9ad024ac8f76592352127651ff4d8c35e48ca9337422a0d7f20ec0c2baf530695c150efff20bbc17ca4c'
ciphertext = bytes.fromhex(ciphertext_hex)

# 用 AES 解
cipher = AES.new(key, AES.MODE_ECB)
plaintext_padded = cipher.decrypt(ciphertext)

# 去除 padding
plaintext = unpad(plaintext_padded, AES.block_size).decode()
print(f'Flag: {plaintext}')

# TFCCTF{c0nway's_g4me_0f_sequences?}