SRL Archive - C/C++ Help and Tutorials

PNG Image Steganography


Yakman

2009-11-17 18:45:43

Can you tell the difference between these images?






The first one is the original, and the rest have files hidden inside them by flipping bits.
The second uses the last bit of every pixel, the third image uses the last 2 bits and the last image uses the last 4 bits. It is distorted noticeably but the rest are almost undetectable to the naked eye.

http://en.wikipedia.org/wiki/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."


And now, my dear SRL, I present to you my own implementation, written in c. Attached to this post.


The files I hid in the pictures of the car are almost random, I got them from my swap disk and split it until it almost filled the image to capacity. Its a worst cast scenario.

If you want to extract from those images, here are the md5sums in case you want to check.

md5sums for the files hidden in output1.png 2.png and 4.png

a126ce1e7342edc51fd6ae21dc9ca15f message.txt
d863a0408f2cd9151d4c609a83cf12d5 message.txt
ea0f8d5cbedd61c2edc17ae6762ec5f0 message.txt


My code uses the LodePNG library for processing png images. It includes a makefile.


Here is another example.

original

hidden file n last 4 bits



to use it, download and extract the zip file.
run

make
to build


to extract from image picture.png and save to new file message.txt, run

png e picture.png message.txt

to hide file message.txt into the image picture.png using the last 2 bits of every byte, run.

png h2 picture.png message.txt


before you hide, you may want to learn the maximum file size your image can hold. run

png c picture.png

example output

$ ./png c input1.png
capacity of input1.png:
BitPerByte Capacity / bytes
1 239967
2 479983
4 959991

WT-Fakawi

2009-11-17 18:55:21

Wow. Crazy. Technically out-of-my-league, but very intriguing…and usefull too. Anxious to know what's in the box :)

ShowerThoughts

2009-11-17 19:08:51

Sounds pretty awesome, and I understand the talking about it, but that's it :p.

mixster

2009-11-17 19:21:43

Be in awe of the Russian dolls! 3 pics in 1.

Edit:
Quite large so hyperlinked instead image!

Yakman

2009-11-17 19:46:25

Hey good idea mixster.



The mechanism of how this works is actually quite simple, except I did a bad job of explaining it in my first post.


As I'm sure you know, images are made up of a list of pixels, each pixel can be represented as 4 bytes, each containing the red, green, blue and alpha component.

My program relies on the fact that if you change the low bit, you effectively change the number 255 to 254, almost invisible to the human eye.

Now suppose I wanted to hide the number 74 which is 01001010 in binary. I have an image made up of 2 pixels, containing 4 bytes each.

All we do is just cycle though each bit of the number and copy it into the last bit of each image byte.

Number = 01001010

Unmodded image =
11111111 10101000 01011010 01101001 11111111 10111101 01110000 01100001

Modified image =
11111110 10101001 01011010 01101000 11111111 10111100 01110001 01100000



Or if I want to make it really obvious whats happened.
Modified image =
11111110 10101001 01011010 01101000 11111111 10111100 01110001 01100000


Thats all there is to it. :)

NCDS

2009-11-17 20:01:34

Intense.

Dan Cardin

2009-11-17 20:34:33

yea, i tried quite hard, but i could only tell the difference between the first 3 and last

boberman

2009-11-18 00:25:51

I've done this before, and it is pretty neat. The problem with stenography is the fact that most is completely security through obscurity.

Might I make a suggestion for a better stenographic algorithm?

Use RSA to determine where each bit should be placed. This requires keeping track of where former bits have been placed, but makes the displacement of bits seem almost completely random (In normal stenographic images, there are noticeable lines). To use an RSA like password, I would take the text password, and then use BlumbBlumbShub on it until I had a couple of prime numbers sufficiently large enough for your security purposes.

Thus, without the correct password, the data is very hard to retrieve. It adds the benefit of a strong crypto algorithm on top of the obscurity of stenography in the first place.

BTW, Stenography works best with not digital photos. People expect digital photos to be smooth. They do not, however, expect a real life photo to be smooth, thus they interpret the extra bits as grain instead of useful data.

Yakman, if you like, I could post some RSA / BlumbBlumbShub code that I have.

