>lhzctf

阅后即焚

1.打开文件

里面有两个文件 一张图stego.bmp和一个一次性看图器reader.npz 看图器中有三个包basis.npy firmware.npy mata.npy

2.分析

从三个文件的源码中提取出

seed:SHA256("afterburn/v1|" + 64×64 basis 每元素 round(v*1024) 大端 int64)
位置:SHA256(seed‖be64(i))[:8] mod N,无放回,N=974*974*3=2 846 028
取位:rgb[p] % 8 >= 4(bit2)
帧:"BURN" + len(4B) + payload + CRC32(4B)
自检:basis.T @ basis ≈ I,烧过就拒绝运行

3.运行脚本

import hashlib, struct, zlib
import numpy as np

B = np.load("reader.npz")["basis"].astype(float)
G = B @ B.T
bad = int(np.argmax(np.linalg.norm(G - np.eye(64), axis=1)))
_, _, vt = np.linalg.svd(B[[i for i in range(64) if i != bad]])
v = vt[-1]

d = open("stego.bmp", "rb").read()
off = struct.unpack_from("<I", d, 10)[0]
w, h = struct.unpack_from("<ii", d, 18)
stride = (w * 3 + 3) // 4 * 4
img = np.frombuffer(d, np.uint8, abs(h) * stride, off).reshape(abs(h), stride)
img = img[:, : w * 3].reshape(abs(h), w, 3)
if h > 0:
    img = img[::-1]
rgb = img[:, :, ::-1].reshape(-1)
N = rgb.size

def seed(basis):
    hh = hashlib.sha256(b"afterburn/v1|")
    for r in basis:
        hh.update(struct.pack(">64q", *[round(float(x) * 1024) for x in r]))
    return hh.digest()

def pos(sd, n):
    out, i = [], 0
    while len(out) < n:
        p = int.from_bytes(hashlib.sha256(sd + struct.pack(">Q", i)).digest()[:8], "big") % N
        if p not in out:
            out.append(p)
        i += 1
    return out

def get(sd, n):
    bits = [int(rgb[p] % 8 >= 4) for p in pos(sd, n)]
    return bytes(int("".join(map(str, bits[i:i + 8])), 2) for i in range(0, n, 8))

for s in (1, -1):
    C = B.copy(); C[bad] = s * v
    sd = seed(C)
    magic, ln = struct.unpack(">II", get(sd, 64))
    if magic != 0x4255524E:
        continue
    blob = get(sd, 64 + 8 * ln + 32)
    print(blob[8:8 + ln].decode(), hex(zlib.crc32(blob[8:8 + ln])), blob[8 + ln:].hex())

得到flag