Beyond the Surface

Confident in your data-hiding skills? Look closer at chall.gif—there is more here than meets the eye.

Flag format: NVR{…}

Attachments

Recon

The download unpacks to a single file, chall.gif, an animated GIF.

$ unzip -l chall.zip
Archive:  chall.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
  1168367  11-25-2026 14:06   chall.gif
---------                     -------
  1168367                     1 file
$ file chall.gif
chall.gif: GIF image data, version 89a, 500 x 281

The only signature binwalk finds is the GIF itself at offset 0, which rules out the easy alternative, a second file appended after the GIF data:

$ binwalk chall.gif
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DECIMAL                            HEXADECIMAL                        DESCRIPTION
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0                                  0x0                                GIF image, 500x281 pixels, total size: 1168367 bytes
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Analyzed 1 file for 85 file signatures (187 magic patterns) in 5.0 milliseconds

So the container itself has to hold whatever is hidden.

The payload in the GIF metadata

A metadata pass over the GIF shows the animation facts and, right next to them, the payload:

$ exiftool -G1 chall.gif | grep -Ei 'count|loop|anim|comment|duration'
[File]          Comment                         : <!--                            --><script>eval(atob("          CiAgICBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuaW5uZXJIVE1MID0gYDxoZWFkPjxtZXRhIGNoYXJzZXQ9InV0Zi04Ij48dGl0bGU+U2lnbmFsPC90aXRsZT4K...
[GIF]           Animation Iterations            : Infinite
[GIF]           Frame Count                     : 33
[GIF]           Duration                        : 1.32 s

The Comment field is an HTML comment followed by a <script> tag whose eval(atob("...")) wraps a large base64 blob, and the blob is padded with wide runs of whitespace, which is what those gaps in the dump are. GIF comments live in a Comment Extension, a block introduced by the two bytes 0x21 0xFE, so this is data sitting inside the container structure, invisible to any viewer.

Finding the real comment extension

Any binary can contain the bytes 0x21 0xFE by coincidence, and compressed data contains them often, so a raw byte-scan is the wrong tool for finding extension blocks. We ran one anyway to see what it would claim:

data = open("chall.gif", "rb").read()
hits = [i for i in range(len(data) - 1) if data[i] == 0x21 and data[i + 1] == 0xFE]
print("naive \\x21\\xfe byte-scan hits:", len(hits))
print("offsets:", hits)
$ python3 scan.py
naive \x21\xfe byte-scan hits: 8
offsets: [800, 139356, 335090, 614914, 811827, 918496, 1004636, 1115230]

Eight candidates, and seven of them sit hundreds of kilobytes into a 1.1 MB file, deep in the LZW stream, which is the lossless compression GIF uses for pixel data. There those two bytes mean nothing. The way to separate real extension blocks from coincidences is to walk the actual block chain, using each block’s declared length to jump to the next block boundary:

import struct

data = open("chall.gif", "rb").read()
w, h, flags = struct.unpack("<HHB", data[6:11])
print(f"header {data[:6].decode()}  logical screen {w}x{h}")
pos = 13
if flags & 0x80:
    pos += 3 * (2 << (flags & 7))   # skip the global color table
gce = images = 0
comments = []
while pos < len(data):
    b = data[pos]
    if b == 0x3B:
        print(f"trailer 0x3B at offset {pos}, file size {len(data)}, bytes after trailer: {len(data)-pos-1}")
        break
    if b == 0x21:
        label = data[pos + 1]
        pos += 2
        if label == 0xF9:
            gce += 1
        if label == 0xFE:
            intro = pos - 2
            chunks = []
            while data[pos] != 0:
                n = data[pos]
                chunks.append(data[pos + 1 : pos + 1 + n])
                pos += 1 + n
            pos += 1
            comments.append((intro, b"".join(chunks)))
        elif label == 0xFF:
            n = data[pos]
            ident = data[pos + 1 : pos + 1 + n].decode("latin1")
            while data[pos] != 0:
                pos += 1 + data[pos]
            pos += 1
            print("application extension:", ident)
        else:
            while data[pos] != 0:
                pos += 1 + data[pos]
            pos += 1
    elif b == 0x2C:
        images += 1
        pos += 1
        lflags = data[pos + 8]
        pos += 9
        if lflags & 0x80:
            pos += 3 * (2 << (lflags & 7))   # skip a local color table
        pos += 1                            # LZW minimum code size
        while data[pos] != 0:
            pos += 1 + data[pos]
        pos += 1
print(f"graphic control extensions: {gce}, image descriptors: {images}")
for intro, payload in comments:
    print(f"comment extension at offset {intro}: {len(payload)} bytes, "
          f"all printable: {all(32 <= c < 127 for c in payload)}")
$ python3 blockwalk.py
header GIF89a  logical screen 500x281
application extension: NETSCAPE2.0
trailer 0x3B at offset 1168366, file size 1168367, bytes after trailer: 0
graphic control extensions: 33, image descriptors: 33
comment extension at offset 800: 1696 bytes, all printable: True

The walk confirms what we are working with: 33 image descriptors, each with a Graphic Control Extension, the block that sets a frame’s delay, the NETSCAPE2.0 application extension that requests the infinite loop, and exactly one Comment Extension, at offset 800, holding 1696 bytes of printable ASCII. The trailer 0x3B is the last byte of the file, so nothing is appended after the GIF either. The walk also settles the byte-scan: of the eight \x21\xFE pairs, only the one at offset 800 sits at a real block boundary.

Pulling the comment out

The comment’s data starts at offset 802, right after the two-byte intro, and continues in sub-blocks, each a one-byte length followed by that many bytes, until a zero length byte ends the chain:

data = open("chall.gif", "rb").read()
pos = 802   # first sub-block length byte of the comment at offset 800
chunks = []
while data[pos] != 0:
    n = data[pos]
    chunks.append(data[pos + 1 : pos + 1 + n])
    pos += 1 + n
payload = b"".join(chunks).decode()
open("comment_payload.html", "w").write(payload)
print("comment payload:", len(payload), "bytes -> comment_payload.html")
print(payload[:120])
print("...")
print(payload[-100:])
$ python3 extract.py
comment payload: 1696 bytes -> comment_payload.html
<!--                            --><script>eval(atob("          CiAgICBkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQuaW5uZXJIVE1MID0g
...
ICsgMSkgKiBzLCBzIC0gMSwgcyAtIDEpOyAgICB9KSk7ICAgIC                "))</script>                <!--

The payload opens with an HTML comment, a long run of spaces between <!-- and -->, then carries the <script> tag, then closes with another HTML comment. Those pieces together are a complete HTML document: a browser that opens the file parses the script tag and runs what is inside it.

Decoding the base64

The base64 inside atob("...") is padded with embedded whitespace, so it has to be stripped before it decodes:

import re, base64

payload = open("comment_payload.html").read()
b64 = re.search(r'atob\("([^"]+)"\)', payload, re.S).group(1)
b64 = re.sub(r"\s+", "", b64)
js = base64.b64decode(b64).decode()
open("decoded_payload.js", "w").write(js)
print("base64 length:", len(b64))
$ python3 decode.py
base64 length: 1584

What the decoded script does

We decoded the base64 ourselves before letting anything run it. The payload came out of a file handed to us by a challenge server, and the point was to read what it does first. Decoded, it looks like this, with the glyph matrix trimmed (all 20 arrays appear in the original):

    document.documentElement.innerHTML = `<head><meta charset="utf-8"><title>Signal</title>
    <style>body{background:#0b0f19;display:flex;justify-content:center;align-items:center;height:100vh;margin:0}
    canvas{border:1px solid #00f0ff;background:#111827;padding:20px;border-radius:10px;box-shadow:0 0 24px rgba(0,240,255,.25);max-width:92vw}</style>
    </head><body><canvas id="c"></canvas></body>`;
    const m = [[17, 25, 21, 19, 17], [17, 17, 17, 10, 4], [30, 17, 30, 20, 18], ... 20 glyph arrays in total ...];
    const s = 8, c = document.getElementById('c'), ctx = c.getContext('2d');
    c.width = m.length * 6 * s; c.height = 7 * s;
    ctx.fillStyle = '#00f0ff';
    m.forEach((g, i) => g.forEach((row, r) => {
      for (let col = 0; col < 5; col++)
        if ((row >> (4 - col)) & 1) ctx.fillRect((i * 6 + col + 1) * s, (r + 1) * s, s - 1, s - 1);
    }));

The script replaces the whole page with its own HTML: a document titled Signal, a near-black background, one <canvas> with a cyan border. Then it draws. m holds 20 glyphs. Each glyph is five integers, and each integer is one pixel row encoded as a 5-bit number from 0 to 31: bit 4 - col set means the pixel at column col of that row gets painted cyan. The canvas is m.length * 6 * s cells wide and 7 * s tall with s = 8, so each glyph is a 5x5 block of cells and glyphs advance by 6 cells, leaving one blank column between neighbors. The script does nothing else: no network access, no further eval stages, only the drawing loop. Having read it, we let a browser run it.

Flag capture

extract.py already saved the comment as comment_payload.html, and opening that file in a browser is the final step. The page takes the title Signal, the background goes near-black, and the canvas draws the 20 glyphs in cyan pixels:

The decoded payload opened in a browser, the flag rendered on the canvas

Reading the rendered canvas gives the flag:

NVR{G1F_1S_N0T_HTML}