赛事:第三届 PCTF2026 新生赛 | 方向:Misc | 状态:已出 flag
Flag:PCTF{you_get_a_correct_answer}
一、题目信息
| 项 | 内容 |
|---|---|
| 附件 | attachments(5).zip → images/(2048 张 32×32 PNG)+ cifar-100-python/ |
| 考点 | 图片集筛选 + PNG 元数据(tEXt) |
| 环境 | 纯离线 |
二、解题思路
- 2048 张 32×32 小图正好是 CIFAR-100 的尺寸/数量级,题面是「在一堆图里找正确答案」。
- 先按常规做统计筛选(均值图、位平面、按通道/行列聚合),能看出部分图与其余图分布不同,但不够直接。
- 换个角度直接读 PNG 的 chunk:72 张图里带
PCTF{...}—— 其中 64 张在tEXt的Comment里,8 张直接追加在IEND之后。 - 取任意一张即得 flag;这 72 张就是「正确答案」集合。
三、关键步骤
- 遍历 PNG,按 chunk 结构解析:
length(4) + type(4) + data + crc(4),找tEXt。 tEXt数据格式为keyword\0text,读取Comment:kw, _, text = data.partition(b"\x00") if kw == b"Comment" and b"PCTF{" in text: ...- 统计: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()