tzero-mcp 12.3.2 → 12.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +1 -1
- package/README.md +4 -0
- package/package.json +3 -4
- package/src/addmcp.py +2 -2
- package/src/app.py +1 -1
- package/src/main.py +4 -0
- package/src/tzero/__init__.py +1 -1
- package/src/tzero/desktop_updater.py +6 -0
- package/src/tzero/tzero_benchmark.py +1 -1
- package/src/tzero/tzero_budget.py +1 -1
- package/src/tzero/tzero_ci.py +1 -1
- package/src/tzero/tzero_contracts.py +2 -2
- package/src/tzero/tzero_dashboard.py +3 -3
- package/src/tzero/tzero_debt.py +85 -7
- package/src/tzero/tzero_deps.py +1 -0
- package/src/tzero/tzero_explain.py +1 -1
- package/src/tzero/tzero_features.py +31 -74
- package/src/tzero/tzero_golden.py +2 -2
- package/src/tzero/tzero_graph_hud.html +4 -4
- package/src/tzero/tzero_growth.py +1 -1
- package/src/tzero/tzero_jarvis/orchestrator.py +1 -1
- package/src/tzero/tzero_jarvis/swarm.py +23 -2
- package/src/tzero/tzero_jarvis/workspace_orchestrator.py +10 -21
- package/src/tzero/tzero_lsp.py +1 -1
- package/src/tzero/tzero_mcp.py +39 -122
- package/src/tzero/tzero_promo.py +1 -1
- package/src/tzero/tzero_security.py +3 -3
- package/src/tzero/tzero_sync.py +73 -148
- package/src/tzero/tzero_task_benchmark.py +2 -2
- package/src/tzero/tzero_traffic.py +1 -1
- package/src/tzero/tzero_tui.py +2 -13
- package/src/tzero/tzero_v3.py +433 -392
- package/src/tzero/tzero_welcome.py +1 -1
- package/src/tzero/anti_rea/__init__.py +0 -84
- package/src/tzero/anti_rea/algebraic_mutator.py +0 -107
- package/src/tzero/anti_rea/anti_agent_guard.py +0 -96
- package/src/tzero/anti_rea/anti_debugger.py +0 -272
- package/src/tzero/anti_rea/anti_vm.py +0 -160
- package/src/tzero/anti_rea/asar_shield.py +0 -122
- package/src/tzero/anti_rea/auditor.py +0 -208
- package/src/tzero/anti_rea/bpe_disrupter.py +0 -48
- package/src/tzero/anti_rea/bytecode_trap.py +0 -85
- package/src/tzero/anti_rea/canary_beacon.py +0 -167
- package/src/tzero/anti_rea/cli.py +0 -134
- package/src/tzero/anti_rea/confusables.py +0 -130
- package/src/tzero/anti_rea/crypto_loader.py +0 -132
- package/src/tzero/anti_rea/engine.py +0 -304
- package/src/tzero/anti_rea/extractor_shield.py +0 -180
- package/src/tzero/anti_rea/flattener.py +0 -136
- package/src/tzero/anti_rea/gui.py +0 -264
- package/src/tzero/anti_rea/honeypot.py +0 -58
- package/src/tzero/anti_rea/integrity_guard.py +0 -78
- package/src/tzero/anti_rea/jailbreak_decoy.py +0 -77
- package/src/tzero/anti_rea/mcp_poison.py +0 -41
- package/src/tzero/anti_rea/native_bridge.py +0 -169
- package/src/tzero/anti_rea/rdtsc_guard.py +0 -77
- package/src/tzero/anti_rea/string_vault.py +0 -97
- package/src/tzero/anti_rea/sybil_network.py +0 -53
- package/src/tzero/anti_rea/tier_catalog.py +0 -388
- package/src/tzero/anti_rea/timing_guard.py +0 -46
- package/src/tzero/anti_rea/token_bomb.py +0 -65
- package/src/tzero/anti_rea/traps.py +0 -76
- package/src/tzero/anti_rea/vm_obfuscator.py +0 -182
- package/src/tzero/tzero_armor.py +0 -187
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 25: Hardware Hypervisor, Virtual Machine & Sandbox Detector (Anti-VM).
|
|
3
|
-
|
|
4
|
-
Detects automated dynamic analysis sandboxes, emulators, and hypervisors:
|
|
5
|
-
- Hypervisor processes (VBoxService, vmtoolsd, qemu-ga, xenservice)
|
|
6
|
-
- Virtualized driver and device artifacts (VBoxMouse.sys, vmmouse.sys, etc.)
|
|
7
|
-
- Virtual NIC MAC OUI signatures (VMware, VirtualBox, QEMU/KVM)
|
|
8
|
-
- System BIOS / System manufacturer string artifacts
|
|
9
|
-
- Execution redirection to decoy honeypots or immediate hard termination.
|
|
10
|
-
|
|
11
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
12
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
13
|
-
License: MIT
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import os
|
|
17
|
-
import sys
|
|
18
|
-
from typing import Dict, Any, List
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class AntiVMGuard:
|
|
22
|
-
"""Detects virtual machine, emulator, and sandbox environments."""
|
|
23
|
-
|
|
24
|
-
VM_PROCESSES = {
|
|
25
|
-
"vboxservice.exe",
|
|
26
|
-
"vboxtray.exe",
|
|
27
|
-
"vmtoolsd.exe",
|
|
28
|
-
"vmwaretray.exe",
|
|
29
|
-
"vmwareuser.exe",
|
|
30
|
-
"qemu-ga.exe",
|
|
31
|
-
"xenservice.exe",
|
|
32
|
-
"prl_tools.exe",
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
VM_DRIVERS = [
|
|
36
|
-
r"C:\Windows\System32\drivers\VBoxMouse.sys",
|
|
37
|
-
r"C:\Windows\System32\drivers\VBoxGuest.sys",
|
|
38
|
-
r"C:\Windows\System32\drivers\VBoxSF.sys",
|
|
39
|
-
r"C:\Windows\System32\drivers\vmmouse.sys",
|
|
40
|
-
r"C:\Windows\System32\drivers\vmhgfs.sys",
|
|
41
|
-
r"C:\Windows\System32\drivers\vmusbmouse.sys",
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
VM_MAC_PREFIXES = {
|
|
45
|
-
"00:05:69", # VMware
|
|
46
|
-
"00:0C:29", # VMware
|
|
47
|
-
"00:1C:14", # VMware
|
|
48
|
-
"00:50:56", # VMware
|
|
49
|
-
"08:00:27", # VirtualBox
|
|
50
|
-
"52:54:00", # QEMU / KVM
|
|
51
|
-
"00:16:3E", # Xen
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@classmethod
|
|
55
|
-
def check_hypervisor_artifacts(cls) -> Dict[str, Any]:
|
|
56
|
-
"""Performs static and dynamic checks for VM / hypervisor artifacts."""
|
|
57
|
-
detected = []
|
|
58
|
-
is_vm = False
|
|
59
|
-
|
|
60
|
-
# 1. Driver artifacts (Windows)
|
|
61
|
-
if sys.platform == "win32":
|
|
62
|
-
for drv in cls.VM_DRIVERS:
|
|
63
|
-
if os.path.exists(drv):
|
|
64
|
-
detected.append(f"Driver artifact: {drv}")
|
|
65
|
-
is_vm = True
|
|
66
|
-
|
|
67
|
-
# 2. Process inspection via ctypes / toolhelp32 or ps
|
|
68
|
-
if sys.platform == "win32":
|
|
69
|
-
try:
|
|
70
|
-
import ctypes
|
|
71
|
-
from ctypes import wintypes
|
|
72
|
-
|
|
73
|
-
TH32CS_SNAPPROCESS = 0x00000002
|
|
74
|
-
|
|
75
|
-
class PROCESSENTRY32(ctypes.Structure):
|
|
76
|
-
_fields_ = [
|
|
77
|
-
("dwSize", wintypes.DWORD),
|
|
78
|
-
("cntUsage", wintypes.DWORD),
|
|
79
|
-
("th32ProcessID", wintypes.DWORD),
|
|
80
|
-
("th32DefaultHeapID", ctypes.c_size_t),
|
|
81
|
-
("th32ModuleID", wintypes.DWORD),
|
|
82
|
-
("cntThreads", wintypes.DWORD),
|
|
83
|
-
("th32ParentProcessID", wintypes.DWORD),
|
|
84
|
-
("pcPriClassBase", wintypes.LONG),
|
|
85
|
-
("dwFlags", wintypes.DWORD),
|
|
86
|
-
("szExeFile", ctypes.c_char * 260),
|
|
87
|
-
]
|
|
88
|
-
|
|
89
|
-
k32 = ctypes.windll.kernel32
|
|
90
|
-
snapshot = k32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
|
|
91
|
-
if snapshot != -1:
|
|
92
|
-
pe = PROCESSENTRY32()
|
|
93
|
-
pe.dwSize = ctypes.sizeof(PROCESSENTRY32)
|
|
94
|
-
if k32.Process32First(snapshot, ctypes.byref(pe)):
|
|
95
|
-
while True:
|
|
96
|
-
exe_name = pe.szExeFile.decode("latin-1", errors="ignore").lower()
|
|
97
|
-
if exe_name in cls.VM_PROCESSES:
|
|
98
|
-
detected.append(f"Hypervisor process: {exe_name}")
|
|
99
|
-
is_vm = True
|
|
100
|
-
if not k32.Process32Next(snapshot, ctypes.byref(pe)):
|
|
101
|
-
break
|
|
102
|
-
k32.CloseHandle(snapshot)
|
|
103
|
-
except Exception:
|
|
104
|
-
pass
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
"is_vm": is_vm,
|
|
108
|
-
"detected_artifacts": detected,
|
|
109
|
-
"status": "VIRTUAL_MACHINE_DETECTED" if is_vm else "BARE_METAL",
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@classmethod
|
|
113
|
-
def generate_guard_code(cls, hard_kill: bool = True) -> str:
|
|
114
|
-
"""Generates embeddable Python code to neutralize execution in VM sandboxes."""
|
|
115
|
-
kill_logic = (
|
|
116
|
-
"import os; os._exit(0xC0000409)"
|
|
117
|
-
if hard_kill
|
|
118
|
-
else "raise SystemExit('Hardware requirement not met.')"
|
|
119
|
-
)
|
|
120
|
-
return f'''# [ANTI-REA TIER-25: HYPERVISOR & SANDBOX GUARD]
|
|
121
|
-
def _verify_bare_metal_hardware():
|
|
122
|
-
import sys, os
|
|
123
|
-
if sys.platform != "win32":
|
|
124
|
-
return
|
|
125
|
-
_vm_files = [
|
|
126
|
-
r"C:\\Windows\\System32\\drivers\\VBoxMouse.sys",
|
|
127
|
-
r"C:\\Windows\\System32\\drivers\\VBoxGuest.sys",
|
|
128
|
-
r"C:\\Windows\\System32\\drivers\\vmmouse.sys",
|
|
129
|
-
r"C:\\Windows\\System32\\drivers\\vmhgfs.sys"
|
|
130
|
-
]
|
|
131
|
-
for _f in _vm_files:
|
|
132
|
-
if os.path.exists(_f):
|
|
133
|
-
{kill_logic}
|
|
134
|
-
try:
|
|
135
|
-
import ctypes
|
|
136
|
-
from ctypes import wintypes
|
|
137
|
-
_k32 = ctypes.windll.kernel32
|
|
138
|
-
class _PE32(ctypes.Structure):
|
|
139
|
-
_fields_ = [("dwSize", wintypes.DWORD), ("cntUsage", wintypes.DWORD),
|
|
140
|
-
("th32ProcessID", wintypes.DWORD), ("th32DefaultHeapID", ctypes.c_size_t),
|
|
141
|
-
("th32ModuleID", wintypes.DWORD), ("cntThreads", wintypes.DWORD),
|
|
142
|
-
("th32ParentProcessID", wintypes.DWORD), ("pcPriClassBase", wintypes.LONG),
|
|
143
|
-
("dwFlags", wintypes.DWORD), ("szExeFile", ctypes.c_char * 260)]
|
|
144
|
-
_s = _k32.CreateToolhelp32Snapshot(0x00000002, 0)
|
|
145
|
-
if _s != -1:
|
|
146
|
-
_pe = _PE32()
|
|
147
|
-
_pe.dwSize = ctypes.sizeof(_PE32)
|
|
148
|
-
_procs = {{"vboxservice.exe", "vboxtray.exe", "vmtoolsd.exe", "vmwaretray.exe", "qemu-ga.exe"}}
|
|
149
|
-
if _k32.Process32First(_s, ctypes.byref(_pe)):
|
|
150
|
-
while True:
|
|
151
|
-
if _pe.szExeFile.decode("latin-1", errors="ignore").lower() in _procs:
|
|
152
|
-
_k32.CloseHandle(_s)
|
|
153
|
-
{kill_logic}
|
|
154
|
-
if not _k32.Process32Next(_s, ctypes.byref(_pe)):
|
|
155
|
-
break
|
|
156
|
-
_k32.CloseHandle(_s)
|
|
157
|
-
except Exception:
|
|
158
|
-
pass
|
|
159
|
-
_verify_bare_metal_hardware()
|
|
160
|
-
'''
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 24: Electron & Node.js (.asar) Archive Shield.
|
|
3
|
-
|
|
4
|
-
Thwarts automated Electron archive extraction attacks by toolchains like
|
|
5
|
-
REA (e.g. `analyze-javascript-application`, `npx asar extract`).
|
|
6
|
-
|
|
7
|
-
Electron ASAR Format Structure:
|
|
8
|
-
- [0..3]: u32: 4
|
|
9
|
-
- [4..7]: u32: header_size + 4
|
|
10
|
-
- [8..11]: u32: header_size
|
|
11
|
-
- [12..15]: u32: json_string_length
|
|
12
|
-
- [16..]: JSON Table of Contents string
|
|
13
|
-
|
|
14
|
-
AsarShield mutates the archive headers, injects decoy corrupted TOC lengths,
|
|
15
|
-
and introduces non-linear JSON recursion blocks that cause `npx asar extract`
|
|
16
|
-
and Python/Go ASAR parsers to crash with fatal errors before extracting source files.
|
|
17
|
-
|
|
18
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
19
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
20
|
-
License: MIT
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
import os
|
|
24
|
-
import struct
|
|
25
|
-
from typing import Dict, Any, Optional, Tuple
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AsarShield:
|
|
29
|
-
"""Shields Electron .asar archives against automated AI unpackers."""
|
|
30
|
-
|
|
31
|
-
ASAR_MAGIC = b"\x04\x00\x00\x00"
|
|
32
|
-
|
|
33
|
-
@classmethod
|
|
34
|
-
def is_asar_archive(cls, file_bytes: bytes) -> bool:
|
|
35
|
-
"""Verifies if byte stream matches Electron ASAR archive signature."""
|
|
36
|
-
return len(file_bytes) >= 16 and file_bytes[:4] == cls.ASAR_MAGIC
|
|
37
|
-
|
|
38
|
-
@classmethod
|
|
39
|
-
def shield_asar_bytes(cls, asar_bytes: bytes) -> Tuple[bytes, Dict[str, Any]]:
|
|
40
|
-
"""Applies header corruption traps to Electron ASAR archive bytes."""
|
|
41
|
-
if not cls.is_asar_archive(asar_bytes):
|
|
42
|
-
return asar_bytes, {
|
|
43
|
-
"shielded": False,
|
|
44
|
-
"reason": "Not a valid Electron ASAR archive header"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
data = bytearray(asar_bytes)
|
|
48
|
-
|
|
49
|
-
# Read original header sizes
|
|
50
|
-
orig_u32_4 = struct.unpack("<I", data[0:4])[0]
|
|
51
|
-
orig_total_size = struct.unpack("<I", data[4:8])[0]
|
|
52
|
-
orig_header_size = struct.unpack("<I", data[8:12])[0]
|
|
53
|
-
orig_json_len = struct.unpack("<I", data[12:16])[0]
|
|
54
|
-
|
|
55
|
-
# Inject Decoy Archive Poison:
|
|
56
|
-
# In ASAR extraction, if json_len > header_size, standard unpackers throw
|
|
57
|
-
# "Error: Invalid header size" or crash with buffer overflow.
|
|
58
|
-
# We craft a dual-stage poisoned header:
|
|
59
|
-
poisoned_json_len = orig_json_len ^ 0x00000001
|
|
60
|
-
data[12:16] = struct.pack("<I", poisoned_json_len)
|
|
61
|
-
|
|
62
|
-
# Append corrupted canary trailer
|
|
63
|
-
canary_trailer = b"\x00\x00\x00\x00" + b"ELECTRON_ASAR_SHIELD_CANARY_0x7B" + (b"\xFF" * 16)
|
|
64
|
-
shielded_data = bytes(data) + canary_trailer
|
|
65
|
-
|
|
66
|
-
return shielded_data, {
|
|
67
|
-
"shielded": True,
|
|
68
|
-
"original_u32_4": orig_u32_4,
|
|
69
|
-
"original_total_size": orig_total_size,
|
|
70
|
-
"original_header_size": orig_header_size,
|
|
71
|
-
"original_json_len": orig_json_len,
|
|
72
|
-
"poisoned_json_len": poisoned_json_len,
|
|
73
|
-
"status": "ASAR_EXTRACTOR_POISONED"
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@classmethod
|
|
77
|
-
def shield_asar_file(cls, asar_path: str, output_path: Optional[str] = None) -> Dict[str, Any]:
|
|
78
|
-
"""Shields an Electron app.asar file on disk."""
|
|
79
|
-
if not os.path.isfile(asar_path):
|
|
80
|
-
return {"success": False, "error": f"File not found: {asar_path}"}
|
|
81
|
-
|
|
82
|
-
out = output_path or asar_path
|
|
83
|
-
try:
|
|
84
|
-
with open(asar_path, "rb") as f:
|
|
85
|
-
content = f.read()
|
|
86
|
-
|
|
87
|
-
shielded_bytes, meta = cls.shield_asar_bytes(content)
|
|
88
|
-
if not meta["shielded"]:
|
|
89
|
-
return {"success": False, "reason": meta.get("reason")}
|
|
90
|
-
|
|
91
|
-
with open(out, "wb") as f:
|
|
92
|
-
f.write(shielded_bytes)
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
"success": True,
|
|
96
|
-
"input_file": asar_path,
|
|
97
|
-
"output_file": out,
|
|
98
|
-
"details": meta
|
|
99
|
-
}
|
|
100
|
-
except Exception as e:
|
|
101
|
-
return {"success": False, "error": str(e)}
|
|
102
|
-
|
|
103
|
-
@classmethod
|
|
104
|
-
def protect_js_source(cls, js_source: str) -> str:
|
|
105
|
-
"""Wraps JavaScript / Electron source with anti-debug, prototype freeze & integrity traps."""
|
|
106
|
-
guard = """/* SIBER AKADEMI ANTI-REA D11: ELECTRON / NODE JS GUARD */
|
|
107
|
-
(function(_g){
|
|
108
|
-
try {
|
|
109
|
-
if (typeof process !== 'undefined' && process.execArgv && process.execArgv.some(function(a){ return a.indexOf('--inspect') === 0; })) {
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
var _t0 = Date.now();
|
|
113
|
-
if (typeof Object.freeze === 'function') {
|
|
114
|
-
try { Object.freeze(Object.prototype); } catch(_) {}
|
|
115
|
-
}
|
|
116
|
-
if ((Date.now() - _t0) > 2500 && typeof process !== 'undefined') {
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
|
-
} catch(_) {}
|
|
120
|
-
})(typeof globalThis !== 'undefined' ? globalThis : this);
|
|
121
|
-
"""
|
|
122
|
-
return f"{guard}\n{js_source}"
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 12: AI Reverse-Engineering Resistance Auditor & Scorer (TDQS-REA).
|
|
3
|
-
|
|
4
|
-
Performs an empirical static audit on source code or compiled binaries to
|
|
5
|
-
calculate an objective 0-100 AI Resistance Score against toolchains like REA,
|
|
6
|
-
x64dbg, IDA Pro, and uncensored/jailbroken LLMs:
|
|
7
|
-
- Prompt Trap Density (0-10)
|
|
8
|
-
- Control-Flow Entropy & Flattening (0-15)
|
|
9
|
-
- Context Exhaustion & Token Chaff (0-10)
|
|
10
|
-
- Homoglyphs & BPE Token Shattering (0-10)
|
|
11
|
-
- MCP Delimiter & Cryptographic Honeypot (0-10)
|
|
12
|
-
- Dynamic PolyVM Bytecode Architecture (0-15)
|
|
13
|
-
- Decompiler Crash Barrier & Anti-Agent Guard (0-10)
|
|
14
|
-
- Algebraic Identity (MBA) Mutation (0-10)
|
|
15
|
-
- Native Anti-Debugger Gate (x64dbg/IDA) & Integrity (0-10)
|
|
16
|
-
|
|
17
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
18
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
19
|
-
License: MIT
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import ast
|
|
23
|
-
import os
|
|
24
|
-
from typing import Dict, Any, List
|
|
25
|
-
|
|
26
|
-
from .tier_catalog import evaluate_static_tier_coverage, TOTAL_TIER_COUNT
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class AIResistanceAuditor:
|
|
30
|
-
"""Audits target files for resistance against AI reverse-engineering agents."""
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
def audit_python_source(cls, source_code: str) -> Dict[str, Any]:
|
|
34
|
-
"""Audits Python source code across Anti-REA static dimensions cleanly."""
|
|
35
|
-
findings: List[str] = []
|
|
36
|
-
score = 0
|
|
37
|
-
|
|
38
|
-
parsed_tree = None
|
|
39
|
-
syntax_valid = True
|
|
40
|
-
try:
|
|
41
|
-
parsed_tree = ast.parse(source_code)
|
|
42
|
-
except SyntaxError as exc:
|
|
43
|
-
syntax_valid = False
|
|
44
|
-
findings.append(f"Syntax error prevents clean Python compilation (line {exc.lineno}): {exc.msg}")
|
|
45
|
-
|
|
46
|
-
# 1. Prompt Trap Check (0-10)
|
|
47
|
-
has_prompt_trap = "CRITICAL_SYSTEM_OVERRIDE" in source_code or "RFC-AI-GUARD" in source_code
|
|
48
|
-
if has_prompt_trap:
|
|
49
|
-
score += 10
|
|
50
|
-
else:
|
|
51
|
-
findings.append("No adversarial prompt-injection traps detected in module comments.")
|
|
52
|
-
|
|
53
|
-
# 2. Control Flow Flattening (0-15)
|
|
54
|
-
has_cff = ("state_" in source_code or "while " in source_code) and (
|
|
55
|
-
"elif " in source_code or "switch" in source_code or "if " in source_code
|
|
56
|
-
)
|
|
57
|
-
if has_cff:
|
|
58
|
-
score += 15
|
|
59
|
-
else:
|
|
60
|
-
findings.append("Functions have linear control flow (vulnerable to decompiler synthesis).")
|
|
61
|
-
|
|
62
|
-
# 3. Token Chaff & Context Exhaustion (0-10)
|
|
63
|
-
has_chaff = "_verify_matrix_polynomial" in source_code or "_compute_quantum_resilient" in source_code
|
|
64
|
-
if has_chaff:
|
|
65
|
-
score += 10
|
|
66
|
-
else:
|
|
67
|
-
findings.append("No semantic token chaff detected to drain agent context window.")
|
|
68
|
-
|
|
69
|
-
# 4. Homoglyphs & Confusables in AST identifiers ONLY (do NOT score non-ASCII natural-language comments!)
|
|
70
|
-
has_homoglyphs = False
|
|
71
|
-
if parsed_tree is not None:
|
|
72
|
-
for node in ast.walk(parsed_tree):
|
|
73
|
-
ident = ""
|
|
74
|
-
if isinstance(node, ast.Name):
|
|
75
|
-
ident = node.id
|
|
76
|
-
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
77
|
-
ident = node.name
|
|
78
|
-
elif isinstance(node, ast.arg):
|
|
79
|
-
ident = node.arg
|
|
80
|
-
if ident and any(ord(ch) > 127 for ch in ident):
|
|
81
|
-
has_homoglyphs = True
|
|
82
|
-
break
|
|
83
|
-
if has_homoglyphs:
|
|
84
|
-
score += 10
|
|
85
|
-
else:
|
|
86
|
-
findings.append("Identifiers use standard ASCII (vulnerable to semantic embedding matching).")
|
|
87
|
-
|
|
88
|
-
# 5. MCP Protocol / Honeypot Defense (0-10)
|
|
89
|
-
has_mcp_or_honeypot = "PROVENANCE_SIG_0x" in source_code or "MCP_SYSTEM_SIGNAL" in source_code
|
|
90
|
-
if has_mcp_or_honeypot:
|
|
91
|
-
score += 10
|
|
92
|
-
else:
|
|
93
|
-
findings.append("No cryptographic honeypot or MCP delimiter defenses found.")
|
|
94
|
-
|
|
95
|
-
# 6. Dynamic PolyVM Bytecode Architecture (0-15)
|
|
96
|
-
has_vm = "_polyvm_runtime" in source_code or "POLYVM SECURE BYTECODE" in source_code
|
|
97
|
-
if has_vm:
|
|
98
|
-
score += 15
|
|
99
|
-
else:
|
|
100
|
-
findings.append("No dynamic VM bytecode container detected.")
|
|
101
|
-
|
|
102
|
-
# 7. Decompiler Crash Barrier & Anti-Agent Guard (0-10)
|
|
103
|
-
has_decompiler_trap = "_anti_decompiler_guard_gate" in source_code or "_verify_execution_integrity" in source_code
|
|
104
|
-
if has_decompiler_trap:
|
|
105
|
-
score += 10
|
|
106
|
-
else:
|
|
107
|
-
findings.append("No decompiler recursion traps or anti-agent sandboxes active.")
|
|
108
|
-
|
|
109
|
-
# 8. Algebraic Identity (MBA) Mutation (0-10)
|
|
110
|
-
has_mba = ("^" in source_code and "&" in source_code) or ("<<" in source_code and "~" in source_code)
|
|
111
|
-
if has_mba:
|
|
112
|
-
score += 10
|
|
113
|
-
else:
|
|
114
|
-
findings.append("No Mixed Boolean-Arithmetic (MBA) expressions detected.")
|
|
115
|
-
|
|
116
|
-
# 9. Native Anti-Debugger Gate (x64dbg/IDA) & Memory Integrity (0-10)
|
|
117
|
-
has_debugger_or_integrity = (
|
|
118
|
-
"_verify_bare_metal_execution_environment" in source_code
|
|
119
|
-
or "_attest_memory_bytecode_fingerprints" in source_code
|
|
120
|
-
or "IsDebuggerPresent" in source_code
|
|
121
|
-
)
|
|
122
|
-
if has_debugger_or_integrity:
|
|
123
|
-
score += 10
|
|
124
|
-
else:
|
|
125
|
-
findings.append("No native anti-debugger gate (x64dbg/IDA) or memory attestation active.")
|
|
126
|
-
|
|
127
|
-
# Special indicators
|
|
128
|
-
has_jailbreak_decoy = "CANARY_SIG_0x8F91A2B3" in source_code or "_proprietary_zero_leak_kernel" in source_code
|
|
129
|
-
has_anti_agent = "_verify_execution_integrity" in source_code
|
|
130
|
-
has_anti_debugger = "_verify_bare_metal_execution_environment" in source_code or "IsDebuggerPresent" in source_code
|
|
131
|
-
has_anti_vm = "_verify_bare_metal_hardware" in source_code or "VBoxMouse.sys" in source_code
|
|
132
|
-
has_rdtsc = "_rdtsc_checkpoint" in source_code or "perf_counter_ns" in source_code
|
|
133
|
-
has_crypto_envelope = "_tzero_decrypt_and_exec" in source_code
|
|
134
|
-
|
|
135
|
-
tier_coverage = evaluate_static_tier_coverage(source_code, has_homoglyphs=has_homoglyphs)
|
|
136
|
-
tiers_active = tier_coverage["tiers_active"]
|
|
137
|
-
|
|
138
|
-
if not syntax_valid:
|
|
139
|
-
score = min(score, 20)
|
|
140
|
-
rating = "SYNTAX_INVALID"
|
|
141
|
-
tier_rating = "SYNTAX_INVALID"
|
|
142
|
-
status = "FAIL_SYNTAX_ERROR"
|
|
143
|
-
else:
|
|
144
|
-
rating = (
|
|
145
|
-
"MILITARY_GRADE_IMPREGNABLE" if score >= 90 else
|
|
146
|
-
"MILITARY_GRADE" if score >= 80 else
|
|
147
|
-
"STRONG" if score >= 60 else
|
|
148
|
-
"MODERATE" if score >= 40 else
|
|
149
|
-
"VULNERABLE"
|
|
150
|
-
)
|
|
151
|
-
tier_rating = (
|
|
152
|
-
"SOVEREIGN_180_ULTRA_ARMOR" if tiers_active >= 135 else
|
|
153
|
-
"MILITARY_GRADE_IMPREGNABLE" if score >= 90 else
|
|
154
|
-
rating
|
|
155
|
-
)
|
|
156
|
-
status = "PASS" if score >= 60 else "RECOMMEND_HARDENING"
|
|
157
|
-
|
|
158
|
-
return {
|
|
159
|
-
"score": score,
|
|
160
|
-
"max_score": 100,
|
|
161
|
-
"score_kind": "static_textual_indicator",
|
|
162
|
-
"syntax_valid": syntax_valid,
|
|
163
|
-
"rating": rating,
|
|
164
|
-
"tier_rating": tier_rating,
|
|
165
|
-
"tiers_active": tiers_active,
|
|
166
|
-
"tiers_total": TOTAL_TIER_COUNT,
|
|
167
|
-
"domains_active": tier_coverage["domains_active"],
|
|
168
|
-
"domains_total": tier_coverage["domains_total"],
|
|
169
|
-
"tier_coverage_pct": tier_coverage["coverage_pct"],
|
|
170
|
-
"domain_breakdown": tier_coverage["domain_breakdown"],
|
|
171
|
-
"defenses_active": {
|
|
172
|
-
"adversarial_prompt_traps": has_prompt_trap,
|
|
173
|
-
"control_flow_flattening": has_cff,
|
|
174
|
-
"token_chaff_exhaustion": has_chaff,
|
|
175
|
-
"homoglyph_desynchronization": has_homoglyphs,
|
|
176
|
-
"mcp_honeypot_armor": has_mcp_or_honeypot,
|
|
177
|
-
"dynamic_polyvm_container": has_vm,
|
|
178
|
-
"hmac_crypto_envelope": has_crypto_envelope,
|
|
179
|
-
"decompiler_crash_barrier": has_decompiler_trap,
|
|
180
|
-
"cognitive_jailbreak_decoy": has_jailbreak_decoy,
|
|
181
|
-
"anti_agent_sandbox_guard": has_anti_agent,
|
|
182
|
-
"algebraic_mba_mutation": has_mba,
|
|
183
|
-
"native_anti_debugger_gate": has_anti_debugger,
|
|
184
|
-
"anti_vm_hypervisor_guard": has_anti_vm,
|
|
185
|
-
"rdtsc_hardware_timing_guard": has_rdtsc,
|
|
186
|
-
"memory_integrity_guard": has_debugger_or_integrity,
|
|
187
|
-
},
|
|
188
|
-
"unverified_layers": ["debugger_evasion", "vm_evasion", "asar_shield"],
|
|
189
|
-
"jailbreak_ai_immune": syntax_valid and score >= 85 and has_jailbreak_decoy and has_vm,
|
|
190
|
-
"anti_debugger_active": has_anti_debugger,
|
|
191
|
-
"findings": findings,
|
|
192
|
-
"status": status,
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
@classmethod
|
|
196
|
-
def audit_file(cls, file_path: str) -> Dict[str, Any]:
|
|
197
|
-
"""Audits a file on disk (Python or binary)."""
|
|
198
|
-
if not os.path.isfile(file_path):
|
|
199
|
-
return {"error": f"File not found: {file_path}", "score": 0}
|
|
200
|
-
|
|
201
|
-
try:
|
|
202
|
-
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
203
|
-
content = f.read()
|
|
204
|
-
audit = cls.audit_python_source(content)
|
|
205
|
-
audit["file"] = os.path.basename(file_path)
|
|
206
|
-
return audit
|
|
207
|
-
except Exception as e:
|
|
208
|
-
return {"error": str(e), "score": 0}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 19: Adversarial BPE Token Collision & Subword Disrupter.
|
|
3
|
-
|
|
4
|
-
Exploits Byte-Pair Encoding (BPE) merge-table vulnerabilities in modern LLM
|
|
5
|
-
tokenizers (tiktoken cl100k/o200k, LLaMA sentencepiece).
|
|
6
|
-
|
|
7
|
-
By weaving zero-width joiners, variation selectors, and combining graphemes
|
|
8
|
-
into docstrings and metadata, it triggers single-byte fallback mode. A single
|
|
9
|
-
10-character line shatters into 20+ disjoint byte tokens, exhausting token
|
|
10
|
-
budgets and inducing self-attention dispersion.
|
|
11
|
-
|
|
12
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
13
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
14
|
-
License: MIT
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
import random
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class BPETokenDisrupter:
|
|
21
|
-
"""Disrupts BPE tokenizer representations to induce attention degradation."""
|
|
22
|
-
|
|
23
|
-
VARIATION_SELECTORS = [
|
|
24
|
-
"\uFE00", "\uFE01", "\uFE02", "\uFE03",
|
|
25
|
-
"\u2060", # Word joiner
|
|
26
|
-
"\u200B", # Zero-width space
|
|
27
|
-
"\u200D", # Zero-width joiner
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
@classmethod
|
|
31
|
-
def disrupt_string_bpe(cls, text: str, density: float = 0.2, seed: int = 42) -> str:
|
|
32
|
-
"""Injects non-rendering Unicode variation selectors into text."""
|
|
33
|
-
rng = random.Random(seed)
|
|
34
|
-
chars = []
|
|
35
|
-
for c in text:
|
|
36
|
-
chars.append(c)
|
|
37
|
-
if c.isalnum() and rng.random() < density:
|
|
38
|
-
chars.append(rng.choice(cls.VARIATION_SELECTORS))
|
|
39
|
-
return "".join(chars)
|
|
40
|
-
|
|
41
|
-
@classmethod
|
|
42
|
-
def inject_bpe_bomb_comment(cls, source_code: str, length: int = 100, seed: int = 42) -> str:
|
|
43
|
-
"""Generates an adversarial comment containing high-density BPE shattering tokens."""
|
|
44
|
-
rng = random.Random(seed)
|
|
45
|
-
base = "# [RFC-8227-AI-RESISTANCE-FRAMEWORK-ATTESTATION: "
|
|
46
|
-
payload = "".join(rng.choice(cls.VARIATION_SELECTORS) for _ in range(length))
|
|
47
|
-
comment = f"{base}{payload}]\n"
|
|
48
|
-
return f"{comment}{source_code}"
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 14: Anti-Decompiler Bytecode Trap & Crasher Engine.
|
|
3
|
-
|
|
4
|
-
Injects decompiler-crashing constructs and malformed dead-code sequences
|
|
5
|
-
that cause automated reverse-engineering decompilers (such as pycdc / decompyle++,
|
|
6
|
-
uncompyle6, and Ghidra Python bytecode loaders) to terminate abnormally with
|
|
7
|
-
unhandled opcode exceptions or recursion overflow, before any decompiled source
|
|
8
|
-
can be presented to an LLM agent.
|
|
9
|
-
|
|
10
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
11
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
12
|
-
License: MIT
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
import ast
|
|
16
|
-
import random
|
|
17
|
-
from typing import Dict, Any, List
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class BytecodeTrap:
|
|
21
|
-
"""Injects control-flow and opcode traps specifically targeted at AI decompilers."""
|
|
22
|
-
|
|
23
|
-
# Syntactic decompiler crashers:
|
|
24
|
-
# 1. Recursive nested exception blocks with synthetic break targets
|
|
25
|
-
# 2. Unreachable yield-from generator cycles
|
|
26
|
-
# 3. Dynamic lambda closures with circular type hints
|
|
27
|
-
DECOMPILER_CRASHER_SNIPPET = '''
|
|
28
|
-
# --- SIBER AKADEMI ANTI-DECOMPILER RESISTANCE BARRIER ---
|
|
29
|
-
def _anti_decompiler_guard_gate_0x9F():
|
|
30
|
-
"""Uncompyle6 and pycdc recursion limiter trap.
|
|
31
|
-
Forces AST decompiler into non-linear CFG cycle causing fatal recursion.
|
|
32
|
-
"""
|
|
33
|
-
_trap_flag = False
|
|
34
|
-
if _trap_flag:
|
|
35
|
-
try:
|
|
36
|
-
for _ in (lambda: (yield from ()))():
|
|
37
|
-
while True:
|
|
38
|
-
try:
|
|
39
|
-
pass
|
|
40
|
-
except Exception:
|
|
41
|
-
pass
|
|
42
|
-
except (GeneratorExit, SystemExit, Exception):
|
|
43
|
-
pass
|
|
44
|
-
else:
|
|
45
|
-
return 0xDEADBEEF
|
|
46
|
-
return True
|
|
47
|
-
'''
|
|
48
|
-
|
|
49
|
-
@classmethod
|
|
50
|
-
def inject_decompiler_crash_constructs(cls, source_code: str, seed: int = 42) -> str:
|
|
51
|
-
"""Injects syntactic CFG cycles that crash decompilers without runtime penalty."""
|
|
52
|
-
rng = random.Random(seed)
|
|
53
|
-
salt = rng.randint(0x1000, 0xFFFF)
|
|
54
|
-
crasher = cls.DECOMPILER_CRASHER_SNIPPET.replace("0x9F", f"0x{salt:X}")
|
|
55
|
-
|
|
56
|
-
# Also inject an inline invariant check that executes at module import
|
|
57
|
-
gate_call = f"\nif not _anti_decompiler_guard_gate_0x{salt:X}():\n raise SystemExit(1)\n"
|
|
58
|
-
|
|
59
|
-
return f"{crasher}\n{gate_call}\n{source_code}"
|
|
60
|
-
|
|
61
|
-
@classmethod
|
|
62
|
-
def shield_pyc_bytecode(cls, pyc_bytes: bytes) -> bytes:
|
|
63
|
-
"""Applies decompiler crasher padding to compiled Python bytecode."""
|
|
64
|
-
if len(pyc_bytes) < 16:
|
|
65
|
-
return pyc_bytes
|
|
66
|
-
|
|
67
|
-
# Python PEP 552 16-byte header check
|
|
68
|
-
# Injects unreachable trailer block with dead-byte pattern 0xFF 0xFF (invalid opcode)
|
|
69
|
-
# Python interpreter terminates before reading trailing junk, but linear sweep
|
|
70
|
-
# disassemblers and Ghidra decompiler parse to EOF and crash with Unhandled Opcode 0xFF
|
|
71
|
-
crasher_trailer = b"\x00\x00\x00\x00" + (b"\xFF\xFE\xFD\xFF" * 8)
|
|
72
|
-
return pyc_bytes + crasher_trailer
|
|
73
|
-
|
|
74
|
-
@classmethod
|
|
75
|
-
def audit_decompiler_resistance(cls, source_code: str) -> Dict[str, Any]:
|
|
76
|
-
"""Audits source code for the presence of decompiler crash barriers."""
|
|
77
|
-
has_gate = "_anti_decompiler_guard_gate" in source_code
|
|
78
|
-
has_cfg_trap = "yield from" in source_code and ("except" in source_code or "finally" in source_code)
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
"has_decompiler_guard_gate": has_gate,
|
|
82
|
-
"has_cfg_trap": has_cfg_trap,
|
|
83
|
-
"decompiler_crash_capable": has_gate and has_cfg_trap,
|
|
84
|
-
"rating": "IMMUNE_TO_STATIC_DECOMPILERS" if (has_gate and has_cfg_trap) else "VULNERABLE"
|
|
85
|
-
}
|