The cutest little virus

2020-01-31 Sven Halvorson

As a kid growing up when the Matrix movies came out, the idea of hacking was amazing to me. I didn't have a particular affinity for computers until much later in life but this idea stuck with me. I'm not a malicious guy but I thought about writing little R scripts for a while to prank people. Here's my example of the cutest little virus. The idea of this is that it uses the praw library to go to Reddit and download cat photos to a random location in the user's home directory.

You can choose a list of subreddits to pull from. Then create a .bat file on their computer that looks like this:

call "C:\ProgramData\Anaconda3\Scripts\activate.bat" "C:\ProgramData\Anaconda3\python.exe" "C:\path_to_your_script\cutest_virus.py" EXIT

The explanation of this is that you first have to call a .bat file that comes with Anaconda that will enable you to use libraries downloaded with this. Then you tell the script where python is located and which script to run, then you hit exit.

After making these files, go the task scheduler and call this .bat file at whatever interval you think they deserve a cat picture.

As I said, I am not a real hacker and this will not work easily in practice. Your 'victim' will have to have anaconda already installed. The bigger problem is that it opens up a command line or terminal which is somewhat obvious as to what is going on. I'm trying to figure out if this is possible to mask but haven't solved it yet.

Below is the example code:

In [1]:
import praw, os, requests, re, prawcore, random
from pathlib import Path

# Go to reddit and create an account. You need to go to the account settings and declare it a bot with a script.
# Reddit will givey ou some keys which you place here:
secret_key = ''
personal_key = ''


# Now we make the connection to reddit using praw
reddit = praw.Reddit(client_id = personal_key,
                    client_secret = secret_key,
                    user_agent = '',
                    username = 'your_username',
                    password = 'your_password')

# Select the subreddits to draw from and pick one at random:
subreddits = ['aww', 'chonkers', 'catpictures', 'Floof', 'cat', 'Catloaf']
subreddit = subreddits[random.randrange(len(subreddits))]

#get the hot submissions from that page
subreddit = reddit.subreddit(subreddit)
subreddit = subreddit.hot(limit = 25)
In [2]:
# Get the urls of the content and keep the ones with jpg endings:
urls = [x.url for x in subreddit]
urls = [x for x in urls if bool(re.search('jpg',x))]
url = urls[random.randrange(len(urls))]

# I'm sure it would be possible to make this more sophisticated to get gifs and media from linked
# sites but selecting the jpg was pretty reliable in my tests
In [3]:
# Okay now we need to get a place to put the file:
home = str(Path.home())
done_flag = 0
while done_flag == 0:
    # Here I set a tolerance for going deeper into the folders.
    further = random.random() > .3
    if further:
        subdirs = os.listdir(home)
        subdirs = [home + '/' + x for x in subdirs]
        subdirs = [x for x in subdirs if os.path.isdir(x)]
        subdirs = [x for x in subdirs if not bool(re.search('\\.',x))]
        if(len(subdirs) > 0):
            home = subdirs[random.randrange(len(subdirs))]
        else:
            done_flag = 1
    else:
        done_flag = 1
home = home + '/'
In [4]:
# Download the file:
def get_filename(directory, x):
    x = x.split('/')
    x = x[len(x)-1]
    return(directory + x)
img_data = requests.get(url).content
with open(get_filename(home, url), 'wb') as handler:
    handler.write(img_data)