-
Notifications
You must be signed in to change notification settings - Fork 8
/
obfuscation.py
132 lines (123 loc) · 5.9 KB
/
obfuscation.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
import os
import sys
import subprocess
import argparse
import random
import time
import marshal
import lzma
import gzip
import bz2
import binascii
import zlib
def prett(text):
return text.title().center(os.get_terminal_size().columns)
try:
import requests
import tqdm
import colorama
import pyfiglet
except ModuleNotFoundError:
if os.name == 'nt':
_ = 'python'
else:
_ = 'python' + '.'.join(str(i) for i in sys.version_info[:2])
if subprocess.run([_, '-m', 'pip', 'install', '-r', 'requirements.txt']).returncode == 0:
exit('\x1b[1m\x1b[92m' + prett('[+] dependencies installed\nrun the program again'))
elif subprocess.run(['pip3', 'install', '-r', 'requirements.txt']).returncode == 0:
exit('\x1b[1m\x1b[92m' + prett('[+] dependencies installed\nrun the program again'))
else:
exit('\x1b[1m\x1b[31m' + prett('[!] something error occured while installing dependencies\n maybe pip isn\'t installed or requirements.txt file not available?'))
BLU = colorama.Style.BRIGHT + colorama.Fore.BLUE
CYA = colorama.Style.BRIGHT + colorama.Fore.CYAN
GRE = colorama.Style.BRIGHT + colorama.Fore.GREEN
YEL = colorama.Style.BRIGHT + colorama.Fore.YELLOW
RED = colorama.Style.BRIGHT + colorama.Fore.RED
MAG = colorama.Style.BRIGHT + colorama.Fore.MAGENTA
LIYEL = colorama.Style.BRIGHT + colorama.Fore.LIGHTYELLOW_EX
LIRED = colorama.Style.BRIGHT + colorama.Fore.LIGHTRED_EX
LIMAG = colorama.Style.BRIGHT + colorama.Fore.LIGHTMAGENTA_EX
LIBLU = colorama.Style.BRIGHT + colorama.Fore.LIGHTBLUE_EX
LICYA = colorama.Style.BRIGHT + colorama.Fore.LIGHTCYAN_EX
LIGRE = colorama.Style.BRIGHT + colorama.Fore.LIGHTGREEN_EX
CLEAR = 'cls' if os.name == 'nt' else 'clear'
COLORS = BLU, CYA, GRE, YEL, RED, MAG, LIYEL, LIRED, LIMAG, LIBLU, LICYA, LIGRE
FONTS = 'basic', 'o8', 'cosmic', 'graffiti', 'chunky', 'epic', 'poison', 'doom', 'avatar'
PYTHON_VERSION = 'python' + '.'.join(str(i) for i in sys.version_info[:2])
colorama.init(autoreset=True)
def encode(source:str) -> str:
selected_mode = random.choice((lzma, gzip, bz2, binascii, zlib))
marshal_encoded = marshal.dumps(compile(source, 'Py-Fuscate', 'exec'))
if selected_mode is binascii:
encoded = binascii.b2a_base64(marshal_encoded)
else:
encoded = selected_mode.compress(marshal_encoded)
if selected_mode is binascii:
TMP = 'import marshal,lzma,gzip,bz2,binascii,zlib;exec(marshal.loads(binascii.a2b_base64({})))'
return TMP.format(encoded)
else:
TMP = 'import marshal,lzma,gzip,bz2,binascii,zlib;exec(marshal.loads({}.decompress({})))'
return TMP.format(selected_mode.__name__, encoded)
def logo() -> None:
os.system(CLEAR)
font = random.choice(FONTS)
color1 = random.choice(COLORS)
color2 = random.choice(COLORS)
while color1 == color2:
color2 = random.choice(COLORS)
print(color1 + '_' * os.get_terminal_size().columns, end='\n'*2)
print(color2 + pyfiglet.figlet_format(
'KSCH\nBlackCap',
font=font,
justify='center',
width=os.get_terminal_size().columns),
end=''
)
print(color1 + '_' * os.get_terminal_size().columns, end='\n'*2)
def parse_args():
parser = argparse.ArgumentParser(description='obfuscate python programs'.title())
parser._optionals.title = "syntax".title()
parser.add_argument(
'-r','--recursion',
default=False,
required=False,
help="recursion encoding by using this flag you will get x2 obfuscation strength".title(),
dest='r',
action='store_true')
parser.add_argument('-i', '--input', type=str, help='input file name'.title(), required=True)
parser.add_argument('-o', '--output', type=str, help='output file name'.title(), required=True)
parser.add_argument('-s', '--strength', type=int,
help='strengthness of obfuscation. 100 recomended'.title(), required=True)
if len(sys.argv)==1:
parser.print_help()
exit()
return parser.parse_args()
def main():
args = parse_args()
print(random.choice(COLORS) + '\t[+] encoding '.title() + args.input)
if not(args.r):
print(random.choice(COLORS) + '\t[!] you haven\'t selected the recursion mode'.title())
with tqdm.tqdm(total=args.strength) as pbar:
with open(args.input) as input:
if args.r:
for i in range(args.strength):
if i == 0:
encoded = encode(source=input.read())
else:
encoded = encode(source=encode(source=encoded))
time.sleep(0.1)
pbar.update(1)
else:
for i in range(args.strength):
if i == 0:
encoded = encode(source=input.read())
else:
encoded = encode(source=encoded)
time.sleep(0.1)
pbar.update(1)
with open(args.output, 'w') as output:
output.write(f"import asyncio, json, ntpath, os, random, re, shutil, sqlite3, subprocess, threading, winreg, zipfile, httpx, psutil, win32gui, win32con, pyperclip, base64, requests, ctypes, time;from sqlite3 import connect;from base64 import b64decode;from urllib.request import Request, urlopen;from shutil import copy2;from datetime import datetime, timedelta, timezone;from sys import argv;from tempfile import gettempdir, mkdtemp;from json import loads, dumps;from ctypes import windll, wintypes, byref, cdll, Structure, POINTER, c_char, c_buffer;from Crypto.Cipher import AES;from PIL import ImageGrab;from win32crypt import CryptUnprotectData\n\ntry:\n\t{encoded}\nexcept KeyboardInterrupt:\n\tpass")
print(LIGRE + '\t[+] encoding successful!\n\tsaved as '.title() + args.output)
if __name__ == '__main__':
logo()
main()