This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
# stepic - Python image steganography
from PIL import Image
def _validate_image(image):
if image.mode not in ('RGB', 'RGBA', 'CMYK'):
raise ValueError('Unsupported pixel format: '
'image must be RGB, RGBA, or CMYK')
if image.format == 'JPEG':
raise ValueError('JPEG format incompatible with steganography')
def encode_imdata(imdata, data):
'''given a sequence of pixels, returns an iterator of pixels with
encoded data'''
datalen = len(data)
if datalen == 0:
raise ValueError('data is empty')
if datalen * 3 > len(imdata):
raise ValueError('data is too large for image')
imdata = iter(imdata)
for i in range(datalen):
pixels = [value & ~1 for value in
imdata.__next__()[:3] + imdata.__next__()[:3] + imdata.__next__()[:3]]
byte = data[i]
for j in range(7, -1, -1):
pixels[j] |= byte & 1
byte >>= 1
if i == datalen - 1:
pixels[-1] |= 1
pixels = tuple(pixels)
yield pixels[0:3]
yield pixels[3:6]
yield pixels[6:9]
def encode_inplace(image, data):
'''hides data in an image'''
_validate_image(image)
w = image.size[0]
(x, y) = (0, 0)
for pixel in encode_imdata(image.getdata(), data):
image.putpixel((x, y), pixel)
if x == w - 1:
x = 0
y += 1
else:
x += 1
def encode(image, data):
'''generates an image with hidden data, starting with an existing
image and arbitrary data'''
image = image.copy()
encode_inplace(image, data)
# Save image
image.save('python-secret.png')
return image
def decode_imdata(imdata):
'''Given a sequence of pixels, returns an iterator of characters
encoded in the image'''
imdata = iter(imdata)
while True:
pixels = list(imdata.__next__()[:3] + imdata.__next__()[:3] + imdata.__next__()[:3])
byte = 0
for c in range(7):
byte |= pixels[c] & 1
byte <<= 1
byte |= pixels[7] & 1
yield chr(byte)
if pixels[-1] & 1:
break
def decode(image):
'''extracts data from an image'''
_validate_image(image)
return ''.join(decode_imdata(image.getdata()))
if __name__ == "__main__":
img = Image.open('python.png')
#encrypt message in image
encode(img,'this is a secret message')
#decrypt messagte in image
img = Image.open('python-secret.png')
text_decoded = decode(img)
print(text_decoded)