Developer creates a 100% valid ZIP file that doubles as a BIOS-bootable operating system

Science & Technology

One File, Three Functions: Developer Boots a PC From a Valid ZIP Archive

A developer built a ZIP file that unpacks normally, boots via GRUB and QEMU as a Multiboot OS, and starts a PC BIOS straight from a floppy — unmodified.

By
Nathan Brooks
Filed
Channel
Science & Technology
Read
3 min read

A single 512-byte constraint is the hinge of the whole trick: developer David Oberhollenzer, known online as Goliath, has built a 100% valid ZIP file that also boots as an operating system. The archive unpacks normally in any ZIP tool, loads as a Multiboot-compatible OS image through GRUB or QEMU, and starts a standard PC BIOS when written raw to a floppy. No modification required for any of the three.

This is hacking in the older sense of the word. Rather than hunting hidden vulnerabilities, Oberhollenzer bent a file format toward a purpose its designers never imagined. The result is an artifact that three entirely different pieces of software — an archiver, a Multiboot loader, and a 1980s-vintage BIOS — each interpret as legitimate.

How does a ZIP become a bootloader?

The structure of the format does most of the work. Unlike most file types, a ZIP keeps its metadata, the central directory, at the end of the archive. Everything before it is a sequence of file entries, each beginning with the signature bytes "PK" followed by 03 04, then header fields, then the file contents. Critically, any file inside a ZIP may be stored uncompressed.

Oberhollenzer exploited that with the first entry, a file named ZIPHEAD.COM. A valid Multiboot image needs only the magic number 0x1BADB002 within its first 8 KiB, plus flags and a checksum. He called making the archive a valid Multiboot image "easy": the magic number and the pointer to the bootloader both fit inside ZIPHEAD's stored data. GRUB and QEMU ignore everything else in the image once they have that initialization information. The rest, as he notes, becomes the bootloader's problem.

The actual bootloader code lives in ZIPHEAD's uncompressed contents. Boot it via a Multiboot loader, or image the file to media, and it runs.

What about the BIOS boot sector?

Standard PC BIOS booting is stricter. The BIOS reads the first 512 bytes of a disk, checks that they end with the bytes 0x55AA at positions 510 and 511, and then begins executing code from the very first byte. Placing 0x55AA inside ZIPHEAD's data was once again simple, and the Multiboot specification is flexible enough about data locations that nothing broke.

The harder question is the beginning. When the BIOS executes from byte zero, the first thing it hits is the ZIP local file header: "PK", the bytes 03 04, and then metadata fields. That is not code. Except, it turns out, it is.

The first four bytes decode as CPU instructions that write nothing to memory — harmless, apart from one push to the stack. The following metadata bytes Oberhollenzer then massaged by hand until they represented instructions that were either innocuous or directly useful. The file's modification time bytes, for instance, became a jump instruction pointing further down into the data, past the header and into working code.

The craft sits in the intersection of three constraints. The same bytes had to be non-crashing CPU instructions, useful setup code for the boot process, and a still-valid ZIP file header. Meeting any two is an exercise; meeting all three, according to the developer, was far trickier than the summary suggests. He has published the full details in a blog post for readers who want the byte-level accounting.

The project has no commercial bearing, and that is rather the point. It demonstrates that format parsers and boot firmware agree on very little, and that a sufficiently determined author can make one file satisfy all of them at once. Expect the technique to reappear, in less playful contexts, wherever input validation still assumes file formats are single-purpose.

Source: Tom's Hardware

Share this article:

More from Nathan Brooks

Nathan Brooks

Show full bio

Senior reporter covering people, launches and day-to-day practice in Semiconductors, chip manufacturing, hardware, AI compute at Chip Dispatch.

1,010 articles

Related articles

« Previous articleNext article »