PyFuscator
PyFuscator is designed for security professionals, Red Teamers, and penetration testers who need to bypass detection mechanisms and protect their operational code. The tool supports both Python and PowerShell and applies common obfuscation techniques to evade security controls while maintaining full code functionality.
PyFuscator provides a layer of protection against static analysis, signature-based detection, and reverse engineering attempts. However, it’s important to understand that:
- An analyst may still be able to recover the original logic.
- The tool is designed to make reverse engineering difficult, not impossible.
- For maximum security, combine code obfuscation with other evasion mechanisms.
- Always use this tool in accordance with proper authorization and legal compliance.
Example usage
Running PyFuscator
pyfuscator python -e 1 test.py encrypted.py # Encrypt
pyfuscator python -a test.py obfuscated.py # Obfuscate
...
Renamed Identifiers
├── Global Functions
│ └── calculate_sum → Rdm3
│ ├── Variable: a → xmEDioovE
│ └── Variable: b → JeGZ
└── Global Variables
└── result → xUOriginal file
test.py
import numpy as np
def calculate_sum(a, b):
"""Add two numbers and return the result."""
return a + b
result = calculate_sum(10, 20)
print("The result is:", result)Encrypted file
encrypted.py
def xkL(p, c, s):
t = {(p * ch + s) % 256: ch for ch in range(256)}
return bytes([t[b] for b in bytes.fromhex(c)]).decode()
NIWi = '04fb9fda71ac7e0a08e79fda8b0ab3150a08da0404ee57c00a85b33685e736b37e57e115e79f52b3f60a1cbbb4040a0a0a0aac577ee7ac080a52b30a8d0a1cbb04ac5715e7367e0aef0a85b33685e736b37e57e115e79f52039af60a6c9abb04daacfb087e52e95e92570aac5715e7367e0afb15b4e9f60aac5715e7367ebb04'
MBdFQv6c = 230761
hTPE7gkyTE = 234
exec(xkL(MBdFQv6c, NIWi, hTPE7gkyTE))Obfuscated file
obfuscated.py
N0VfNU = 67
phb = __import__('base64').b64decode('V2t4VFE=').decode()
for X0W4O4wQc in range(4):
ASv = X0W4O4wQc
def BhrY():
while (0 == 1):
'This loop will never execute'
def oroeah():
return 93
iqfrib = oroeah()
return iqfrib
try:
U2cs = True
except Exception:
U2cs = False
for yJp in range(10):
P = yJp
cZ = bool(0)
uj0DW = 873
if False:
Ieb3bwftzj = 94
n = {__import__('base64').b64decode('bUNN').decode(): 86}
y = {__import__('base64').b64decode('SkNn').decode(): 57, __import__('base64').b64decode('UnRN').decode(): 69}
for vFmvfU89 in range(5):
ZNUf3YK = vFmvfU89
CHX = __import__('base64').b64decode('bzVvREg=').decode()
if True:
i5 = 34
if False:
Q = 49
Ss2ubPJIT = [63]
L = (15 + 31)
thKjfTYgMd = 179
CFu3 = __import__('base64').b64decode('WG05bEY=').decode()
DHBF = {__import__('base64').b64decode('S2pZ').decode(): 15, __import__('base64').b64decode('V1Ex').decode(): 87}
def bXL6qTt():
while (0 == 1):
'This loop will never execute'
def hmyjwv():
return 85
vlplyd = hmyjwv()
return vlplyd
def xrZO():
while (0 == 1):
'This loop will never execute'
def aqbmsa():
return 52
ugsrsl = aqbmsa()
return ugsrsl
q1 = [70]
def biHf2BnK():
if (False == True):
_x = 100
_y = 200
(_x + _y)
def oxojop():
return 65
yknmhl = oxojop()
return yknmhl
if (9 > 8):
B = 56
hIPPJa = len(__import__('base64').b64decode('d0wyVzY=').decode())
if True:
g94SF3K0J = 70
z = {__import__('base64').b64decode('Z055').decode(): 85, __import__('base64').b64decode('SDRw').decode(): 66}
for Mh4I in range(4):
S = Mh4I
if (4 > 1):
BOjI = 19
for oNl in range(5):
D = oNl
Q5OzG = {__import__('base64').b64decode('bk9C').decode(): 15}
if False:
q7626ylUv = 34
wUtgwJl = [46, 72]
class Gchuukxx():
def __init__(self):
try:
'This try block contains an illegal operation'
except Exception:
pass
def yhtuch():
pass
fpvlji = yhtuch()
return fpvlji
if False:
PS = 28
QlhMOOk = 979
mwmHH7ctai = [31, 65]
cWAAYbj = 907
dgVMabD9rA = [60, 61, 47]
wjQ4ORfKG = (52 + 92)
for O3z in range(9):
sPKNjO = O3z
if (6 > 2):
mV = 41
for DkWyd2 in range(10):
jOpQPwRmo = DkWyd2
if False:
ioOGOnSsw = 21
def HE():
if (1 > 100):
'This code will never execute'
def idlxdn():
return 56
ohwpgk = idlxdn()
return ohwpgk
if (9 > 2):
Ias = 77
def eoM():
if (1 > 100):
'This code will never execute'
def idzgdi():
return 66
wpyesb = idzgdi()
return wpyesb
gNVVci2b = len(__import__('base64').b64decode('Zjg3TW0=').decode())
DkSPiGQ = len(__import__('base64').b64decode('SGhZTXo=').decode())
for vfH in range(4):
pLsCNF = vfH
if False:
nRmtmjT = 52
class Sh():
def __init__(self):
if (1 > 100):
'This code will never execute'
def trkias():
pass
gfzpxk = trkias()
return gfzpxk
tn = len(__import__('base64').b64decode('SGpudmU=').decode())
X2WOWuG = 852
eR08k4w = len(__import__('base64').b64decode('VUR5NFY=').decode())
for nGqE in range(3):
TD07BjR = nGqE
if True:
ZMiBj3U = 14
if False:
f3eABeJnLV = 27
if False:
pHYZ = 39
if True:
TO = 35
sM = 744
EjS4OXzL = (__import__('base64').b64decode('cHdHMg==').decode() + __import__('base64').b64decode('eHAySA==').decode())
CJAMIf = 13
class Mg8v7():
def __init__(self):
assert (1 == 1), 'This assert will always pass'
def gozutt():
pass
pzwwtd = gozutt()
return pzwwtd
Hp7 = [53, 59, 40]
if True:
a8u = 48
lvAYme = (__import__('base64').b64decode('ajdRNA==').decode() + __import__('base64').b64decode('ZFppTg==').decode())
gmsLy = {__import__('base64').b64decode('RzBi').decode(): 58, __import__('base64').b64decode('VFUz').decode(): 8}
if False:
rgiMfDIAlU = 18
msr = len(__import__('base64').b64decode('a2d5eTY=').decode())
if (2 > 5):
e = 20
noMbC = __import__('base64').b64decode('eDhoWDc=').decode()
D5mVmNwl8 = __import__('base64').b64decode('bHIzNGE=').decode()
if True:
Oe = 11
for kGAsqoD30 in range(7):
HTF = kGAsqoD30
nvp99BEGM8 = (__import__('base64').b64decode('SHA0Tg==').decode() + __import__('base64').b64decode('V0RXaQ==').decode())
mu3G = (25 + 14)
RoBxGm = len(__import__('base64').b64decode('eHk2cVU=').decode())
for XkkdB2jz in range(3):
i = XkkdB2jz
def e71y1g():
try:
'This try block contains an illegal operation'
except Exception:
pass
def cozdua():
return 59
ilgvju = cozdua()
return ilgvju
def Ih():
while (0 == 1):
'This loop will never execute'
def gthslu():
return 56
goneek = gthslu()
return goneek
def WcT4NLb():
while (0 == 1):
'This loop will never execute'
def kwqfdi():
return 57
xvlous = kwqfdi()
return xvlous
for OO9sF6W9Zt in range(3):
ThLTi = OO9sF6W9Zt
if False:
xmwL5p3uYd = 68
qaQIX = bool(True)
if False:
ez2GtysU = 15
def IK1():
try:
'This try block contains an illegal operation'
except Exception:
pass
def tirzax():
return 3
bsuqap = tirzax()
return bsuqap
yIoM8 = __import__('base64').b64decode('enZmNmQ=').decode()
def ymXc():
while (0 == 1):
'This loop will never execute'
def htuadg():
return 83
nqbozu = htuadg()
return nqbozu
def VPSg():
while (0 == 1):
'This loop will never execute'
def npvwsc():
return 37
qyoikj = npvwsc()
return qyoikj
P4gH = {__import__('base64').b64decode('cjlJ').decode(): 58}
wpKchCfYa5 = len(__import__('base64').b64decode('ajNuN0Q=').decode())
GazYt = bool(1)
if True:
Mb = 82
kDoDuX5W = 809
xzcHwlFI = 696
def X4AIQ():
assert (1 == 1), 'This assert will always pass'
def akeskh():
return 31
obzqur = akeskh()
return obzqur
for Z in range(8):
xNHdkOR = Z
ay3 = __import__('base64').b64decode('Z1R4YUc=').decode()
UC33U = __import__(__import__(__import__('base64').b64decode('YmFzZTY0').decode()).b64decode(__import__('base64').b64decode('Ym5WdGNIaz0=').decode()).decode(__import__('base64').b64decode('dXRmLTg=').decode()))
def Rdm3(xmEDioovE, JeGZ):
assert (1 == 1), 'This assert will always pass'
def thcmhz():
return (xmEDioovE + JeGZ)
hffuva = thcmhz()
return hffuva
xU = Rdm3(10, 20)
print(__import__('base64').b64decode('VGhlIHJlc3VsdCBpczo=').decode(), xU)
zzeEy0WGk = (39 + 46)
gsBmz = 113
if False:
l4DvHbli = 30
uEtZde = 652
oN = len(__import__('base64').b64decode('QzZUTVY=').decode())
GyIyiCzot = {__import__('base64').b64decode('aThF').decode(): 93, __import__('base64').b64decode('SVFh').decode(): 68}
try:
n = True
except Exception:
n = False
class Ylkijne():
def __init__(self):
while (0 == 1):
'This loop will never execute'
def svkcjz():
pass
fjcuod = svkcjz()
return fjcuod
fvaWTh = __import__('base64').b64decode('STh0YW8=').decode()
E = [58, 70]
djTJbL = bool(1)
c68V = (__import__('base64').b64decode('d3Fucg==').decode() + __import__('base64').b64decode('RHNSZg==').decode())
xz = __import__('base64').b64decode('SEJIZnc=').decode()
class E0lkys():
def __init__(self):
while (0 == 1):
'This loop will never execute'
def lanhcl():
pass
iyvzou = lanhcl()
return iyvzou
def slOHIG():
assert (1 == 1), 'This assert will always pass'
def cbsarx():
return 49
jpfaln = cbsarx()
return jpfaln
for t in range(8):
nebj0YrO1 = t
for k in range(8):
cZ2m = k
o = [85, 24, 59]
y7iA = [84, 4]
if False:
cxYktUVt7 = 3
if (5 > 8):
r7K6K = 67
def VFU4():
if (False == True):
_x = 100
_y = 200
(_x + _y)
def smhqet():
return 33
ojvnby = smhqet()
return ojvnby
try:
lwT0HOEWeU = True
except Exception:
lwT0HOEWeU = False
def gb0cJqH():
while (0 == 1):
'This loop will never execute'
def aetaic():
return 80
ogqtpv = aetaic()
return ogqtpv
try:
L0MuTa5Z = True
except Exception:
L0MuTa5Z = False
def rX():
while (0 == 1):
'This loop will never execute'
def mdclvk():
return 14
ywxsyv = mdclvk()
return ywxsyv
RDE = __import__('base64').b64decode('ekVWUW4=').decode()
def Ud1C2PpU9():
while (0 == 1):
'This loop will never execute'
def tlekgk():
return 85
wuwkby = tlekgk()
return wuwkby
flcU = {__import__('base64').b64decode('alJF').decode(): 11}
M8y0vMg = {__import__('base64').b64decode('SG5Q').decode(): 64, __import__('base64').b64decode('dFJt').decode(): 71}
if (4 > 1):
cINYk5bfdv = 21
n2hWM = 243
if True:
P5Ey = 88
s1vnIt = len(__import__('base64').b64decode('djZBbXI=').decode())
if False:
kQ = 80
for jyPuE in range(5):
rj4vem = jyPuE
if True:
z597BvgZW = 83
def JInDc():
assert (1 == 1), 'This assert will always pass'
def sqcehd():
return 37
mhuykv = sqcehd()
return mhuykv
def ocFc2Rh():
if (1 > 100):
'This code will never execute'
def ffinrs():
return 31
jjjmhc = ffinrs()
return jjjmhc
if False:
yQ = 81
qRuEuDS = bool(1)
def fPBr():
while (0 == 1):
'This loop will never execute'
def nscbrg():
return 87
jrhrea = nscbrg()
return jrhrea
for CYfw8E in range(6):
xGK7SKtD8 = CYfw8E
HukxNNxQyp = {__import__('base64').b64decode('cG9t').decode(): 56}
def aSRvIk():
assert (1 == 1), 'This assert will always pass'
def mrhukd():
return 15
wifmdz = mrhukd()
return wifmdz
def uDSOCn():
try:
'This try block contains an illegal operation'
except Exception:
pass
def tmvnlr():
return 95
udhjpd = tmvnlr()
return udhjpd
nb = [80, 29, 17]
for aLXKLtSYQ in range(6):
v72457s = aLXKLtSYQ
for rP in range(8):
r2pu = rP
def oa3zDUVSKm():
assert (1 == 1), 'This assert will always pass'
def xylvsl():
return 23
yfimcg = xylvsl()
return yfimcg
R3XPFtbmX = 602
HQYL2p = __import__('base64').b64decode('SXV4d2c=').decode()
BJ = (89 + 39)
try:
DreT4 = True
except Exception:
DreT4 = False
class Ryuuaxue4i():
def __init__(self):
if (1 > 100):
'This code will never execute'
def pnmolr():
pass
oqpyhq = pnmolr()
return oqpyhq
f6h4g = (63 + 100)
uinGmQYL = bool(True)
QlCAQWe08 = [56, 25]
PxsLV = [83, 50]
def bh():
if (1 > 100):
'This code will never execute'
def ejyzww():
return 12
xzpqud = ejyzww()
return xzpqud
Tz0tmHS02 = bool(True)
for cd4AxaFLL in range(5):
Cm = cd4AxaFLL
sDeKsbC4js = len(__import__('base64').b64decode('Vk9xWW0=').decode())
EgQ = (__import__('base64').b64decode('eUdLYg==').decode() + __import__('base64').b64decode('SUZtaw==').decode())
N = bool(True)
S = 663
f4yGxdAnKm = [66, 77, 11]
x4Km6 = 164
ZJYa60VbH = (3 + 2)
for LZ95 in range(8):
hX2 = LZ95
if (3 > 10):
al = 58
for Or in range(4):
DzjtJA5 = Or
def XXQL():
if (False == True):
_x = 100
_y = 200
(_x + _y)
def oxxypo():
return 74
zhqaeu = oxxypo()
return zhqaeu
eqy = {__import__('base64').b64decode('VWoy').decode(): 5, __import__('base64').b64decode('RzNK').decode(): 66}
def HO5gfSxk():
try:
'This try block contains an illegal operation'
except Exception:
pass
def gdikdq():
return 5
waibgz = gdikdq()
return waibgz
for foznRlz in range(4):
hqcF = foznRlz
fU5DVgIoc = __import__('base64').b64decode('WThDaUs=').decode()
if True:
wmH = 16
rTd = {__import__('base64').b64decode('VW80').decode(): 65}
ZHz8PGDOD = __import__('base64').b64decode('Y0I3Unk=').decode()
class Tdrb():
def __init__(self):
if (False == True):
_x = 100
_y = 200
(_x + _y)
def dkjngu():
pass
vdgrgt = dkjngu()
return vdgrgt
w38D = [77, 45]
oUZAZ = {__import__('base64').b64decode('Vmlk').decode(): 24}
def TWmnQnWzvY():
try:
'This try block contains an illegal operation'
except Exception:
pass
def yewgwl():
return 32
rxbbxv = yewgwl()
return rxbbxv
try:
k8zHPSxx7 = True
except Exception:
k8zHPSxx7 = False
hm = [78, 75]
HOlnrFdlU = __import__('base64').b64decode('a0czV2Q=').decode()
wMX9x = 659
sOeV = __import__('base64').b64decode('SEl6YlE=').decode()
ATOwKb = [90]
FwQpe = {__import__('base64').b64decode('aW85').decode(): 25}
Xrhc = 867
for eatDDZkJ4I in range(3):
OuFvjgg = eatDDZkJ4I
vdY = 152
Je1IYov = 62
JDTlaMDgt = (__import__('base64').b64decode('ZEc2cg==').decode() + __import__('base64').b64decode('TGU2cA==').decode())
def h():
assert (1 == 1), 'This assert will always pass'
def vrpdoe():
return 92
faoisg = vrpdoe()
return faoisg
if False:
GnVhJX8 = 38
try:
zplJREWlN = True
except Exception:
zplJREWlN = False
try:
ZLyiXKkX = True
except Exception:
ZLyiXKkX = FalseLast updated on