第二届帕鲁杯时间循环的信使
题目描述:
某神秘组织通过时间循环传递加密信息,我们在捕获的流量日志中发现异常时间戳。日志文件显示:"在错误的时间做正确的事,在正确的时间解开谜题",flag格式为palu{xxx}
解压得到timeloop.log:
感觉里面有一些十六进制数据,八个相同的字符?
根据题目描述,先查看一下文件时间戳:
stat timeloop.log
额,还是看不出什么
按时间戳排序->保留'|'右侧字符重复数据->取右侧1位组成十六进制字符串解码
python代码如下:
import re
import binasciidef extract_and_decode_hex():# 读取日志文件try:with open('timeloop.log', 'r') as f:lines = f.readlines()except FileNotFoundError:print("错误: 文件 'timeloop.log' 未找到")return# 正则表达式:匹配8个相同十六进制字符的行pattern = re.compile(r'^([0-9a-fA-F])\1{7}$')parsed_data = []# 解析每一行for line in lines:line = line.strip()if not line:continue# 分割时间戳和数据部分parts = line.split('|', 1)if len(parts) != 2:continue # 忽略格式不正确的行timestamp_str, data = parts[0], parts[1]# 验证时间戳是否为数字try:timestamp = int(timestamp_str)except ValueError:continue # 时间戳无效则跳过# 验证数据是否符合规则:8个相同十六进制字符if len(data) == 8 and pattern.match(data):parsed_data.append((timestamp, data))# 按时间戳排序parsed_data.sort(key=lambda x: x[0])# 提取最后一个字符并拼接成HEX字符串hex_str = ''.join([item[1][-1] for item in parsed_data])print(f"提取的HEX字符串: {hex_str}")# 解码HEX为ASCII/字符串try:# 补全偶数长度(若需要)if len(hex_str) % 2 != 0:hex_str += '0'print("提示: HEX长度为奇数,已补零")decoded = binascii.unhexlify(hex_str).decode('utf-8', errors='replace')print("解码结果:",decoded)except binascii.Error as e:print(f"解码失败: HEX格式错误 ({e})")except UnicodeDecodeError as e:print(f"解码失败: 非UTF-8字符 ({e})")if __name__ == "__main__":extract_and_decode_hex()
得到flag:
palu{Time_1s_cycl1c@l_0x}