Beispiel #1
0
def embed(imgFile, payload, password):
    # Process source image
    img = Image.open(imgFile)
    (width, height) = img.size
    conv = img.convert("RGBA").getdata()
    print "[*] Input image size: %dx%d pixels." % (width, height)
    max_size = width * height * 3.0 / 8 / 1024  # max payload size
    print "[*] Usable payload size: %.2f KB." % (max_size)

    f = open(payload, "rb")
    data = f.read()
    f.close()
    print "[+] Payload size: %.3f KB " % (len(data) / 1024.0)

    # Encypt
    cipher = AESCipher(password)
    data_enc = cipher.encrypt(data)

    # Process data from payload file
    v = decompose(data_enc)

    # Add until multiple of 3
    while (len(v) % 3):
        v.append(0)

    payload_size = len(v) / 8 / 1024.0
    print "[+] Encrypted payload size: %.3f KB " % (payload_size)
    if (payload_size > max_size - 4):
        print "[-] Cannot embed. File too large"
        sys.exit()

    # Create output image
    steg_img = Image.new('RGBA', (width, height))
    data_img = steg_img.getdata()

    idx = 0

    for h in range(height):
        for w in range(width):
            (r, g, b, a) = conv.getpixel((w, h))
            if idx < len(v):
                r = set_bit(r, 0, v[idx])
                g = set_bit(g, 0, v[idx + 1])
                b = set_bit(b, 0, v[idx + 2])
            data_img.putpixel((w, h), (r, g, b, a))
            idx = idx + 3

    steg_img.save(imgFile + "-stego.png", "PNG")

    print "[+] %s embedded successfully!" % payload
Beispiel #2
0
def embed(imgFile, payload, password):
	# Process source image
	img = Image.open(imgFile)
	(width, height) = img.size
	conv = img.convert("RGBA").getdata()
	print "[*] Input image size: %dx%d pixels." % (width, height)
	max_size = width*height*3.0/8/1024		# max payload size
	print "[*] Usable payload size: %.2f KB." % (max_size)

	f = open(payload, "rb")
	data = f.read()
	f.close()
	print "[+] Payload size: %.3f KB " % (len(data)/1024.0)
		
	# Encypt
	cipher = AESCipher(password)
	data_enc = cipher.encrypt(data)

	# Process data from payload file
	v = decompose(data_enc)
	
	# Add until multiple of 3
	while(len(v)%3):
		v.append(0)

	payload_size = len(v)/8/1024.0
	print "[+] Encrypted payload size: %.3f KB " % (payload_size)
	if (payload_size > max_size - 4):
		print "[-] Cannot embed. File too large"
		sys.exit()
		
	# Create output image
	steg_img = Image.new('RGBA',(width, height))
	data_img = steg_img.getdata()

	idx = 0

	for h in range(height):
		for w in range(width):
			(r, g, b, a) = conv.getpixel((w, h))
			if idx < len(v):
				r = set_bit(r, 0, v[idx])
				g = set_bit(g, 0, v[idx+1])
				b = set_bit(b, 0, v[idx+2])
			data_img.putpixel((w,h), (r, g, b, a))
			idx = idx + 3
    
	steg_img.save(imgFile + "-stego.png", "PNG")
	
	print "[+] %s embedded successfully!" % payload
def hide_text(sourceImg, secrettext, password):
    # Process source image
    img = Image.open(sourceImg)
    (width, height) = img.size
    conv_image = img.convert("RGBA").getdata()

    max_size = width * height * 3.0 / 8 / 1024

    f = open(secrettext, "rb")
    data = f.read()
    f.close()

    cipher = AESCipher(password)
    data_enc = cipher.encrypt(data)

    # Process data from secrettext
    bitsoffile = binary_to_bits(data_enc)

    # Add until multiple of 3
    while (len(bitsoffile) % 3):
        bitsoffile.append(0)

    secrettext_size = len(bitsoffile) / 8 / 1024.0

    if (secrettext_size > max_size - 4):
        print "\n>>> Failed to hide the text, file is too large.\n"
        sys.exit()

    # Create output image
    steg_img = Image.new('RGBA', (width, height))
    data_img = steg_img.getdata()

    v = 0

    for h in range(height):
        for w in range(width):
            (r, g, b, a) = conv_image.getpixel((w, h))
            if v < len(bitsoffile):
                r = set_bit(r, 0, bitsoffile[v])
                g = set_bit(g, 0, bitsoffile[v + 1])
                b = set_bit(b, 0, bitsoffile[v + 2])
            data_img.putpixel((w, h), (r, g, b, a))
            v = v + 3

    steg_img.save("stego.png", "PNG")

    print "\n>> %s hidden successfully in the source file!\n" % secrettext
Beispiel #4
0
 def _encrypt_params(self, raw_params={}):
     aes = AESCipher(self.config['crypt']['aeskey'])
     s = []
     for k in raw_params:
         s.append(k + '=' + str(raw_params[k]))
     return aes.encrypt('&'.join(s))
Beispiel #5
0
def encrypt(raw_str, platform=1):
    aes = AESCipher(platform)
    enc = urllib.quote(aes.encrypt(raw_str))
    return enc