-
Notifications
You must be signed in to change notification settings - Fork 2
/
white-obfs.py
92 lines (83 loc) · 3.68 KB
/
white-obfs.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
import os
import marshal
import logging
# ANSI color codes
yellow = '\033[93m'
lgreen = '\033[92m'
clear = '\033[0m'
red = '\033[91m'
# Clear the terminal and display the banner
os.system("clear")
banner = yellow + """
\t
+-------------------------------------------------------------------+
│ │
│ █ █ █ █▄█ ▀█▀ ▀█▀ █▀▀ █▀█ █▄▄ █▀▀ █ █ █▀▀ █▀▀ ▄▀▄ ▀█▀ █▀▀ │
│ ▀▄▀▄▀ █ █ ▄█▄ █ ██▄ █▄█ █▄█ █▀ █▄█ ▄██ █▄▄ █▀█ █ ██▄ │
│ │
│ Author : whxite Instagram : @whxitte
│ │
+-------------------------------------------------------------------+
\t\twhite obfuscate
""" + clear
print(banner)
def mode1(files, string):
try:
with open(files, 'r') as f:
s = f.read()
z = [ord(i) for i in s]
pea = [string.replace("'", "").replace('"', '') * i for i in z]
obfuscated_code = """
# coding=utf-8
# obfuscated with white obfuscate : https://github.com/WH1T3-E4GL3/white-obfuscate
d={};exec("".join([chr(len(i)) for i in d]))
""".format(pea)
with open(files.replace(".py", "encrypted.py"), "w") as f:
f.write(obfuscated_code)
logging.info("Saved as " + files.replace(".py", "encrypted.py"))
print("File encrypted successfully as '{}'".format(files.replace(".py", "encrypted.py")))
except Exception as e:
print(red + "[ERROR]" + clear + " An error occurred: {}".format(e))
def mode2(file):
try:
with open(file, 'r') as f:
x = f.read()
m = compile(x, '', 'exec')
k = marshal.dumps(m)
encoded_filename = 'encoded-' + file
with open(encoded_filename, 'w') as l:
l.write('import marshal\n')
l.write('exec(marshal.loads(' + repr(k) + "))")
print("File encoded successfully as '{}'".format(encoded_filename))
except Exception as e:
print(red + "[ERROR]" + clear + " An error occurred: {}".format(e))
def main_menu():
while True:
print(lgreen + """
+-------------------------------------------------------------------+
│ │
│ 1. Mode-1 (string substitution) │
│ │
│ 2. Mode-2 (marshal encoding) │
│ │
│ 3. Exit │
│ │
+-------------------------------------------------------------------+
""" + clear)
try:
number = int(input("Enter the number you want from above > "))
if number == 1:
file = input("Enter the name of the file to be encrypted: ")
string = input("Enter the string to be used for substitution cipher: ")
mode1(file, string)
elif number == 2:
file = input("Enter the name of the file to be encoded: ")
mode2(file)
elif number == 3:
break
else:
print(red + "[ERROR]" + clear + " Invalid input, please try again.")
except ValueError:
print(red + "[ERROR]" + clear + " Please enter a valid number.")
if __name__ == "__main__":
main_menu()