Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
avatar
Master Guru

Use Case

I want to hide text messages inside images. When the images arrive somewhere else, I want to extract those messages.

It let's you hide text in images, binaries in images and images in images.

I was interesting in hiding text messages in images. After seeing https://en.wikipedia.org/wiki/Turn:_Washington's_Spies I thought secret messages were cool.

So using the library, I take an image and text and hide the text in there. The library produces a new image (PNG) that has the message in it. I have a second script that extracts the text.

The images look the same to my eyes.

A future test would be to run a deep learning library or image analysis tool on the images to see if they spot the bits. They should be able to. A future NiFi tool would be to spot hidden images.

It's a fun exercise to use NiFi and it seems possible that encoding messages in images were passing through Niagra Files back in the NSA days.

13337-spydataflow.png

Step 1: Hide Text (ExecuteStreamCommand)

13338-spyhide.png

13351-spyencoderesults.png

Step 2: Fetch File

13339-spyfetchfile.png

Step 3: UnHide Text (ExecuteStreamCommand)

13340-spyunhide.png

13352-spysecretmessage.png

The left image is the original image and the right PNG is the output image with text. The size on disk has increased at a noticeable level.

13336-spy1.png

The python source code is in github and referenced below:

hide.sh

wget $1 -O img.jpg
python hidetext.py img.jpg "$2"

hidetext.py

import cv
from LSBSteg import LSBSteg

import sys
imagename=sys.argv[1]
textstring=sys.argv[2]
carrier = cv.LoadImage(imagename)
steg = LSBSteg(carrier)
steg.hideText(textstring)
steg.saveImage(imagename + ".png") 

#Image that contain datas

unhide.sh

python unhidetext.py $1

unhidetext.py

import cv
from LSBSteg import LSBSteg
import sysimagename=sys.argv[1]
im = cv.LoadImage(imagename)steg = LSBSteg(im)
print steg.unhideText()

For installation, you need to download LSB-Steganography script.

OpenCV

pip install cv

Reference:

https://en.wikipedia.org/wiki/Steganography

https://github.com/tspannhw/spy

https://github.com/RobinDavid/LSB-Steganography

1,958 Views