Hide any type of information inside an image

Some FBI stuff huh? Yeah, you can say that

Ayush Shah
4 min readSep 15, 2021
Photo from WIRED

In this post, we are going to discuss about how can we hide information inside an image using cmd on your computer; no need to download additional software or tools. You will need a zip extractor program to extract the information from image. I have kept this simple and basic so that everyone can use this with basic computer knowledge.

What is Steganography?

Steganography is the technique of hiding secret data within an ordinary looking, non-secret, file or message to avoid being sus. There are a vast number of methods and techniques in Steganography ranging from basic to advanced level.

Fun fact: Many secret agencies and hackers use Steganography, but at an advanced level.

While you can find a lot of methods on the internet in which you can do this using some Python library or downloading some tool (or something else), the method we are using is a basic one with no tools required. First of all, I want you to compare the two images below:

Cute cat image by Edgar on Unsplash
Same image, but with stored information

Both images look the same right? You can’t differentiate between them. That’s called Steganography. The second image contains two mp3 music files, one text file, and one Python hello-world program file hidden inside it.

Now without wasting time, let’s learn how to do that

First of all, choose an image in which you want to hide the information. I am using the same above image named cat.jpg. Image file should not have blank spaces in the name. For example, cute cat.jpg won’t work.

Now, make a new folder at the same location of image file. I am making a folder named secret. Copy all the files/information you want to hide inside the folder.

Don’t use spaces in the name of image file or the folder.
Right-click the folder and convert it to zip file.
Don’t use spaces in the name of the zip file.

After right-click: select (or point to) Send to, and then select Compressed (zipped) folder to convert it to zip file.

At this point we have three things in the directory:

  • cat.jpg image file
  • secret folder containing all information
  • secret.zip file

Now press windows key, type cmd and hit enter. Go to the directory where all the files are located using cd command or simply use this pro tip.

Pro tip: At the location of files (no files selected), Shift + Right-click and select Open Command window here. No need to use cd command.

Being at proper directory in cmd, type (replace zip file and image name with yours):

copy /b imagefile.jpg + zip_file.zip new_image.jpg

Replace:

  • imagefile.jpg with your image file name with proper image extension.
  • zip_file.zip with the name of your zip folder.
  • new_image.jpg with any name but with same image extension.

new_image.jpg is the new produced image with all the hidden information.
You can name it anything of your choice. Just don’t use spaces in the name.

Note:
If your image file is of any other format such as .png, then replace .jpg in the above command with the respected format.

Example of the cat image:

copy /b cat.jpg + secret.zip cute_cat.jpg

The cat.jpg and secret.zip files are combined into one cute_cat.jpg image.

Understanding the code

The copy /b command treats the files as binary and copies both files byte-for-byte instead of the default text behaviour. In short, it copes all the binary bytes into one file.

What is binary?
Binary is a base-2 number system that is made up only two numbers, i.e. 0 and 1. When data is stored on a computer, it is stored in the form of binary. A binary file could therefore refer to any computer file, as they are all made up of binary numbers.

How does this hide information inside the image?
You cannot simply copy the bytes from two binary files and expect them to work because binary files usually have headers, metadata, data structures, etc. that define the format of the file.

Copying will simply mean combining all the bytes of the files as it is into one which ends up putting these structures in places that they should not be, so when you open them, the parsing function will have trouble and see what is essentially corrupt data. Some programs will ignore the parts that don’t make sense and simply show what they can (which allows for steganography to work), in our case only the image is shown.

That’s it. You have learned how to store information inside images!

But wait, how to extract the information from the image?

You can use any zip extractor program of your choice to extract the information. Some of the most popular programs are 7zip and WinRAR.

  • Right-click on the image file, and you will find an option to extract or open the image with the installed zip extractor program.
  • If not, then open your zip extractor program and open the image manually there and you will be able to extract the information.

Go and try yourself now!

On a side note

I have made a program that automatically compresses the files, create zip, and produce the new image with hidden data. You just have to run it and type the image name. That’s it!

You can check it out on Github.

--

--