Skip to content

Instantly share code, notes, and snippets.

@SoniEx2
Last active August 27, 2016 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoniEx2/60a025d5901f67b2e549dca4a0ba7d46 to your computer and use it in GitHub Desktop.
Save SoniEx2/60a025d5901f67b2e549dca4a0ba7d46 to your computer and use it in GitHub Desktop.
EPNG spec

EPNG - Executable PNG

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Version: 0.2

Authors: Check Commit Log.

Rationale

Sometimes we want an image associated with a program or script.

Some operating systems, such as Windows, have an icon mechanism for that, while others, such as Linux, don't.

There are also esoteric programming languages and domain specific languages based on images. On Linux, they have to be manually passed to the interpreter, as PNGs don't support a shebang.

The exEc Chunk

Bytes 0-3: Reserved. 00 00 00 00 as of this version.
Bytes 4-n: Executable data (raw data from a file).

This chunk contains the bytes 00 00 00 00 followed by executable data. Attempting to execute a PNG which has this chunk should be equivalent to executing the 'executable data' part of this chunk as a file/standalone executable.

If this chunk appears multiple times in an EPNG, each chunk should be tried, until the first one to execute. (Doesn't have to execute successfuly, just has to execute.)

File managers should ask the user whether they want to execute or display the PNG file. File managers may choose to always display the PNG file, even if they recognize the EPNG chunks.

Example

The exEc chunk containing #!/usr/bin/env xdg-open should open the image in the default image viewer, given a system with xdg-open and GNU coreutils installed.

This is equivalent to embedding the following executable file in the PNG:

#!/usr/bin/env xdg-open

When executing the PNG, it should be treated as the above file. That is, it should be equivalent to running the above file.

Security Considerations

I never heard of a system that attempts to execute PNG files. This should be safe on any modern system. This adds no new practical vulnerabilities, as any exploits you'd do with this can already be done more efficiently with other mechanisms.

@glennrp
Copy link

glennrp commented Aug 6, 2016

Example 2:
000cexEc0000rm -rf /XXXX where XXXX is the crc.

@SoniEx2
Copy link
Author

SoniEx2 commented Aug 7, 2016

@glennrp "#!/usr/bin/env rm -rf /", actually. This is better than "#!" because you need to put a "#!" inside the exEc chunk to run an arbitrary command. It's like the system treats the exEc chunk as the file itself, for the purposes of executing it. (Note, however, that any interpreter for such PNGs needs to be PNG-aware because the path passed to it is the path to the PNG file.)

Also, this is backwards-compatible, unlike adding a "#!" to PNGs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment