Hide Data In Plain Sight Using Steganography?

Steganography is the art of hiding one file into another to stealthily pass on information without arousing any suspicion. In this module, we are going to learn how we can hide our data in a media file on Linux.

Introduction to Steganography

As we said, Steganography helps us hide data in different types of media files. The data can even be encrypted with a passphrase so as to prevent unwanted access to the sensitive information contained within. For demonstration purposes, we will hide a simple text file in this image of the Tux Penguin:

Tux Mascot
Tux Mascot

Prerequisites for hiding data in images

For our intents and purposes, we would use a program called steghide but first we need to install the following dependencies with the apt command:

$ sudo apt install -y libjpeg-dev libmcrypt-dev libmhash-dev

Next up, we need to install the package itself with:

$ sudo apt install steghide

Thus we have our tools ready and now we can move onto the next step

Hiding Our Secret File In The Media File

Now, we will hide our secret text file in our JPEG image. First let’s generate the md5sum of our image with :

$ md5sum Tux.jpg 
52de2bedf7374c758dcb4a88027f8b81  Tux.jpg

Next generate a file to hide into our image and generate it’s md5sum as well:

$ echo "This Is A Super Secret Document" > Secret.txt
$ tmp md5sum Secret.txt 
f886e930e3180f49fb0b4a6cbfc4ce55  Secret.txt

Now to hide our text file in our image using steghide, we use the following syntax :

$ steghide embed -cf <Media File> -ef <Secret File >

Thus in our case, this would look like :

$ steghide embed -cf Tux.jpg -ef Secret.txt 
Enter passphrase: 
Re-Enter passphrase: 
embedding "Secret.txt" in "Tux.jpg"... done

Breaking down the command:

  • steghide : This is the name of the program we are using to hide our files
  • embed : It tells the program that we are going to embed information
  • -cf : Specify The Cover file, aka the Media file (Tux.jpg)
  • -ef : Embed file, aka the file we want to hide (Secret.txt)

You can also encrypt the secret file with a passphrase for an added layer of security.

If we check the md5sum of our file now, we would see a different value than before which signifies that the contents of the file have been changed.

$ md5sum Tux.jpg 
639a806d89f42c8670fda0ba344aa6e0  Tux.jpg

Hence, our text file was successfully hidden in the image !

Extract Data From Images

Now we will extract secret information from a Media File modified with steganography. Make sure that you have removed the original file, and after that, you can extract your secret file with:

$ steghide extract -sf <File Name>

For example, in our case, it would look somewhat like this :

$ steghide extract -sf Tux.jpg

Here,

  • steghide‘ is the name of our program with which we are going to use to extract our secret data
  • extract‘ instructs our program to extract data from a given file
  • -sf‘ flag indicates the stego file, aka the file from which we are going to extract our data

This should prompt you for a password, and on success, your secret file should be extracted !

$ steghide extract -sf Tux.jpg
Enter passphrase: 
wrote extracted data to "Secret.txt".

You can even verify the integrity of the file by checking it’s md5sum :

$ cat Secret.txt 
This Is A Super Secret Document
$ md5sum Secret.txt
f886e930e3180f49fb0b4a6cbfc4ce55  Secret.txt

Thus our secret has been preserved!

Conclusion

I hope you now understand the concept of steganography and have learned to successfully hide a text file in an image. Apart from images, you can also hide data in audio files. Steghide supports hiding JPEG, BMP, WAV and AU file formats as cover files. You can always refer to the man pages for more information!