HeadlinesBriefing favicon HeadlinesBriefing.com

Hacker Shrinks Minimal ELF Executable to 79 Bytes

Hacker News •
×

A developer revisited their quest for the smallest possible ELF executable, responding to criticism that their original 45-byte creation wasn't truly compliant with the ELF specification. The challenge required balancing strict standards adherence against extreme size optimization, pushing the boundaries of what constitutes a valid executable file format.

Starting from a 91-byte conforming version, the author exploited ELF's allowance for overlapping data structures between headers and program sections. By carefully arranging the binary layout, they reduced the size to 83 bytes through strategic header overlap. The breakthrough came from repurposing the p_paddr field, which the spec marks as having unspecified contents.

Further optimization involved manipulating the load address to embed executable instructions within header fields. Moving to address 0x2AB30000 allowed the 'mov bl, 42' instruction to occupy space in the p_vaddr field, shaving the total down to 79 bytes. This demonstrates creative exploitation of ELF specification flexibility.

The remaining hurdle involves fitting the final 'inc eax' instruction while maintaining specification compliance. The author explores jumping over p_filesz into p_memsz, noting that inflating memory allocation beyond file size remains valid. This represents the current limit of header-embedded code placement.