Aleer
Aleer
发布于 2026-11-10 / 6 阅读
0
0

MISC - bj

赛事:第三届 PCTF2026 新生赛 | 方向:Misc | 状态:已出 flag

Flag:PCTF{you_get_a_correct_answer}

一、题目信息

项内容
附件attachments(5).zip → images/(2048 张 32×32 PNG)+ cifar-100-python/
考点图片集筛选 + PNG 元数据(tEXt)
环境纯离线

二、解题思路

  1. 2048 张 32×32 小图正好是 CIFAR-100 的尺寸/数量级,题面是「在一堆图里找正确答案」。
  2. 先按常规做统计筛选(均值图、位平面、按通道/行列聚合),能看出部分图与其余图分布不同,但不够直接。
  3. 换个角度直接读 PNG 的 chunk:72 张图里带 PCTF{...} —— 其中 64 张在 tEXt 的 Comment 里,8 张直接追加在 IEND 之后。
  4. 取任意一张即得 flag;这 72 张就是「正确答案」集合。

三、关键步骤

  1. 遍历 PNG,按 chunk 结构解析:length(4) + type(4) + data + crc(4),找 tEXt。
  2. tEXt 数据格式为 keyword\0text,读取 Comment:
    kw, _, text = data.partition(b"\x00")
    if kw == b"Comment" and b"PCTF{" in text:
        ...
  3. 统计:2048 张里 72 张命中(64 张 tEXt + 8 张尾部追加),内容均为 PCTF{you_get_a_correct_answer}。

四、拿到 Flag

PCTF{you_get_a_correct_answer}

五、Exp

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""bj:扫图片里的 PCTF 字样(tEXt 注释 / IEND 之后追加)

用法:python "Misc - bj - exp.py" bj/images
"""
import os
import re
import sys

ROOT = sys.argv[1] if len(sys.argv) > 1 else "images"
PAT = re.compile(rb"PCTF\{[^}]+\}")


def scan(path):
    """返回 [(flag, where)],where = tEXt / trailing / pixels"""
    data = open(path, "rb").read()
    res = []
    for m in PAT.finditer(data):
        before = data[:m.start()]
        if b"tEXt" in before[-64:]:
            where = "tEXt"
        elif b"IEND" in before:
            where = "trailing (IEND 之后)"
        else:
            where = "in-data"
        res.append((m.group(0).decode(), where))
    return res


def main():
    hits, flags = [], {}
    for dp, _, fn in os.walk(ROOT):
        for f in fn:
            if not f.lower().endswith(".png"):
                continue
            p = os.path.join(dp, f)
            for s, where in scan(p):
                hits.append((p, s, where))
                flags[s] = flags.get(s, 0) + 1

    print("hit images:", len({h[0] for h in hits}))
    for p, s, where in hits[:5]:
        print("   ", p, "->", where)
    for s, n in flags.items():
        print("[+] flag:", s, "(出现 %d 次)" % n)


if __name__ == "__main__":
    main()

评论