Hacking stories these days mostly involve someone using an army of AI agents to find vulnerabilities in networks and software that were carefully hidden in plain sight. Today, for a change, we have a story about hacking in its original meaning — twisting computing artifacts into purposes not in their design spec. David Oberhollenzer, aka Goliath, a greybeard in spirit if not in shade, crafted a 100% valid ZIP file that's simultaneously an archive, BIOS-bootable, and a Multiboot-compatible OS image.

You can unpack the ZIP file just like any other, boot it using Linux's GRUB, QEMU, or any other Multiboot-compatible loader (even if imaged to different media), or alternatively, perform the finest party trick: image-write it to a floppy and boot from it directly from BIOS on any compatible PC, without modification.

Much like me, that sequence of words may be triggering a head-tilt reminiscent of a confused puppy, so we'll explain. The first thing you need to know is that unlike most file types, the metadata (in this case, file directory) of a ZIP is actually at the end of the archive. Up to that point, the data is comprised of every compressed file in sequence.

The file packs all have a predictable structure: "PK" followed by bytes 03 04, metadata (including name), some extra/comment fields, and then the file's contents. Notably, any file can be stored uncompressed, and Goliath made use of that for the very first file, called ZIPHEAD.COM — remember, this is the start of the ZIP archive.

Goliath said that it was "easy" to make the ZIP file a valid Multiboot system image. A valid image only needs to contain bytes 0x1BADB002 in the first 8 KiB, followed by some flags and a checksum. It was trivial to place that datum in ZIPHEAD's data, along with the location of where the bootloader lies.

Grub or QEMU don't care about anything else in the image, as once they have the initialization information, from that point it's the bootloader's problem. The actual bootloader, predictably, is in ZIPHEAD's uncompressed data, and the image will happily boot directly, or, say, from a floppy.

Making the same exact archive bootable via a standard PC BIOS took a little more work and some clever shenanigans. Making a disk bootable is simple enough: the BIOS reads the first exact 512 bytes of the disk's contents, and if they end with bytes 0x55AA, then it's bootable, and the BIOS starts executing whatever code is the first byte.

Placing 0x55AA precisely at position 510 of the ZIP, already in ZIPHEAD's contents, is once again simple, and won't corrupt the Multiboot image, as if you'll recall, the Multiboot spec is flexible with data locations. But you may wonder: once the BIOS runs code in sequence starting from the ZIP's first byte, then ZIPHEAD's header ("PK" + 0x0304, plus all metadata) surely is garbage for practical purposes, and not proper code? Well, yes, but actually no.

The first four bytes represent CPU instructions that don't write anything to memory, so they're harmless, other than a push-to-stack. The next few belong to ZIPHEAD's metadata, and Goliath massaged those values to represent instructions that would either be innocuous or perform operations he could use, namely using the modification time bytes as instructions to jump further down the data.

Sounds simple, but the actual process of choosing bytes that represent (1) non-crashy CPU instructions, (2) useful code for setting up the boot process, and (3) still represent a valid file header in a ZIP archive is far trickier than the above. Do go and check out the full blog post if you want all the details.