-
Notifications
You must be signed in to change notification settings - Fork 12
/
specter.py
232 lines (180 loc) · 8.75 KB
/
specter.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
from marshal import dumps
from binascii import hexlify
from random import randint, shuffle
from pystyle import *
banner1 = r'''
██████ ██▓███ ▓█████ ▄████▄ ▄▄▄█████▓▓█████ ██▀███
▒██ ▒ ▓██░ ██▒▓█ ▀ ▒██▀ ▀█ ▓ ██▒ ▓▒▓█ ▀ ▓██ ▒ ██▒
░ ▓██▄ ▓██░ ██▓▒▒███ ▒▓█ ▄ ▒ ▓██░ ▒░▒███ ▓██ ░▄█ ▒
▒ ██▒▒██▄█▓▒ ▒▒▓█ ▄ ▒▓▓▄ ▄██▒░ ▓██▓ ░ ▒▓█ ▄ ▒██▀▀█▄
▒██████▒▒▒██▒ ░ ░░▒████▒▒ ▓███▀ ░ ▒██▒ ░ ░▒████▒░██▓ ▒██▒
▒ ▒▓▒ ▒ ░▒▓▒░ ░ ░░░ ▒░ ░░ ░▒ ▒ ░ ▒ ░░ ░░ ▒░ ░░ ▒▓ ░▒▓░
░ ░▒ ░ ░░▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░▒ ░ ▒░
░ ░ ░ ░░ ░ ░ ░ ░ ░░ ░
░ ░ ░░ ░ ░ ░ ░
░'''[1:]
banner2 = r"""
,-.
___,---.__ /'|`\ __,---,___
,-' \` `-.____,-' | `-.____,-' // `-.
,' | ~'\ /`~ | `.
/ ___// `. ,' , , \___ \
| ,-' `-.__ _ | , __,-' `-. |
| / /\_ ` . | , _/\ \ |
\ | \ \`-.___ \ | / ___,-'/ / | /
\ \ | `._ `\\ | //' _,' | / /
`-.\ /' _ `---'' , . ``---' _ `\ /,-'
`` / \ ,='/ \`=. / \ ''
|__ /|\_,--.,-.--,--._/|\ __|
/ `./ \\`\ | | | /,//' \,' \
/ / ||--+--|--+-/-| \ \
| | /'\_\_\ | /_/_/`\ | |
\ \__, \_ `~' _/ .__/ /
`-._,-' `-._______,-' `-._,-'"""[1:]
banner = Add.Add(banner1, banner2, center=True)
purple = Col.StaticMIX([Col.blue, Col.purple])
def stage(text: str, symbol: str = '...') -> str:
ppurple = purple if symbol == '...' else Col.light_blue
return f""" {Col.Symbol(symbol, ppurple, Col.blue)} {ppurple}{text}{Col.reset}"""
class Specter:
vars = []
def specterize(script: str) -> str:
print(stage("Starting specterization!"))
# print(stage("Preparing anti skid layer...")) just to be sure
script = Specter.anti_skid(script=script)
print(stage("Adding layer 1!"))
script = Specter.layer_1(script=script)
print(stage("Adding layer 2!"))
script = Specter.layer_2(script=script)
print(stage("Adding layer 3!"))
script = Specter.layer_3(script=script)
return script
def hex(text: str) -> bytes:
return "b'" + "".join(fr"\x{hexlify(t.encode('utf-8')).decode()}" for t in text) + "'"
def encrypt(text: str, key: int) -> str:
return "\x00".join(str(ord(x)+key) for x in text)
def randvar() -> str:
var = randint(1000, 9999)
while var in Specter.vars:
var = randint(1000, 9999)
Specter.vars.append(var)
return f"__{var}__"
def get_key_by_value(vars, key) -> str:
return list(vars.keys())[list(vars.values()).index(key)]
def anti_skid(script: str) -> str:
return r"""
# GG! You just deobfuscated Specter
# https://github.com/billythegoat356/Specter
# by billythegoat356
# join discord.gg/plague for more Python tools!
try:
if (
__author__ != "billythegoat356" or
__github__ != "https://github.com/billythegoat356/Specter" or
__discord__ != "https://discord.gg/plague" or
__license__ != "EPL-2.0" or
__code__ != "Hello world!" or
"Specter" not in globals() or
"Func" not in globals()
):
int('skid')
except:
input("You just executed a file obfuscated with Specter!\n\nAuthor: billythegoat356\nGitHub: https://github.com/billythegoat356/Specter\nDiscord: https://discord.gg/plague")
__import__('sys').exit()
"""[1:] + script
def layer_1(script: str) -> str:
ten_split = []
key = randint(3, 33)
splitting = randint(3, 9)
while True:
if len(script) >= splitting:
ten_split.append(Specter.hex(Specter.encrypt(script[:splitting], key)))
script = script[splitting:]
else:
ten_split.append(Specter.hex(Specter.encrypt(script, key)))
break
lexec = Specter.hex(Specter.encrypt("exec", key))
lkey = Specter.hex(str(key))
ten_split.append(lexec)
ten_split.append(lkey)
ten_split.append("globals")
correct = [x for x in ten_split]
shuffle(ten_split)
vars = {Specter.randvar(): x for x in ten_split}
script = ",".join(vars.keys()) + '=' + ",".join(vars.values()) + '\n'
all_correct = []
for x in correct:
if x not in (lexec, lkey, "globals"):
all_correct.append(Specter.get_key_by_value(vars, x))
l1, l2, l3 = Specter.randvar(), Specter.randvar(), Specter.randvar()
glob = f"{Specter.get_key_by_value(vars, 'globals')}()[{l1}({l2}={Specter.get_key_by_value(vars, lexec)})]"
print(stage("Creating random vars..."))
lambdas = [fr"{l1}=lambda {l2}:''.join(chr(int({l3})-int({lkey}))for {l3} in {l2}.decode().split('\x00'))",
f"(lambda {l3}:{glob}(''.join({l1}({l2}={l2})for {l2} in {l3}),{Specter.get_key_by_value(vars, 'globals')}()))([{','.join(all_correct)}])",]
script = "from builtins import *\n" + script + '\n'.join(lambdas)
return script
def layer_2(script: str) -> str:
print(stage("Compiling and dumping code with marshal..."))
return dumps(compile(script, 'Specter', 'exec'))
def layer_3(script: str) -> str:
split = []
splitting = 2000
while True:
if len(script) >= splitting:
split.append(script[:splitting])
script = script[splitting:]
else:
split.append(script)
break
vars = {Specter.randvar(): x for x in split}
codevars = "\n".join(f"{a} = Func.calculate({randint(1,9)}){' ' * 500},Func.define('{a}', {b})" for a, b in vars.items())
print(stage("Camouflation of the obfuscated code..."))
script = fr"""
# this code has been obfuscated with Specter
# https://github.com/billythegoat356/Specter
# by billythegoat356
# join discord.gg/plague for more Python tools!
__author__ = "billythegoat356"
__github__ = "https://github.com/billythegoat356/Specter"
__discord__ = "https://discord.gg/plague"
__license__ = "EPL-2.0"
__code__ = "Hello world!"
Any = (...,)
class Specter:
def __init__(self, code: str) -> None:
self.code = code
self.execute(...)
return None
def execute(self, code: str = ...) -> None:
return exec(str(code))
class Func:
def calculate(num: int) -> int:
return num*2
def define(key, value: Any) -> Any:
globals()[key] = value
return globals()[key]
{codevars}
if __name__ == '__main__':
Specter(__code__){' ' * 500},exec(__import__('marshal').loads({"+".join(var + "[1]" for var in vars)}),globals())"""[1:]
return script
def main():
System.Size(150, 40)
System.Title("Specter")
Cursor.HideCursor()
print()
print(Colorate.Diagonal(Colors.purple_to_blue, Center.XCenter(banner + '\n\n')))
file = input(stage(f"Drag the file you want to obfuscate {Col.blue}-> {Col.reset}", "?")).replace('"','').replace("'","")
print('\n')
try:
with open(file, mode='rb') as f:
script = f.read().decode('utf-8')
filename = file.split('\\')[-1]
except:
input(f""" {Col.Symbol('!', Col.light_red, Col.blue)} {Col.light_red}Invalid file!{Col.reset}""")
exit()
script = Specter.specterize(script=script)
with open(f'obf-{filename}', mode='wb') as f:
f.write(script.encode('utf-8'))
print('\n')
input(stage("Done!", '!'))
main()