1 de noviembre de 2012

Steganography

Seguridad de la Información y Criptografía
Homework 8 - Program 4

The hidden code in the images of the last publication was in the images 1, 2 and 5

The homework was create a program to hide a text in an image file or an audio file, it is called Steganography.

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity. [1]

I create two python programs, one for hide the text (in this case my own code), and other for get again the hidden text.

First of all, I read the PDF that is at the end of this publication, where they explain why is common to hide text in bitmap images, and a introduction to how to change data of the image.

A little introduction about the bitmap images, is how the bytes are arranged, the next is what information is stored in the first bytes of the file.

Header of the file:
Bytes - Description
0-1 Bitmap identifier (BM)
2-5 Bitmap file size
6-9 Reserved
10-13 Bitmap data offset

Information about the file:
Bytes - Description
14-17 Bitmap header size
18-21 Bitmap image width
22-25 Bitmap image height
28:29 Bitmap color depth
26-27 Number of color planes
28:29 Bitmap color depth
30-33 Bitmap compression method
34-37 Bitmap data size
38-41 Bitmap image horizontal rule
42-45 Bitmap image vertical resolution
46-49 Number of colors used
50-53 Number of important colors used

*Information extracted from the PDF in the references.

The rest of the bytes are the image information. In my case I used images with a extension of color of 32 bits per pixel, so are 4 bytes in each pixel, we know that colors are composed by three elemental color, and a fourth in this case that is the "transparent color", (red, green, blue, alpha).

I only made changes in the byte of color red. Per byte we have 8 bits, and I only used the last bit to hide one bit of the complete hidden code.

Example:
If the letter "i" in binary is 01101001, in the first 8 bytes where the color red is stored, I change something like that.

Original - Changed
01010011 - 01010010
01010000 - 01010001
01001101 - 01001101
01001110 - 01001110
01001011 - 01001011
01001001 - 01001000
01001010 - 01001010
01001001 - 01001001

Code



The first parameter in the program is the original bitmap file, then a file with the code and the name of the new image.

~$ python stegano.py "images/rmn-01.bmp" "code_file" "rmn-01.bmp"
Identifier  BM
File size 810054
Reserved 0
Data offset 54
Width  450
Height  450
Text file size 2315
~$

The file with the code look like this.


Then the program to find the code in the image.


In this case the program only needs the bitmap file with the hidden code, and a file name to save the text.

~$ python decode.py "rmn-01.bmp" "decoded"
Image size 810054
~$

If we open the file created, we can see the code in it. After the end of the code we have waste information, because we don't know how many bytes had the original code_file. If we don't want to have waste information at the end, we can include in an specific array of bytes in the beginning, the length of the hidden text.


Image without the hidden text


Image with the hidden text


References:
[1] - Steganography - Definition
Introduction to Bitmap Steganography

1 comentario:

  1. ihqu:Downloads elisa$ python ramon.py ramon.bmp out
    Image size 70652
    ihqu:Downloads elisa$ less out
    "out" may be a binary file. See it anyway?
    - usando una de las imágenes que decías que tiene un mensaje... Además me hubiera gustado que fuese un sólo programa con los dos modos de operación. Van 8 pts.

    ResponderEliminar

Nota: solo los miembros de este blog pueden publicar comentarios.