warmup問というだけあって簡単そう
import struct import os MSG = b'twctf: please give me the flag of 2020' assert os.environ['FLAG'] def easy_hash(x): m = 0 for i in range(len(x) - 3): m += struct.unpack('<I', x[i:i + 4])[0] m = m & 0xffffffff return m def index(request): message = request.get_data() if message[0:7] != b'twctf: ' or message[-4:] != b'2020': return b'invalid message format: ' + message if message == MSG: return b'dont cheet' msg_hash = easy_hash(message) expected_hash = easy_hash(MSG) if msg_hash == expected_hash: return 'Congrats! The flag is ' + os.environ['FLAG'] return 'Failed: easy_hash({}) is {}. but expected value is {}.'.format(message, msg_hash, expected_hash)
スライドしながら4バイトを足し合わせていくeasy_hash
で、twctf: please give me the flag of 2020
と同じhashになって、この文字列ではなく、またtwctf:
で始まり2020
で終わるような文字列を送れば良い。これは簡単で、4バイトのブロックに区切ってどこか一つをswapすれば良い。
twctf: pe gileasve me the flag of 2020
とかで通る