Hi. This post is about Hiding Images with UNIX Utilities
The following article is about a small trick I learned on the internet. It concerns with how we can hide an image within another image. This will be done with just the standard UNIX utilities (no crazy steganography).
Albeit other ways exist, a simple method to achieve this is to simply append the main image to another one. All this time, we’ve been using the
cat command to view contents of a file. However, it was originally intended to be used to concatenate two files together. Most of the time, these files will be text-only but it behaves no different for binaries.
Let’s say I have the following two images:
One is an image of the Linux® mascot, tux:
Whereas the other one’s Beastie, the (Free)BSD® mascot.
I wish to hide little beastie inside the penguin. Here’s how to do that.
Let’s first take note of the size our beastie occupies.
Now we can proceed in two ways.
Either concatenate the two images together and redirect the output to a new file, say
Or we can simply
cat out the contents of
beastie.png and append the output to
In both cases, we can still view the image and we only see the penguin even though beastie is hiding inside.
Now that the storm is over, we can tell little beastie it’s okay and call him out. How would we do that?
Let’s bring back the size we recorded earlier. Our beastie image is
51873 bytes after the tux image data. So, we can just use
tail to extract the last
51873 bytes from the file containing the embedded image. Here, I use
tail and give it the
-c flag after which we can specify the number of characters to output from the end followed with a file as arguments. I will redirect the output to a different file called
beastie_back.png. Once again let’s do it for both the methods. But this time I will do show it in a single screenshot.
Additionally, we can use exiftool to embed the required size within the metadata of our images.