(Yes, I've played with stenography, it is fun to dink around with :))

super_

2009-11-23 11:53:36

nice work yakman. reminds me of hackthissite… is that site still alive?

Floor66

2009-11-23 12:14:43

From: boberman
I've done this before, and it is pretty neat. The problem with stenography is the fact that most is completely security through obscurity.

Might I make a suggestion for a better stenographic algorithm?

Use RSA to determine where each bit should be placed. This requires keeping track of where former bits have been placed, but makes the displacement of bits seem almost completely random (In normal stenographic images, there are noticeable lines). To use an RSA like password, I would take the text password, and then use BlumbBlumbShub on it until I had a couple of prime numbers sufficiently large enough for your security purposes.

Thus, without the correct password, the data is very hard to retrieve. It adds the benefit of a strong crypto algorithm on top of the obscurity of stenography in the first place.

BTW, Stenography works best with not digital photos. People expect digital photos to be smooth. They do not, however, expect a real life photo to be smooth, thus they interpret the extra bits as grain instead of useful data.

Yakman, if you like, I could post some RSA / BlumbBlumbShub code that I have.

(Yes, I've played with stenography, it is fun to dink around with :))


Do you have like… A GUI where the magic is done? ;)

Wizzup?

2009-11-23 13:23:22

From: Floor66
Do you have like… A GUI where the magic is done? ;)


Real men don't use GUI's.

Floor66

2009-11-23 13:25:09

Hmm what about .bat / console ? :p (I don't use GUI's often tbh)

Wizzup?

2009-11-23 13:55:04

From: Floor66
Hmm what about .bat / console ? :p (I don't use GUI's often tbh)


I was thinking about bash. :p

n3ss3s

2009-11-23 15:36:04

From: NCDS
Intense.


Took the words out of my mouth.

mrpickle

2009-11-23 18:14:46

Whoa.

Freddy1990

2009-11-26 04:47:45

From: Wizzup?
Real men don't use GUI's.


Neither do cavemen ;)

mixster

2009-11-26 11:45:34

Cavemen didn't have computers silly.

Dan Cardin

2009-11-26 21:18:51

From: mixster
Cavemen didn't have computers silly.

said the liar to the beached whale!

Wizzup?

2009-11-27 06:33:10

From: Dan Cardin
said the liar to the beached whale!


I'm beached bro? I'm beached as!

Anyway… It's a cool way of encrypting data, yakman. ;)

NiCbaZ

2009-11-27 15:34:22

From: Wizzup?
Real men don't use GUI's.


Big man.

R0b0t1

2010-06-05 05:08:50

Might want to more evenly disperse the data into the picture. It seems that the pictures accumulate a "green shift". This might depend on the data, but it's happened to everything I've done so far… It would help if this could be remedied, as the human eye is really only good at looking for patterns, and "green" is certainly a distinguishable pattern. Also, if a file is less than the picture, split it up so that a bit is every n bytes, so it is harder to see.

I forget how PNG stores the image data, so you might have to do a few sets of storing in the specified bits, then the next, and so on, to avoid fucking up the image completely.

EDIT

To illustrate my point, here is an image with the two things I am talking about. You will see the background, which, due to it being an oil painting, has many swirls and color variations. You will also see the shirt, which is mainly black. There is a semi-checked pattern amongst the whole image, yet this is only noticeable on his shirt; there is also a stark dividing line. Try to find differences in the background. You will see a slight green-shift that I mentioned before, but it is relatively hard to see without looking. NOTE: If you have a large monitor and can see both pictures at once, it might appear obvious, but only because of the line. I put a zip file in this, so the tree takes up the first part, ergo, the density in bits making the picture white. I couldn't find a picture big enough to put text into, the program erred with code 75.



Yakman

2010-07-03 11:29:21

Russian spies used this technique.
http://www.newscientist.com/article/dn19126-russian-spy-ring-hid-secret-messages-on-the-web.html

dwimage

2013-06-06 22:49:02

awesome and powerful, i know the technique

Peanuts

2013-06-06 23:06:50

That's awesome..
Totally out of my depth.. But awesome, lol.

EDIT: God damn.. Grave dug..

This kid before me put it on the new posts page…

Ass.

adlena

2013-06-24 05:39:56

nice post