-
Notifications
You must be signed in to change notification settings - Fork 31
/
mysterium.py
210 lines (173 loc) · 8.78 KB
/
mysterium.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
# Made by @venaxyt on Github (helped by @IDRALOU, @Bleu-No and @vjousse)
# @venaxyt: All code and interface | @Bleu-No: Blue Mysterium | @vjousse: Linux support
# >>> https://github.com/venaxyt/mysterium
# Checking if needed modules are installed
import argparse, platform, zipfile, sys, os
from shutil import copyfile
# Detecting the operating system
is_windows = True if platform.system() == "Windows" else False
try:
import gratient, fade
except:
try:
if is_windows:
output = ">nul"
else:
output = "/dev/null"
os.system(f"py -m pip install -r requirements.txt {output}")
import gratient, fade
except:
exit()
system = platform.system()
if is_windows:
# Mysterium top bar title
os.system("title 𝙈 𝙔 𝙎 𝙏 𝙀 𝙍 𝙄 𝙐 𝙈 (Github: @venaxyt)")
# Definitions
def clear():
if is_windows:
os.system("cls")
else:
os.system("clear")
def pause():
if is_windows:
os.system(f"pause >nul")
else:
input()
def leave():
try:
sys.exit()
except:
exit()
def error(error):
print(gratient.red(f" [>] Error: {error}"), end="")
pause(); clear(); leave()
# Custom purple gratient color definition
def purple(text):
os.system("")
faded = ""
down = False
for line in text.splitlines():
red = 40
for character in line:
if down:
red -= 3
else:
red += 3
if red > 254:
red = 255
down = True
elif red < 1:
red = 30
down = False
faded += (f"\033[38;2;{red};0;220m{character}\033[0m")
return faded
# Gradient coloured banner
banner = f"""
::: ::: ::: ::: :::::::: ::::::::::: :::::::::: ::::::::: ::::::::::: ::: ::: ::: :::
:+:+: :+:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:+: :+:+:
+:+ +:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+:+ +:+
+#+ +:+ +#+ +#++: +#++:++#++ +#+ +#++:++# +#++:++#: +#+ +#+ +:+ +#+ +:+ +#+
+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+#
### ### ### ######## ### ########## ### ### ########### ######## ### ###
{purple("[>] Mysterium has been created by @venaxyt on Github / https://github.com/venaxyt/mysterium / Mysterium 2021©")}
{purple("[>] To inspect a code encrypted with Pyarmor, put it in a zip with the pytransform folder and it's architecture")}
{purple(f"[>] Mysterium version : 1.2.6 / Running with Python {sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]} / Discord server : https://discord.gg/mysterium")}
"""
# [EN]: Editing this banner will not make you a programmer / [FR]: Ce n'est pas en changeant la bannière que vous allez devenir développeur
# Allow mysterium to be used in command line interface (CLI)
parser = argparse.ArgumentParser(description="[+] Mysterium CLI")
parser.add_argument("-f", dest="filepath", required=False, default=None, help="The path to the file you want to inspect")
args = parser.parse_args()
blue_mysterium = False
uninspected_file_directory = args.filepath
# Mysterium user makes his choice about Blue Mysterium usage
# Blue Mysterium is not working anymore
blue_mysterium = "no"
#while not blue_mysterium:
# clear()
# print(fade.water(banner))
# try:
# blue_mysterium = input(purple(" [>] Do you want to use Blue Mysterium (y/n) : ") + "\033[38;2;184;0;230m")
# except:
# pass
if blue_mysterium.lower() in ["y", "ye", "yes"]:
blue_mysterium = True
elif blue_mysterium.lower() in ["n", "no"]:
blue_mysterium = False
else:
error(f'You have to make your choice, "{blue_mysterium}" is not a choice')
# Mysterium user inputs his uninspected file directory if not specified
# With the -f flag
while not uninspected_file_directory:
clear()
print(fade.water(banner))
try:
uninspected_file_directory = input(purple(" [>] Enter uninspected file path : ") + "\033[38;2;148;0;230m")
except:
pass
uninspected_file_directory = uninspected_file_directory.replace("'", "").replace('"', "")
uninspected_file_name = "uninspected"
filename, uninspected_file_extension = os.path.splitext(uninspected_file_directory)
# Removing the dot from the file's extension
uninspected_file_extension = uninspected_file_extension[1:]
# Checking if Mysterium user specified uninspected file extension
if not uninspected_file_extension:
error("You have to specify the file extension")
supported_file_extensions = ["py", "pyc", "exe", "zip"]
if uninspected_file_extension not in supported_file_extensions:
error("This extension of the file is not supported. You can only scan the following formats: {}.".format(",".join(supported_file_extensions)))
# Extraction of Python files from the executable one
if uninspected_file_extension == "exe":
copyfile(uninspected_file_directory, os.path.join("executable", "uninspected.exe"))
print(gratient.blue("\n [>] Trying to extracted Python files from the executable..."), end="")
os.system("cd executable && python pyinstxtractor.py uninspected.exe")
if os.path.isdir(os.path.join("executable", "uninspected.exe_extracted")):
print(gratient.blue("\n [>] Successfully extracted files from the executable"), end="")
else:
error("There was an error extracting Python files from the executable")
# Remove exported executable file
os.remove(os.path.join("executable", "uninspected.exe"))
print("") # To jump a line (for a better aesthetic interface)
uninspected_file_name = input(purple(" [>] Enter Python file name with extension : ") + "\033[38;2;178;0;230m")
exe_base_path = os.path.join("executable", "uninspected.exe_extracted")
if os.path.isfile(os.path.join(exe_base_path, f"{uninspected_file_name}.pyc")):
copyfile(os.path.join(exe_base_path, f"{uninspected_file_name}.pyc"), os.path.join("modules", f"{uninspected_file_name}.pyc"))
elif os.path.isfile(os.path.join(exe_base_path, f"{uninspected_file_name}")):
copyfile(os.path.join(exe_base_path, f"{uninspected_file_name}"), os.path.join("modules", f"{uninspected_file_name}.pyc"))
else:
error("The extracted pyc file has not been found")
# Define uninspected file extension as .pyc
uninspected_file_extension = "pyc"
# Check if Mysterium directory exists
if not os.path.isdir("modules"):
error("You have to download modules before inspecting any file")
if not uninspected_file_extension == "exe":
try:
copyfile(uninspected_file_directory, os.path.join("modules", f"uninspected.{uninspected_file_extension}"))
except FileNotFoundError:
error("File to inspect not found. Check the uninspected file path.")
# Unzip the file if it is in a "zip" file (used for Pyarmor / external encryptages)
if uninspected_file_extension == "zip":
zipfile.ZipFile(os.path.join("modules", "uninspected.zip"), "r").extractall("modules")
os.remove(os.path.join("modules", "uninspected.zip"))
uninspected_file_name = input(purple(" [>] Enter Python obfuscated file name with extension : ") + "\033[38;2;211;0;230m")
uninspected_file_name, uninspected_file_extension = os.path.splitext(uninspected_file_name)
# Remove the dot from the extension
uninspected_file_extension = uninspected_file_extension[1:]
if not uninspected_file_extension == "py" and not uninspected_file_extension == "pyc":
error("The file extension can only be .py or .pyc")
# Jump a line even zip file detected (for a better aesthetic interface)
print("")
# Define pyarmor uninspected file as ".py" (important for zip / exe files)
if not uninspected_file_extension == "pyc":
uninspected_file_extension = "py"
# Start uninspected file under Mysterium modules if user enabled it
if blue_mysterium:
import modules.blue
modules.blue.Blue(f'modules\\{uninspected_file_name}.{uninspected_file_extension}', uninspected_file_directory)
else:
os.system("python {}".format(os.path.join("modules", f"{uninspected_file_name}.{uninspected_file_extension}")))
print(gratient.blue("\n [>] The code is finished"), end="")
# os.remove(os.path.join("modules", f"{uninspected_file_name}.{uninspected_file_extension}")) # It's better to keep it to avoid re-extracting the zip folder
pause(); clear(); leave()