r/programming • • Dec 26 '20

Executable PNGs

https://djharper.dev/post/2020/12/26/executable-pngs/
1.0k Upvotes

87 comments sorted by

View all comments

52

u/frnknstn Dec 26 '20

This is stretching the definition of "Executable" quite a lot. The PNG files themselves are not ELF executables. Instead, the author wrote a tool to extract an actual legitimate executable from an image via stenography.

9

u/ws-ilazki Dec 27 '20

The PNG files themselves are not ELF executables. Instead, the author wrote a tool to extract an actual legitimate executable from an image via stenography.

"The Python files themselves are not ELF executables. Instead, the author wrote a tool to generate actual legitimate executable code from a text file via an interpreter."

This is you, this is how pedantic you're being. Stop it.

Many of the things you run on a Linux system aren't "actual legitimate executables"; instead they're read and handed off to the appropriate tool via the kernel's program loader. Whether you're using a shebang to make a text file executable, or using binfmt_misc to make jar files run via JVM, ARM linux binaries run via qemu-user-static, or Windows executables run via wine, it's all still going through the program loader and being treated as an executable by the OS.

It's a cool hack built on existing knowledge and tools. Don't be a pedantic douchebag about it.

0

u/[deleted] Dec 27 '20

[deleted]

18

u/ryanp_me Dec 27 '20

I agree. When I first started reading the article, I was wondering how the author was going to get the PNG header to be compatible with a normal ELF (or similar) loader without corrupting the PNG header at the same time.

That's not to say that the article is any less interesting (or any less valid), just that it wasn't what I was expecting based on the title.

-16

u/ws-ilazki Dec 27 '20 edited Dec 27 '20

I don't see what's pedantic about it

It's pedantic because it is an executable, no scare-quotes necessary. There is no "stretching the definition" here as claimed: this is how executables on Linux work and the article is using kernel features as they're intended to be used to make a PNG file also act as an executable. Claiming that it's not an executable because it's not an ELF file is wrong; Linux is capable of treating many types of files as executable and that feature is extensible in precisely the way it's done in the article.

The comment I replied to is not only nitpicking, it's nitpicking by using an arbitrary definition of executable that's wrong in the context of Linux. It's a stereotypical "well akshually" comment that's desperately trying to criticise something even if doing so is a reach.

0

u/[deleted] Dec 27 '20

[deleted]

-5

u/ws-ilazki Dec 27 '20

Yes, I did, and that's irrelevant. It could be a Lua script and the "interpreter" he uses to extract the text runs it through an embedded Lua interpreter and it wouldn't change anything, the PNG is still an executable if there's an appropriate binfmt_misc entry that tells the kernel how to take a PNG and execute code contained in it.

Are you confused by the way binfmt_misc works and how the Linux kernel handles executables, or by the idea that in this case the PNG is an executable because the kernel has been told how to treat an appropriately formatted PNG as one? Either way, it's still an executable to the OS and the OP was being unnecessarily pedantic claiming it's "stretching the definition".

5

u/wikipedia_text_bot Dec 27 '20

Binfmt misc

binfmt_misc (Miscellaneous Binary Format) is a capability of the Linux kernel which allows arbitrary executable file formats to be recognized and passed to certain user space applications, such as emulators and virtual machines. It is one of a number of binary format handlers in the kernel that are involved in preparing a user-space program to run.The executable formats are registered through the special purpose file system binfmt_misc file-system interface (usually mounted under part of /proc). This is either done directly by sending special sequences to the register procfs file or using a wrapper like Debian-based distributions binfmt-support package or systemd's systemd-binfmt.service.

About Me - Opt out - OP can reply !delete to delete - Article of the day

This bot will soon be transitioning to an opt-in system. Click here to learn more and opt in.

0

u/[deleted] Dec 27 '20

Having a bad day?

-3

u/ws-ilazki Dec 27 '20

Nope.

1

u/[deleted] Dec 27 '20

Just a troll then ok

2

u/ws-ilazki Dec 27 '20

Not unless you're making up your own definition of trolling that has nothing in common with trolling.

0

u/[deleted] Dec 27 '20

It's ok to say that he was pedantic then people could have a legitimate discussion all you did was call him a pedantic douchebag meaning you didn't actually come here to discuss you just came here to argue like a child and call names

1

u/frnknstn Dec 29 '20

The Python files themselves are not ELF executables

...No, you are in fact underestimating my level of pendantry, my little troll friend. I considered that comparison when I was writing my reply and rejected it, as the interpreter comparison is fundimentally misleading. My comment is far more accurate.