题目:

注:这是 题目/比赛海报(裁剪版),想要题目的可以去参加阿里ctf获取

​

分析

PNG Chunk 隐写:存在非法 Chunk Fl4G

对题目PNG图片进行chunk解析,PNG chunk type 按规范应是 4 个字母,但文件里存在 Fl4G(含数字),所以该 chunk 的 data 以 0x78 0x9c 开头,是 zlib压缩流。


zlib 解压得到 WAV

对 Fl4G chunk 的 data 做 zlib.decompress,解出 RIFF....WAVE,得到隐藏音频。

脚本如下:

#!/usr/bin/env python3
import struct
import zlib
import sys

PNG_SIG = b"\x89PNG\r\n\x1a\n"

def read_chunk(f):
    raw_len = f.read(4)
    if len(raw_len) != 4:
        return None
    length = struct.unpack(">I", raw_len)[0]
    ctype = f.read(4)
    data = f.read(length)
    crc = f.read(4)
    if len(ctype) != 4 or len(data) != length or len(crc) != 4:
        return None
    return length, ctype, data, crc

def main(png_path, out_path="hidden.wav", target=b"Fl4G"):
    with open(png_path, "rb") as f:
        sig = f.read(8)
        if sig != PNG_SIG:
            raise SystemExit("Not a PNG file (bad signature).")

        while True:
            chunk = read_chunk(f)
            if chunk is None:
                break
            length, ctype, data, crc = chunk

            if ctype == target:
                hdr = data[:2].hex(" ")
                print(f"[+] Found chunk: {ctype.decode()} ({length} bytes)   header: {hdr} ... (zlib)")
                raw = zlib.decompress(data)
                with open(out_path, "wb") as w:
                    w.write(raw)
                print(f"[+] zlib.decompress -> {out_path}")
                return

            if ctype == b"IEND":
                break

    raise SystemExit(f"Target chunk {target.decode()} not found.")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print(f"Usage: {sys.argv[0]} <png> [out]")
        sys.exit(1)
    png = sys.argv[1]
    out = sys.argv[2] if len(sys.argv) > 2 else "hidden.wav"
    main(png, out)

音频参数:

  • 1 channel
  • 16-bit
  • 48000 Hz
  • 5707200 frames

​

WAV 频域隐写 → 字节流 → PNG

将音频按 **0.1s 一段(4800 samples)**切片;每段用 8 个频点是否存在表示 8 bit:

频点(Hz):[100, 200, 400, 800, 1600, 3200, 6400, 12800]
阈值:频点幅值 > 1e6 认为该 bit=1。

bit 顺序:低频=低位(LSB)。
这样 1189 段 = 1189 字节,字节流开头正好是 PNG 头:89 50 4E 47 ...



#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os, sys, zipfile, zlib, struct, wave
import numpy as np
from pathlib import Path

FREQS = [100, 200, 400, 800, 1600, 3200, 6400, 12800]
THR = 1e6  # 幅值阈值
BLOCK = 4800  # 0.1s at 48kHz

def parse_png_chunks(png: bytes):
    if png[:8] != b"\x89PNG\r\n\x1a\n":
        raise ValueError("Not a PNG")
    pos = 8
    while pos + 8 <= len(png):
        length = struct.unpack(">I", png[pos:pos+4])[0]; pos += 4
        ctype  = png[pos:pos+4]; pos += 4
        data   = png[pos:pos+length]; pos += length
        crc    = png[pos:pos+4]; pos += 4
        yield ctype, data
        if ctype == b"IEND":
            break

def extract_fl4g(png_path: Path) -> bytes:
    b = png_path.read_bytes()
    for ctype, data in parse_png_chunks(b):
        if ctype == b"Fl4G":
            return data
    raise ValueError("Fl4G chunk not found")

def wav_to_bytes(wav_bytes: bytes) -> bytes:
    # 读 wav
    import io
    wf = wave.open(io.BytesIO(wav_bytes), "rb")
    assert wf.getnchannels() == 1
    assert wf.getsampwidth() == 2
    assert wf.getframerate() == 48000

    n = wf.getnframes()
    samples = np.frombuffer(wf.readframes(n), dtype=np.int16).astype(np.float32)

    sr = wf.getframerate()
    num_blocks = len(samples) // BLOCK
    samples = samples[:num_blocks * BLOCK].reshape(num_blocks, BLOCK)

    # FFT 一次性做完(快)
    window = np.hanning(BLOCK).astype(np.float32)
    fft = np.fft.rfft(samples * window, axis=1)
    mag = np.abs(fft)

    # 频点 bin
    step = sr / BLOCK  # 10Hz
    bins = [int(f / step) for f in FREQS]
    energies = mag[:, bins]

    bits = (energies > THR).astype(np.uint8)  # (num_blocks, 8)

    # 低频=LSB
    weights = (1 << np.arange(8, dtype=np.uint8))
    out = (bits * weights).sum(axis=1).astype(np.uint8)
    return out.tobytes()

def main():
    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} 热身赛题目.zip")
        sys.exit(1)

    zpath = Path(sys.argv[1]).resolve()
    outdir = Path("out").resolve()
    outdir.mkdir(parents=True, exist_ok=True)

    # 解压
    with zipfile.ZipFile(zpath, "r") as z:
        z.extractall(outdir)

    # 找 png
    pngs = list(outdir.rglob("*.png"))
    if not pngs:
        raise SystemExit("No PNG found in zip")
    png_path = pngs[0]
    print("[+] PNG:", png_path)

    # 提取 Fl4G -> zlib 解压 -> wav
    fl4g = extract_fl4g(png_path)
    wav_bytes = zlib.decompress(fl4g)
    wav_path = outdir / "hidden.wav"
    wav_path.write_bytes(wav_bytes)
    print("[+] WAV extracted:", wav_path)

    # wav -> bytes -> png
    payload = wav_to_bytes(wav_bytes)
    aztec_png = outdir / "decoded_from_audio.png"
    aztec_png.write_bytes(payload)
    print("[+] Aztec PNG:", aztec_png)

    print("\nNext: use ZXing to decode this Aztec image and you will get the flag:")
    print("  ", aztec_png)

if __name__ == "__main__":
main()

得到

Aztec 解码得到 flag

用 ZXing / 任何支持 Aztec 的解码器扫这张图,输出即 flag

脚本:
import zxingcpp

from PIL import Image

img = Image.open("decoded_from_audio.png").convert("RGB")

res = zxingcpp.read_barcode(img)

print(res.text)

​

运行得到flag

最后也是拿到了衣服