示例#1
0
def decode(request):
    if request.user.is_authenticated:
        if request.method == "POST":
            owner = str(request.POST['owner_name'])
            key = str(request.POST['custom_key'])
            uploaded_filename = save_upload_image(
                request.FILES['image_decode'], 'download')
            try:
                fkey = Stega.objects.get(username=owner, user_key=key)
                msg_img = exifHeader.reveal(uploaded_filename).decode()
                fkey = fkey.fernet_key
                f = Fernet(fkey.encode())
                org_msg = f.decrypt(msg_img.encode()).decode()
                os.remove(uploaded_filename)
                messages.success(
                    request,
                    "Success the stored information is displayed below")
                return render(request, 'menu/decode.html', {'data': org_msg})
            except:
                messages.error(request,
                               "Please check the file, key and owner name")
                return render(request, 'menu/decode.html')

        else:
            return render(request, 'menu/decode.html')
    else:
        return redirect('%s' % (settings.LOGIN_URL))
示例#2
0
    def test_with_png_image(self):
        secret = exifHeader.hide("./tests/sample-files/Lenna.png",
                                "./image.png", secret_message="Secret")
        #secret.save(""./image.png"")

        with self.assertRaises(ValueError):
            clear_message = exifHeader.reveal("./image.png")
示例#3
0
 def retr(self, filename):
     self.filename = filename
     img = Image.open(filename)
     binary = ''
     # Getting file extension
     temp = "." + self.fileExtractor(filename, '.').lower()
     # For png & ico images
     if (temp == '.png' or temp == '.ico'):
         if img.mode in ('RGBA'):
             img = img.convert('RGBA')
             datas = img.getdata()
             for item in datas:
                 digit = self.decode(self.rgb2hex(item[0], item[1],
                                                  item[2]))
                 if digit == None:
                     pass
                 else:
                     binary = binary + digit
                     if (binary[-16:] == "1111111111111110"):
                         return str(self.bin2str(binary[:-16]))[2:-1]
             return str(self.bin2str(binary))
     # For jpeg & jpg images
     else:
         message = con.reveal(filename)
         message = str(message)[2:-1]
     return message
示例#4
0
文件: app.py 项目: JonW27/bstego2.0
 def POST(self):
     input = web.input(file={})
     filename = input['file'].filename
     fileds = input['file'].value
     if filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.jpeg') and filename.count('/') == -1:
         os.chdir('static/files')
         with open(filename, 'wb') as fout:
             shutil.copyfileobj(input['file'].file, fout, 100000)
         os.chdir('../../')
         # do NOT touch above code
         if filename.endswith('.png'):
             return '''
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                     <title>Attempted to Decode</title>
                     <meta charset="utf-8">
                 </head>
                 <body>
         '''+lsb.reveal("static/files/"+filename)+"<p>Message decoded should be above.</p></body></html>"
         if filename.endswith('.jpg') or filename.endswith('.jpeg'):
             return '''
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                     <title>Attempted to Decode</title>
                     <meta charset="utf-8">
                 </head>
                 <body>
         '''+exifHeader.reveal("static/files/"+filename)+"<p>Message decoded should be above.</p></body></html>"
示例#5
0
文件: geary.py 项目: JonW27/bStego
def main():
	print HTML_HEADER
	print HEAD
	data = cgi.FieldStorage()
	fileds = data['file']
	if fileds.filename.endswith('.jpg') or fileds.filename.endswith('.png') or fileds.filename.endswith('.jpeg') or fileds.filename.endswith('.tiff') and fileds.filename.count('/') == -1:
	    os.chdir('files')
	    with open(fileds.filename, 'wb') as fout:
	        shutil.copyfileobj(fileds.file, fout, 100000)
        os.chdir('../')
        # do NOT touch above code
        if fileds.filename.endswith('.png'):
            print lsb.reveal("files/"+fileds.filename)
        if fileds.filename.endswith('.jpg') or fileds.filename.endswith('.jpeg'):
            print exifHeader.reveal("files/"+fileds.filename)
        print "<p>Attempted to decode.</p>"
	print END
示例#6
0
    def test_with_bytes(self):
        outputBytes = io.BytesIO()
        message = b"Secret"
        with open("./tests/sample-files/20160505T130442.jpg", "rb") as f:
            exifHeader.hide(f, outputBytes, secret_message=message)

            clear_message = exifHeader.reveal(outputBytes)
            self.assertEqual(message, clear_message)
