Skip to content

Instantly share code, notes, and snippets.

@Und3rf10w
Last active February 5, 2018 03:49
Show Gist options
  • Save Und3rf10w/53cd6d8ec7ed1547d8c9217382654088 to your computer and use it in GitHub Desktop.
Save Und3rf10w/53cd6d8ec7ed1547d8c9217382654088 to your computer and use it in GitHub Desktop.
Generates and tests a nyancat png with an embedded eicar string
from PIL import Image
from cStringIO import StringIO
import requests
import imageio
import base64
import zlib
import PIL
import re
def encode(data, imageio):
img = Image.open(imageio)
pix = img.load()
data = base64.b64encode(zlib.compress(data, 9))
y = 1
for byte in data:
pix[y,y] = (pix[y,y][0], pix[y,y][1], ord(byte))
y = y + 1
pass
pix[0,0] = (0, 1, 1)
image_byte_array = StringIO()
img.save(image_byte_array, format='PNG')
return image_byte_array
def decode(imageio):
img = Image.open(imageio)
stego_pix = img.load()
byte_list = []
for y in range(1, img.size[1]):
byte_list.append(chr(stego_pix[y,y][2]))
pass
return zlib.decompress(base64.b64decode(''.join(byte_list).strip('\0')))
eicar = 'X5O!P%@AP[4\PZX54(P^)7CC)7}'
eicar += '$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'
nyan_cat_link = "http://aboutcolonblank.com/wp-content/uploads/2012/07/nyan-cat.png"
nyan_cat_io = StringIO(requests.get(nyan_cat_link).content)
evil_nyan_cat = encode(eicar, nyan_cat_io)
decoded_data = decode(evil_nyan_cat)
print decoded_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment