Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanify Code #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pystyle
80 changes: 44 additions & 36 deletions specter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Importing Necessary Modules

from marshal import dumps
from binascii import hexlify
from random import randint, shuffle

from pystyle import *



# Initialise Frontend

banner1 = r'''
██████ ██▓███ ▓█████ ▄████▄ ▄▄▄█████▓▓█████ ██▀███
Expand Down Expand Up @@ -38,60 +38,68 @@
\ \__, \_ `~' _/ .__/ /
`-._,-' `-._______,-' `-._,-'"""[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}"""


# Initialise Backend

class Specter:

vars = []

# Execute obfuscation system

def specterize(script: str) -> str:
print(stage("Starting specterization!"))
# print(stage("Preparing anti skid layer...")) just to be sure
print(stage("Specterizing!", "#"))
script = Specter.anti_skid(script=script)
print(stage("Adding layer 1!"))
print('\n')
print(stage("Applying Security patches [1/3]", ">"))
script = Specter.layer_1(script=script)
print(stage("Adding layer 2!"))
print('\n')
print(stage("Applying Security patches [2/3]", ">"))
script = Specter.layer_2(script=script)
print(stage("Adding layer 3!"))
print('\n')
print(stage("Applying Security patches [3/3]", ">"))
script = Specter.layer_3(script=script)
print('\n')
return script

# Security func: Convert values to hex

def hex(text: str) -> bytes:
return "b'" + "".join(fr"\x{hexlify(t.encode('utf-8')).decode()}" for t in text) + "'"

# Security func: Encrypt values

def encrypt(text: str, key: int) -> str:
return "\x00".join(str(ord(x)+key) for x in text)

# Security func: Randomize variables

def randvar() -> str:
var = randint(1000, 9999)
while var in Specter.vars:
var = randint(1000, 9999)
Specter.vars.append(var)
return f"__{var}__"

# Get value of key

def get_key_by_value(vars, key) -> str:
return list(vars.keys())[list(vars.values()).index(key)]

# Anti-skid system

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!

# This is an de-obfuscated code
# Specter: billythegoat356
# Github: https://github.com/billythegoat356/Specter
# Discord: https://discord.gg/plague

try:
if (
Expand All @@ -108,9 +116,10 @@ def anti_skid(script: str) -> str:
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

# Layer 1: Randomize values

def layer_1(script: str) -> str:
ten_split = []
key = randint(3, 33)
Expand All @@ -137,16 +146,20 @@ def layer_1(script: str) -> str:
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..."))
print(stage("Randomizing keys"))
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

# Layer 2: Compile and dump Script

def layer_2(script: str) -> str:
print(stage("Compiling and dumping code with marshal..."))
print(stage("Compiling and dumping"))
return dumps(compile(script, 'Specter', 'exec'))

# Layer 3: Camoflate Script

def layer_3(script: str) -> str:
split = []
splitting = 2000
Expand All @@ -159,16 +172,12 @@ def layer_3(script: str) -> str:
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..."))
print(stage("Camoflating script"))
script = fr"""
# this code has been obfuscated with Specter

# https://github.com/billythegoat356/Specter

# by billythegoat356

# join discord.gg/plague for more Python tools!

# This is a specterized file.
# Specter: billythegoat356
# Github: https://github.com/billythegoat356/Specter
# Discord: https://discord.gg/plague

__author__ = "billythegoat356"
__github__ = "https://github.com/billythegoat356/Specter"
Expand Down Expand Up @@ -201,6 +210,7 @@ def define(key, value: Any) -> Any:
Specter(__code__){' ' * 500},exec(__import__('marshal').loads({"+".join(var + "[1]" for var in vars)}),globals())"""[1:]
return script

# File Managing System

def main():
System.Size(150, 40)
Expand All @@ -209,7 +219,7 @@ def main():
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("'","")
file = input(stage(f"Enter the path of python script to obfuscate {Col.blue}-> {Col.reset}", ">")).replace('"','').replace("'","")
print('\n')

try:
Expand All @@ -225,8 +235,6 @@ def main():
with open(f'obf-{filename}', mode='wb') as f:
f.write(script.encode('utf-8'))

print('\n')
input(stage("Done!", '!'))

input(stage("Obuscated Successfully!", '!'))

main()