示例#7
0
    def test_with_png_image(self):
        secret = exifHeader.hide("./tests/sample-files/Lenna.png",
                                 "./image.png",
                                 secret_message="Secret")
        #secret.save(""./image.png"")

        with self.assertRaises(ValueError):
            clear_message = exifHeader.reveal("./image.png")
示例#8
0
    def test_with_image_without_exif_data(self):
        secret = exifHeader.hide("./tests/sample-files/Elisha-Cuthbert.jpg",
                                "./image.jpg", secret_message="")
        #secret.save(""./image.png"")

        clear_message = exifHeader.reveal("./image.jpg")

        self.assertEqual(b"", clear_message)
    def deimg():
        if secimg.get() == "png":
            messag = lsb.reveal(fileopen)

        if secimg.get() == "jpeg":
            messag = aaa.reveal(fileopen)

        Label2 = Label(text=messag)
        Label2.place(relx=0.7, rely=0.7, height=21, width=204)
示例#10
0
    def test_with_image_without_exif_data(self):
        secret = exifHeader.hide("./tests/sample-files/Lenna.jpg",
                                 "./image.jpg",
                                 secret_message="")
        #secret.save(""./image.png"")

        clear_message = exifHeader.reveal("./image.jpg")

        self.assertEqual(b"", clear_message)
示例#11
0
    def test_with_bytes(self):
        outputBytes = io.BytesIO()
        message = b"Secret"
        exifHeader.hide(open("./tests/sample-files/20160505T130442.jpg", 'rb'),
                            outputBytes,
                            secret_message=message)

        clear_message = exifHeader.reveal(outputBytes)
        self.assertEqual(message, clear_message)
示例#12
0
    def test_hide_empty_message(self):
        """Test hiding the empty string."""
        secret = exifHeader.hide("./tests/sample-files/20160505T130442.jpg",
                                 "./image.jpg",
                                 secret_message="")
        # secret.save(""./image.png"")

        clear_message = exifHeader.reveal("./image.jpg")

        self.assertEqual(b"", clear_message)
示例#13
0
    def test_with_text_file(self):
        text_file_to_hide = "./tests/sample-files/lorem_ipsum.txt"
        with open(text_file_to_hide, "rb") as f:
            message = f.read()
        secret = exifHeader.hide("./tests/sample-files/20160505T130442.jpg",
                                 img_enc="./image.jpg",
                                 secret_file=text_file_to_hide)

        clear_message = exifHeader.reveal("./image.jpg")
        self.assertEqual(message, clear_message)
示例#14
0
    def test_with_text_file(self):
        text_file_to_hide = "./tests/sample-files/lorem_ipsum.txt"
        with open(text_file_to_hide, "rb") as f:
            message = f.read()
        secret = exifHeader.hide("./tests/sample-files/Elisha-Cuthbert.jpg",
                            img_enc="./image.jpg",
                            secret_file=text_file_to_hide)

        clear_message = exifHeader.reveal("./image.jpg")
        self.assertEqual(message, clear_message)
示例#15
0
    def test_hide_empty_message(self):
        """Test hiding the empty string.
        """
        secret = exifHeader.hide("./tests/sample-files/20160505T130442.jpg",
                                "./image.jpg", secret_message="")
        #secret.save(""./image.png"")

        clear_message = exifHeader.reveal("./image.jpg")

        self.assertEqual(b"", clear_message)
示例#16
0
    def test_hide_and_reveal(self):
        messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]

        for message in messages_to_hide:
            secret = exifHeader.hide("./tests/sample-files/20160505T130442.jpg",
                                    "./image.jpg", secret_message=message)

            clear_message = exifHeader.reveal("./image.jpg")

            self.assertEqual(message, message)
示例#17
0
def main():
    print HTML_HEADER
    print HEAD
    data = cgi.FieldStorage()
    fileds = data['file']
    if fileds.filename.endswith('.jpg') or fileds.filename.endswith(
            '.png') or fileds.filename.endswith(
                '.jpeg') or fileds.filename.endswith(
                    '.tiff') and fileds.filename.count('/') == -1:
        os.chdir('files')
        with open(fileds.filename, 'wb') as fout:
            shutil.copyfileobj(fileds.file, fout, 100000)
    os.chdir('../')
    # do NOT touch above code
    if fileds.filename.endswith('.png'):
        print lsb.reveal("files/" + fileds.filename)
    if fileds.filename.endswith('.jpg') or fileds.filename.endswith('.jpeg'):
        print exifHeader.reveal("files/" + fileds.filename)
    print "<p>Attempted to decode.</p>"
    print END
示例#18
0
    def test_hide_and_reveal(self):
        messages_to_hide = ["a", "foo", "Hello World!", ":Python:"]

        for message in messages_to_hide:
            secret = exifHeader.hide(
                "./tests/sample-files/20160505T130442.jpg",
                "./image.jpg",
                secret_message=message)

            clear_message = exifHeader.reveal("./image.jpg")

            self.assertEqual(message, message)
示例#19
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 decodee():
     message=stg.reveal(fileopen)
     message=str(message)
     message=message[2:-1]
     print(message)
     #message=int(message)
     message=message.split(",")
     message=list(map(int,message))
     print(p)
     dr_msg = decrypt(message, p,key,q) 
     message = ''.join(dr_msg)
     label4=Label(text=message)
     label4.config(font=("Courier", 30))
     label4.place(relx=0.3,rely=0.2)
示例#21
0
def read_wm(wm, ifpath):
    """ Returns 2 for STANDARD message read. Returns 3 for CUSTOM message read.
        Returns 1 for NO message read.
    """
    rt = 2
    if get_ftype(ifpath) in LSB: message = lsb.reveal(ifpath)
    elif get_ftype(ifpath) in EXIF: message = exifHeader.reveal(ifpath)
    else: return err_file_type_nsupported(get_ftype(ifpath))
    if not message: return 1
    try:
        message = json.loads(message)
    except:
        wm.custom = True
        rt = 3
    wm.data = message
    return rt
示例#22
0
    def decode_img_txt(self):  # Fn to decode our txt from our image

        sel_image = self.ids.decode_image_path.text  # getting the file location

        slash_count = sel_image.count("\\")  # getting the file location
        img_type = sel_image.split("\\", slash_count)[slash_count].split(
            ".", 1)[1]  # selecting only the file type with extension

        try:
            # checking the type of file first
            hidden_text = ""  # initializing a variable

            # img type is png
            if img_type == "png":

                # lsb for png
                # reveal is used to decode
                # it's parameter is the selected image
                hidden_text = lsb.reveal(sel_image)

            # img type is jpg/jpeg
            elif img_type == "jpg" or img_type == "jpeg":

                # exifHeader for jpg/jpeg
                # reveal is used to decode
                # it's parameter is the selected image
                hidden_text = exifHeader.reveal(sel_image)

            # checking if there is anything to be decoded
            if hidden_text is not "":

                self.ids.text_decoded.text = hidden_text
                self.ids.decode_result.text = "Decoding was successful"

            else:

                self.ids.text_decoded.text = ""  # setting the text as empty if there is nothing to decode
                self.ids.decode_result.text = "Nothing to Decode"
        except:

            # fail-safe
            self.ids.text_decoded.text = ""
            self.ids.decode_result.text = "Decoding has failed"
示例#23
0
 def POST(self):
     input = web.input(file={})
     filename = input['file'].filename
     fileds = input['file'].value
     if filename.endswith('.jpg') or filename.endswith(
             '.png'
     ) or filename.endswith('.jpeg') and filename.count('/') == -1:
         os.chdir('static/files')
         with open(filename, 'wb') as fout:
             shutil.copyfileobj(input['file'].file, fout, 100000)
         os.chdir('../../')
         # do NOT touch above code
         if filename.endswith('.png'):
             return '''
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                     <title>Attempted to Decode</title>
                     <meta charset="utf-8">
                 </head>
                 <body>
         ''' + lsb.reveal(
                 "static/files/" + filename
             ) + "<p>Message decoded should be above.</p></body></html>"
         if filename.endswith('.jpg') or filename.endswith('.jpeg'):
             return '''
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                     <title>Attempted to Decode</title>
                     <meta charset="utf-8">
                 </head>
                 <body>
         ''' + exifHeader.reveal(
                 "static/files/" + filename
             ) + "<p>Message decoded should be above.</p></body></html>"
