第二届帕鲁杯时间循环的信使

题目描述:

某神秘组织通过时间循环传递加密信息,我们在捕获的流量日志中发现异常时间戳。日志文件显示:"在错误的时间做正确的事,在正确的时间解开谜题",flag格式为palu{xxx}


解压得到timeloop.log:

感觉里面有一些十六进制数据,八个相同的字符?


根据题目描述,先查看一下文件时间戳:

stat timeloop.log

额,还是看不出什么


按时间戳排序->保留'|'右侧字符重复数据->取右侧1位组成十六进制字符串解码

python代码如下:

import re
import binascii

def 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}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值