-
Notifications
You must be signed in to change notification settings - Fork 32
/
kf.py
executable file
·273 lines (249 loc) · 9.32 KB
/
kf.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# -*- coding: UTF-8 -*-
# K-fuscator
# Author : KasRoudra
# Github : https://github.com/KasRoudra
# Contact : https://m.me/KasRoudra
# Language: Python(3)
# Date : 18-08-2021
# Encrypt(obfuscate) or decrypt bash script or compile python script
import os, base64, sys, time
from pprint import pformat
# Emoji unicode list
alphabet = [
"\U0001f600",
"\U0001f603",
"\U0001f604",
"\U0001f601",
"\U0001f605",
"\U0001f923",
"\U0001f602",
"\U0001f609",
"\U0001f60A",
"\U0001f61b",
]
MAX_STR_LEN = 70
OFFSET = 10
# Basic colors
black="\033[0;30m"
red="\033[0;31m"
green="\033[0;32m"
yellow="\033[0;33m"
blue="\033[0;34m"
purple="\033[0;35m"
cyan="\033[0;36m"
white="\033[0;37m"
# Snippets
ask = green + '\n[' + white + '?' + green + '] '+ yellow
success = green + '\n[' + white + '√' + green + '] '
error = red + '\n[' + white + '!' + red + '] '
info= yellow + '\n[' + white + '+' + yellow + '] '+ cyan
# Current Directory
pwd=os.getcwd()
# Logo of K-fuscator
logo=f'''
{green} _ __ _____ _
{yellow}| |/ / | ___| _ ___ ___ __ _| |_ ___ _ __
{red}| ' /_____| |_ | | | / __|/ __/ _' | __/ _ \| '__|
{blue}| . \_____| _|| |_| \__ \ (_| (_| | || (_) | |
{cyan}|_|\_\ |_| \__,_|___/\___\__,_|\__\___/|_|
{purple} [By KasRoudra]
'''
# Normal slowly printer
def sprint(sentence, second=0.05):
for word in sentence + '\n':
sys.stdout.write(word)
sys.stdout.flush()
time.sleep(second)
# About section of script
def about():
os.system("clear")
sprint(logo, 0.01)
print(f"{cyan}[ToolName] {purple} :[K-fuscator]")
print(f"{cyan}[Version] {purple} :[1.0]")
print(f"{cyan}[Author] {purple} :[KasRoudra]")
print(f"{cyan}[Github] {purple} :[https://github.com/KasRoudra]")
print(f"{cyan}[Messenger] {purple} :[https://m.me/KasRoudra]")
print(f"{cyan}[Email] {purple} :[[email protected]]\n")
ret=input(ask+"1 for main menu, 0 for exit > "+green)
if ret=="1":
main()
else:
exit()
# Custom path chooser
def mover(out_file):
move= input(ask+"Move to a custom path?(y/n) > "+green)
if move=="y":
mpath=input(ask+"Enter the path > "+ green)
if os.path.exists(mpath):
os.system(f'''mv -f "{out_file}" "{mpath}" ''')
sprint(f"{success}{out_file} moved to {mpath}\n")
else:
sprint(error+"Path do not exist!\n")
else:
print("\n")
exit()
# Base64 encoder function
def obfuscate(VARIABLE_NAME, file_content):
b64_content = base64.b64encode(file_content.encode()).decode()
index = 0
code = f'{VARIABLE_NAME} = ""\n'
for _ in range(int(len(b64_content) / OFFSET) + 1):
_str = ''
for char in b64_content[index:index + OFFSET]:
byte = str(hex(ord(char)))[2:]
if len(byte) < 2:
byte = '0' + byte
_str += '\\x' + str(byte)
code += f'{VARIABLE_NAME} += "{_str}"\n'
index += OFFSET
code += f'exec(__import__("\\x62\\x61\\x73\\x65\\x36\\x34").b64decode({VARIABLE_NAME}.encode("\\x75\\x74\\x66\\x2d\\x38")).decode("\\x75\\x74\\x66\\x2d\\x38"))'
return code
def chunk_string(in_s, n):
"""Chunk string to max length of n"""
return "\n".join(
"{}\\".format(in_s[i : i + n]) for i in range(0, len(in_s), n)
).rstrip("\\")
def encode_string(in_s, alphabet):
d1 = dict(enumerate(alphabet))
d2 = {v: k for k, v in d1.items()}
return (
'exec("".join(map(chr,[int("".join(str({}[i]) for i in x.split())) for x in\n'
'"{}"\n.split(" ")])))\n'.format(
pformat(d2),
chunk_string(
" ".join(" ".join(d1[int(i)] for i in str(ord(c))) for c in in_s),
MAX_STR_LEN,
),
)
)
# Encrypt Bash code by npm package "bash-obfuscate"
def encryptsh():
in_file = input(ask + "Input Filename > "+cyan)
if not os.path.exists(in_file):
sprint(error+'File not found')
os.system("sleep 2")
encryptsh()
os.system("bash-obfuscate " + in_file + " -o .temp")
if not os.path.exists(".temp"):
try:
sprint(info+"Installing Bash-Obfuscate....\n")
os.system("apt install nodejs -y && npm install -g bash-obfuscate")
os.system("bash-obfuscate " + in_file + " -o .temp")
except:
sprint(error+" Bash-Obfuscate not installed! Install it by:\n"+green+"[+] \"apt install nodejs -y && npm install -g bash-obfuscate\"")
exit(1)
out_file= input(ask + "Output Filename > " + green)
with open(".temp",'r') as temp_f, open(out_file,'w') as out_f:
filedata = temp_f.read()
out_f.write("# Encrypted by K-fuscator\n# Github- https://github.com/KasRoudra/k-fuscator\n\n"+filedata)
os.remove(".temp")
sprint(f"{success}{out_file} saved in {pwd}")
mover(out_file)
# Decrypt bash code by "eval"
def decryptsh():
in_file = input(ask + "Input File > "+cyan)
if not os.path.exists(in_file):
print(error+' File not found')
os.system("sleep 2")
decryptsh()
with open(in_file,'r') as in_f, open(".temp1",'w') as temp_f:
filedata = in_f.read()
if not (filedata.find("eval") != -1):
sprint(error+" Cannot be decrypted!")
exit()
newdata = filedata.replace("eval","echo")
temp_f.write(newdata)
out_file = input(ask + "Output File > " +green)
os.system("bash .temp1 > .temp2")
os.remove(".temp1")
with open(".temp2",'r') as temp_f2, open(out_file,'w') as out_f:
filedata = temp_f2.read()
out_f.write("# Decrypted by K-fuscator\n# Github- https://github.com/KasRoudra/k-fuscator\n\n"+filedata)
os.remove(".temp2")
sprint(f"{success}{out_file} saved in {pwd}")
mover(out_file)
# Encrypting python file into base64 variable, easily decryptable
def encryptvar():
var= input(ask + "Variable to be used(Must Required) > " + green)
if (var==""):
sprint(error + " No variable")
os.system("sleep 3")
encryptvar()
if (var.find(" ")!= -1):
sprint(error+" Only one word!")
os.system("sleep 3")
encryptvar()
iteration = input(ask + "Iteration count for variable > " + green)
try:
iteration = int(iteration)
except Exception:
iteration = 50
VARIABLE_NAME = var * iteration
in_file = input(ask+ "Input file > "+cyan)
if not os.path.isfile(in_file):
print(error+' File not found')
os.system("sleep 2")
encryptvar()
out_file = input(ask + "Output file > " + green)
with open(in_file, 'r', encoding='utf-8', errors='ignore') as in_f,open(out_file, 'w') as out_f:
file_content = in_f.read()
obfuscated_content = obfuscate(VARIABLE_NAME, file_content)
out_f.write("# Encrypted by K-fuscator\n# Github- https://github.com/KasRoudra/k-fuscator\n\n"+obfuscated_content)
sprint(f"{success}{out_file} saved in {pwd}")
mover(out_file)
# Encrypting python file into emoji
def encryptem():
in_file= input(ask +"Input File > "+cyan )
if not os.path.isfile(in_file):
print(error+' File not found')
os.system("sleep 2")
encryptem()
out_file= input(ask + "Output File > " + green)
with open(in_file) as in_f, open(out_file, "w", encoding="utf-8") as out_f:
out_f.write("# Encrypted by K-fuscator\n# Github- https://github.com/KasRoudra/k-fuscator\n\n")
out_f.write(encode_string(in_f.read(), alphabet))
sprint(f"{success}{out_file} saved in {pwd}")
mover(out_file)
# Main function
def main():
os.system("clear")
sprint(logo, 0.01)
print(f"{green}[1]{yellow} Encrypt{cyan} Bash")
print(f"{green}[2]{yellow} Decrypt{cyan} Bash")
print(f"{green}[3]{yellow} Encrypt{cyan} Python into Variable")
print(f"{green}[4]{yellow} Encrypt{cyan} Python into Emoji")
print(f"{green}[5]{yellow} More Tools")
print(f"{green}[6]{yellow} About")
print(f"{green}[0]{yellow} Exit")
choose = input(f"{ask}{blue}Choose an option : {cyan}")
while True:
if choose == "1" or choose=="01":
encryptsh()
elif choose == "2" or choose=="02":
decryptsh()
elif choose == "3" or choose=="03":
encryptvar()
elif choose == "4" or choose=="04":
encryptem()
elif choose == "5" or choose=="05":
if os.path.exists("/data/data/com.termux/files/home"):
os.system("xdg-open --view 'https://github.com/KasRoudra/KasRoudra#My-Best-Works'")
else:
os.system("xdg-open 'https://github.com/KasRoudra/KasRoudra#My-Best-Works'")
main()
elif choose == "6" or choose=="06":
about()
elif choose == "0":
exit()
else:
sprint(error+'Wrong input!')
os.system("sleep 2")
main()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sprint(info+"Thanks for using. Have a good day!")
exit()
except Exception as e:
sprint(error+str(e))