示例#24
0
def reveal_file(currentos):
    if currentos == "windows":
        os.system("cls")
        #get image with hidden file
        img = input(colored("Image File Location -->> ","green"))
        #whitespace
        img = img.replace('"','')
        img = img.strip()
        #get message out
        message = exifHeader.reveal(img)
        message = message.decode()
        #save in tmp file
        with open("tmp",'w') as f:
            f.write(message)
        #get the file
        with open("tmp","r") as r:
            lines = r.read()
            lines = lines.splitlines()
            content = lines[:-1]
            lines = lines[-1]
            for x in content:
                with open("./Messages/"+lines,'a') as f:
                    f.write(x+"\n")
        print(colored("File Unhidden...","green"))
        print(colored("File Can Be Found Under Messages Folder "+lines,"green"))
        goto = input(colored("Type E(exit) M(Main menu) -->> ","green"))
        if goto.lower() == "e":
            os.system("exit")
        elif goto.lower() == "m":
            banner(currentos)
        else:
            print(colored("Wrong Input","red"))
            os.system("exit")  
    elif currentos == "linux":
        os.system("clear")
        #get image with hidden file
        img = input(colored("Image File Location -->> ","green"))
        #whitespace
        img = img.replace('"','')
        img = img.strip()
        #get message out
        message = exifHeader.reveal(img)
        message = message.decode()
        #save in tmp file
        with open("tmp",'w') as f:
            f.write(message)
        #get the file
        with open("tmp","r") as r:
            lines = r.read()
            lines = lines.splitlines()
            content = lines[:-1]
            lines = lines[-1]
            for x in content:
                with open("./Messages/"+lines,'a') as f:
                    f.write(x+"\n")
        print(colored("File Unhidden...","green"))
        print(colored("File Can Be Found Under Messages Folder "+lines,"green"))
        goto = input(colored("Type E(exit) M(Main menu) -->> ","green"))
        if goto.lower() == "e":
            os.system("exit")
        elif goto.lower() == "m":
            banner(currentos)
        else:
            print(colored("Wrong Input","red"))
            os.system("exit")
示例#25
0
#4.1 Написать программу, "прячущую" заданную строку в
# текстовый или графический контейнер. Предусмотреть
# извлечение текста из контейнера.

from stegano import exifHeader # импортируем библиотеку

message = input('Введите ваше секретное послание: \n') # пользователь программы вводит сообщение для зашифровки

secret = exifHeader.hide("img/urfu.jpg", "img/urfu_secret.jpg",f'{message}') # заданная строка прячется в графический контейнер

result = exifHeader.reveal("img/urfu_secret.jpg") # чтение изображения с посланием
result = result.decode() # расшифровка полученного сообщения

print(f'\nПослание, полученное при расшифровке изображения:\n{result}') # вывод расшифрованных данных
示例#26
0
from PIL  import Image
from PIL.ExifTags import TAGS
from stegano import exifHeader

#secret=exifHeader.hide("D:\\junction\\personal\\20200829_113745.jpg","ID.jpg",secret_message="Moatasem")
#print(exifHeader.reveal("ID.jpg").decode("UTF-8"))

image=Image.open("ID.jpg")
exifdata=image.getexif()

for tagid in exifdata:
    tagname=TAGS.get(tagid)
    value=exifdata.get(tagid)
    
    if tagname =="ImageDescription":
        print (exifHeader.reveal("ID.jpg").decode("UTF-8"))
    else:
        print(f"{tagname} :{value}")
示例#27
0
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)
        # with open(lines,'a') as f:
        #     f.write("%s\n"%x)
def jpg_tiff_decode(mfile_name):
    return exifHeader.reveal(mfile_name).decode()
示例#29
0
    if func == "-e":
        msg = input('Enter secret message:')
        trans = lsb.hide(file, message=msg)
        trans.save(file2)
        os.remove(file)
        os.rename(file2, file)
        print(' ')
        print('Message Successfully Hidden!!!')
    if func == "-d":
        message = lsb.reveal(file)
        print(' ')
        print('The Message Was:')
        print(message)

elif file.endswith('.jpg'):
    file2 = 'photo2.jpg'
    if func == "-e":
        msg = input('Enter secret message:')
        parser.hide(file, file2, msg)
        os.remove(file)
        os.rename(file2, file)
        print(' ')
        print('Message Successfully Hidden!!!')
    if func == "-d":
        message = parser.reveal(file)
        print('The Message Was:')
        print(message.decode('utf-8'))

else:
    print('FILE FORMAT NOT SUPPORTED.')
示例#30
0
 def Decoder():
     Message = stg.reveal(FileOpen)
     label3 = Label(text=Message)
     label3.place(relx=0.3, rely=0.3)
示例#31
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")
示例#32
0
    def decodee():
        message = stg.reveal(fileopen)

        label4 = Label(dnc, text=message, bd=3, font=('', 13))
        label4.place(relx=0.3, rely=0.3)
示例#33
0
def view(path):
    sms = exifHeader.reveal(path.get())
    msBox.showinfo("Revealed!!!", "Messasge is  " + sms.decode('UTF-8'))
示例#34
0
def decode(path):
    print('path is ', path.get())
    print(exifHeader.reveal(path.get()))
示例#35
0
def jpg_tiff_decode(mfile_name):
	return exifHeader.reveal(mfile_name).decode()