cedricbonhomme / Stegano

A pure Python steganography module.
https://stegano.readthedocs.io
GNU General Public License v3.0
527 stars 69 forks source link

Error when revealing a hidden binary file #12

Closed furiml closed 7 years ago

furiml commented 7 years ago

Hello, first of all thank you for a wonderful module, I'm using it to learn steganography. I successfully hid and revealed text messages in images, but I'm having trouble revealing a hidden file within an image. I created a small bitmap image, and hid it in another picture : lsb hide -i ./picture.png -f ./small.bmp -o ./picture_steg.png No problem, picture_steg.png is created, but when revealing it, I've got this :

>$ lsb reveal -i ./picture_step.png -o ./small_decode.bmp
Traceback (most recent call last):
  File "/usr/local/bin/lsb", line 91, in <module>
    data = tools.base642binary(secret)
  File "/usr/local/lib/python3.6/site-packages/stegano/tools.py", line 101, in base642binary
    b64_fname += b'==='
TypeError: must be str, not bytes

I've looked into the tools file, but can't figure out where the problem is coming from. Can you help ?

cedricbonhomme commented 7 years ago

Hi, thanks for the report. I think that I see where is the problem. I'll fix that as soon as possible.

cedricbonhomme commented 7 years ago

Hi, I have a fix. I just had to make some tests and deploy a new minor version on pypi.

furiml commented 7 years ago

Hello, I'm still getting an error when revealing a hidden text file within an image :

Traceback (most recent call last):
  File "/usr/local/bin/lsb", line 84, in <module>
    data = tools.base642binary(secret)
  File "/usr/local/lib/python3.6/site-packages/stegano/tools.py", line 95, in base642binary
    b64_fname += '==='
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

This function seems lazy and don't want to work :)

cedricbonhomme commented 7 years ago
$ sudo -H pip3.5 install --upgrade Stegano
$ git clone https://github.com/cedricbonhomme/Stegano.git
$ cd Stegano/
$ lsb hide -i tests/sample-files/Montenach.png -f tests/sample-files/lorem_ipsum.txt -o ~/secret.png
$ lsb reveal -i ~/secret.png -o ~/secret.txt
$ cmp tests/sample-files/lorem_ipsum.txt ~/secret.txt

Can you please test the code above? If it is working and it is still not working with your image/file, can you give me the command you are using? or maybe even the files? (I never had 'NoneType' in this error message)

When you hide a file, it is base64 encoded. So when reveal a secret you also have to output the result in a file ('-o' option of lsb reveal). If you do not specify the '-o' option you will see the base64 representation of the file. You can make the comparison when using Stegano as a Python module: https://github.com/cedricbonhomme/Stegano/blob/master/tests/test_lsb.py#L83 (test_with_text_file and test_with_binary_file)

I admit that this is too complicated for non-binary files. But I am actually working on more major improvements in the "unicode" branch of this repo. This will be an opportunity to harmonize all the different cases. The main motivation of this branch is to hide UTF-8 characters easily (https://github.com/cedricbonhomme/Stegano/blob/unicode/tests/test_lsb.py#L66).

furiml commented 7 years ago

Hello, The code you provided worked flawlessly, the two files are identical. I also tested it with my files, and it worked :) Considering my previous post, I figured out where I did wrong : I used a jpeg file instead of a png.

Thanks

cedricbonhomme commented 7 years ago

Cool! Thank you for the test!