#!/usr/bin/env python3 """HackThisSite Steganography 4 ("I am being hexed!") — extract the appended payload. The GIF is a single-frame GIF89a image. After the normal image data it carries a standard GIF trailer byte 0x3B, and then 64 extra bytes that are not part of the image stream: the ASCII characters '0' and '1'. Grouped into bytes they spell an 8-character lowercase password. """ import sys
defextract(path): data = open(path, "rb").read() trailer = data.rfind(b"\x3b") # last GIF trailer byte (0x3B = ';') trailing = data[trailer + 1:] # everything after the trailer ifnotset(trailing) <= set(b"01"): raise SystemExit("trailing data is not a '0'/'1' bit string: %r" % trailing[:32]) bits = trailing.decode("ascii") iflen(bits) % 8: raise SystemExit("bit string length %d is not a multiple of 8" % len(bits)) out = bytes(int(bits[i:i + 8], 2) for i inrange(0, len(bits), 8)) return trailer, bits, out