tzero-mcp 11.15.3 → 12.2.0
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 +4 -4
- package/README.md +5 -5
- package/bin/postinstall.js +10 -2
- package/bin/tzero-mcp.js +1 -1
- package/bin/tzero.js +17 -0
- package/package.json +1 -1
- package/src/addmcp.py +34 -23
- package/src/app.py +1 -1
- package/src/main.py +6 -0
- package/src/tzero/__init__.py +10 -0
- package/src/tzero/anti_rea/__init__.py +70 -0
- package/src/tzero/anti_rea/algebraic_mutator.py +86 -0
- package/src/tzero/anti_rea/anti_agent_guard.py +96 -0
- package/src/tzero/anti_rea/anti_debugger.py +239 -0
- package/src/tzero/anti_rea/anti_vm.py +160 -0
- package/src/tzero/anti_rea/asar_shield.py +99 -0
- package/src/tzero/anti_rea/auditor.py +158 -0
- package/src/tzero/anti_rea/bpe_disrupter.py +48 -0
- package/src/tzero/anti_rea/bytecode_trap.py +85 -0
- package/src/tzero/anti_rea/canary_beacon.py +187 -0
- package/src/tzero/anti_rea/cli.py +102 -0
- package/src/tzero/anti_rea/confusables.py +86 -0
- package/src/tzero/anti_rea/engine.py +204 -0
- package/src/tzero/anti_rea/extractor_shield.py +102 -0
- package/src/tzero/anti_rea/flattener.py +136 -0
- package/src/tzero/anti_rea/gui.py +267 -0
- package/src/tzero/anti_rea/honeypot.py +58 -0
- package/src/tzero/anti_rea/integrity_guard.py +66 -0
- package/src/tzero/anti_rea/jailbreak_decoy.py +77 -0
- package/src/tzero/anti_rea/mcp_poison.py +41 -0
- package/src/tzero/anti_rea/native_bridge.py +169 -0
- package/src/tzero/anti_rea/rdtsc_guard.py +64 -0
- package/src/tzero/anti_rea/string_vault.py +94 -0
- package/src/tzero/anti_rea/sybil_network.py +53 -0
- package/src/tzero/anti_rea/timing_guard.py +46 -0
- package/src/tzero/anti_rea/token_bomb.py +65 -0
- package/src/tzero/anti_rea/traps.py +76 -0
- package/src/tzero/anti_rea/vm_obfuscator.py +182 -0
- package/src/tzero/siber_akademi.ico +0 -0
- package/src/tzero/siber_akademi_icon.py +1 -1
- package/src/tzero/tzero_armor.py +165 -0
- package/src/tzero/tzero_bridge.py +28 -15
- package/src/tzero/tzero_budget.py +10 -3
- package/src/tzero/tzero_card.py +7 -5
- package/src/tzero/tzero_ci.py +1 -0
- package/src/tzero/tzero_contracts.py +30 -11
- package/src/tzero/tzero_dashboard.py +34 -14
- package/src/tzero/tzero_debt.py +14 -5
- package/src/tzero/tzero_federation.py +11 -6
- package/src/tzero/tzero_fixer/security_zero_leak.py +21 -3
- package/src/tzero/tzero_golden.py +11 -6
- package/src/tzero/tzero_graph_hud.html +1 -1
- package/src/tzero/tzero_growth.py +10 -10
- package/src/tzero/tzero_jarvis/agent_guard.py +16 -10
- package/src/tzero/tzero_jarvis/workspace_orchestrator.py +34 -23
- package/src/tzero/tzero_lsp.py +1 -1
- package/src/tzero/tzero_mcp.py +89 -31
- package/src/tzero/tzero_mutation.py +44 -16
- package/src/tzero/tzero_neural_cortex.py +1 -1
- package/src/tzero/tzero_pc_fixer.py +21 -3
- package/src/tzero/tzero_promo.py +196 -36
- package/src/tzero/tzero_rust_bridge.py +1086 -42
- package/src/tzero/tzero_scip.py +15 -2
- package/src/tzero/tzero_semantic_merge.py +34 -10
- package/src/tzero/tzero_task_benchmark.py +2 -2
- package/src/tzero/tzero_telemetry.py +146 -0
- package/src/tzero/tzero_terminal.py +366 -0
- package/src/tzero/tzero_traffic.py +350 -0
- package/src/tzero/tzero_tui.py +342 -133
- package/src/tzero/tzero_v3.py +652 -29
- package/src/tzero/tzero_welcome.py +72 -12
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Tier 21: Native Anti-Debugger & Reverse Engineering Tool Neutralizer.
|
|
3
|
+
|
|
4
|
+
Comprehensive Ring-3 and Win32/POSIX anti-debugging engine designed to detect,
|
|
5
|
+
neutralize, and terminate execution when running under debuggers or dynamic
|
|
6
|
+
analysis frameworks:
|
|
7
|
+
- x64dbg, x32dbg, OllyDbg
|
|
8
|
+
- IDA Pro, IDA64, Ghidra
|
|
9
|
+
- WinDbg, Process Hacker, Cheat Engine
|
|
10
|
+
- Hardware breakpoints (DR0-DR3)
|
|
11
|
+
- NtGlobalFlag heap inspection & PEB BeingDebugged
|
|
12
|
+
- NtSetInformationThread (ThreadHideFromDebugger)
|
|
13
|
+
- Linux ptrace & TracerPid inspection
|
|
14
|
+
|
|
15
|
+
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
16
|
+
Part of Siber Akademi T-Zero Security Suite.
|
|
17
|
+
License: MIT
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
import time
|
|
23
|
+
from typing import Dict, Any, List, Optional
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AntiDebugger:
|
|
27
|
+
"""Detects and neutralizes active debuggers and dynamic analysis tools."""
|
|
28
|
+
|
|
29
|
+
DEBUGGER_PROCESS_NAMES = {
|
|
30
|
+
"x64dbg.exe",
|
|
31
|
+
"x32dbg.exe",
|
|
32
|
+
"ollydbg.exe",
|
|
33
|
+
"ida.exe",
|
|
34
|
+
"ida64.exe",
|
|
35
|
+
"idag.exe",
|
|
36
|
+
"idag64.exe",
|
|
37
|
+
"idaw.exe",
|
|
38
|
+
"idaw64.exe",
|
|
39
|
+
"scylla.exe",
|
|
40
|
+
"scylla_x64.exe",
|
|
41
|
+
"scylla_x86.exe",
|
|
42
|
+
"cheatengine-x86_64.exe",
|
|
43
|
+
"cheatengine-i386.exe",
|
|
44
|
+
"cheatengine.exe",
|
|
45
|
+
"windbg.exe",
|
|
46
|
+
"windbgx.exe",
|
|
47
|
+
"processhacker.exe",
|
|
48
|
+
"procmon.exe",
|
|
49
|
+
"procmon64.exe",
|
|
50
|
+
"procexp.exe",
|
|
51
|
+
"procexp64.exe",
|
|
52
|
+
"ghidra.exe",
|
|
53
|
+
"cutter.exe",
|
|
54
|
+
"radare2.exe",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
DEBUGGER_WINDOW_KEYWORDS = (
|
|
58
|
+
"x64dbg",
|
|
59
|
+
"x32dbg",
|
|
60
|
+
"ida pro",
|
|
61
|
+
"ollydbg",
|
|
62
|
+
"cheat engine",
|
|
63
|
+
"ghidra",
|
|
64
|
+
"windbg",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def is_debugger_present_win32(cls) -> bool:
|
|
69
|
+
"""Checks Windows API IsDebuggerPresent and CheckRemoteDebuggerPresent."""
|
|
70
|
+
if sys.platform != "win32":
|
|
71
|
+
return False
|
|
72
|
+
try:
|
|
73
|
+
import ctypes
|
|
74
|
+
kernel32 = ctypes.windll.kernel32
|
|
75
|
+
if kernel32.IsDebuggerPresent():
|
|
76
|
+
return True
|
|
77
|
+
|
|
78
|
+
# CheckRemoteDebuggerPresent
|
|
79
|
+
is_remote = ctypes.c_bool(False)
|
|
80
|
+
h_process = kernel32.GetCurrentProcess()
|
|
81
|
+
if kernel32.CheckRemoteDebuggerPresent(h_process, ctypes.byref(is_remote)):
|
|
82
|
+
if is_remote.value:
|
|
83
|
+
return True
|
|
84
|
+
except Exception:
|
|
85
|
+
pass
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def check_blacklisted_processes(cls) -> List[str]:
|
|
90
|
+
"""Scans running system processes for known debugger binaries."""
|
|
91
|
+
detected = []
|
|
92
|
+
try:
|
|
93
|
+
if sys.platform == "win32":
|
|
94
|
+
import subprocess
|
|
95
|
+
# Run lightweight tasklist /fo csv
|
|
96
|
+
res = subprocess.run(
|
|
97
|
+
["tasklist", "/fo", "csv", "/nh"],
|
|
98
|
+
capture_output=True,
|
|
99
|
+
text=True,
|
|
100
|
+
timeout=3,
|
|
101
|
+
creationflags=0x08000000 if hasattr(subprocess, "CREATE_NO_WINDOW") else 0
|
|
102
|
+
)
|
|
103
|
+
output_lower = res.stdout.lower()
|
|
104
|
+
for proc in cls.DEBUGGER_PROCESS_NAMES:
|
|
105
|
+
if proc in output_lower:
|
|
106
|
+
detected.append(proc)
|
|
107
|
+
else:
|
|
108
|
+
# POSIX process check
|
|
109
|
+
for pid_dir in os.listdir("/proc"):
|
|
110
|
+
if pid_dir.isdigit():
|
|
111
|
+
try:
|
|
112
|
+
with open(f"/proc/{pid_dir}/comm", "r") as f:
|
|
113
|
+
comm = f.read().strip().lower()
|
|
114
|
+
for proc in cls.DEBUGGER_PROCESS_NAMES:
|
|
115
|
+
if proc.replace(".exe", "") == comm:
|
|
116
|
+
detected.append(comm)
|
|
117
|
+
except Exception:
|
|
118
|
+
continue
|
|
119
|
+
except Exception:
|
|
120
|
+
pass
|
|
121
|
+
return list(set(detected))
|
|
122
|
+
|
|
123
|
+
@classmethod
|
|
124
|
+
def is_tracer_pid_active_posix(cls) -> bool:
|
|
125
|
+
"""Checks /proc/self/status for TracerPid on Linux."""
|
|
126
|
+
if sys.platform == "win32":
|
|
127
|
+
return False
|
|
128
|
+
try:
|
|
129
|
+
with open("/proc/self/status", "r") as f:
|
|
130
|
+
for line in f:
|
|
131
|
+
if line.startswith("TracerPid:"):
|
|
132
|
+
pid = int(line.split(":")[1].strip())
|
|
133
|
+
return pid != 0
|
|
134
|
+
except Exception:
|
|
135
|
+
pass
|
|
136
|
+
return False
|
|
137
|
+
|
|
138
|
+
@classmethod
|
|
139
|
+
def thread_hide_from_debugger_win32(cls) -> bool:
|
|
140
|
+
"""Invokes NtSetInformationThread with ThreadHideFromDebugger (0x11)."""
|
|
141
|
+
if sys.platform != "win32":
|
|
142
|
+
return False
|
|
143
|
+
try:
|
|
144
|
+
import ctypes
|
|
145
|
+
ntdll = ctypes.windll.ntdll
|
|
146
|
+
kernel32 = ctypes.windll.kernel32
|
|
147
|
+
current_thread = kernel32.GetCurrentThread()
|
|
148
|
+
# 0x11 = ThreadHideFromDebugger
|
|
149
|
+
status = ntdll.NtSetInformationThread(current_thread, 0x11, 0, 0)
|
|
150
|
+
return status == 0
|
|
151
|
+
except Exception:
|
|
152
|
+
return False
|
|
153
|
+
|
|
154
|
+
@classmethod
|
|
155
|
+
def scan_debugger_environment(cls) -> Dict[str, Any]:
|
|
156
|
+
"""Performs a comprehensive scan of host debugger artifacts."""
|
|
157
|
+
py_tracer = sys.gettrace() is not None
|
|
158
|
+
win32_dbg = cls.is_debugger_present_win32()
|
|
159
|
+
posix_tracer = cls.is_tracer_pid_active_posix()
|
|
160
|
+
detected_procs = cls.check_blacklisted_processes()
|
|
161
|
+
|
|
162
|
+
is_debugged = py_tracer or win32_dbg or posix_tracer or bool(detected_procs)
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
"debugger_detected": is_debugged,
|
|
166
|
+
"python_tracer_active": py_tracer,
|
|
167
|
+
"win32_debugger_active": win32_dbg,
|
|
168
|
+
"posix_tracer_active": posix_tracer,
|
|
169
|
+
"blacklisted_debuggers_running": detected_procs,
|
|
170
|
+
"status": "DEBUGGER_ATTACHED_OR_RUNNING" if is_debugged else "SECURE_BARE_METAL"
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@classmethod
|
|
174
|
+
def enforce_guard(cls, action: str = "terminate") -> None:
|
|
175
|
+
"""Enforces anti-debugging policy: terminates immediately if debugger detected."""
|
|
176
|
+
scan = cls.scan_debugger_environment()
|
|
177
|
+
if scan["debugger_detected"]:
|
|
178
|
+
if action == "terminate":
|
|
179
|
+
# Instant hard exit without triggering standard Python tracebacks
|
|
180
|
+
if sys.platform == "win32":
|
|
181
|
+
try:
|
|
182
|
+
import ctypes
|
|
183
|
+
ctypes.windll.kernel32.ExitProcess(0xC0000409)
|
|
184
|
+
except Exception:
|
|
185
|
+
pass
|
|
186
|
+
os._exit(1)
|
|
187
|
+
elif action == "divert":
|
|
188
|
+
# Corrupt internal state silently
|
|
189
|
+
os.environ["_DEFENSE_DIVERGENCE_TRIGGERED"] = "1"
|
|
190
|
+
|
|
191
|
+
@classmethod
|
|
192
|
+
def get_injected_guard_snippet(cls) -> str:
|
|
193
|
+
"""Generates self-contained anti-debugging boiler for protected source files."""
|
|
194
|
+
return '''
|
|
195
|
+
# --- SIBER AKADEMI NATIVE ANTI-DEBUGGER RESISTANCE GATE ---
|
|
196
|
+
def _verify_bare_metal_execution_environment():
|
|
197
|
+
"""Detects and terminates execution under x64dbg, IDA Pro, WinDbg, or tracers."""
|
|
198
|
+
import os, sys
|
|
199
|
+
|
|
200
|
+
# 1. Active Python tracer / debugger
|
|
201
|
+
if sys.gettrace() is not None:
|
|
202
|
+
os._exit(1)
|
|
203
|
+
|
|
204
|
+
# 2. Windows Native Debugger Check
|
|
205
|
+
if sys.platform == "win32":
|
|
206
|
+
try:
|
|
207
|
+
import ctypes
|
|
208
|
+
k32 = ctypes.windll.kernel32
|
|
209
|
+
if k32.IsDebuggerPresent():
|
|
210
|
+
k32.ExitProcess(0xC0000409)
|
|
211
|
+
is_remote = ctypes.c_bool(False)
|
|
212
|
+
if k32.CheckRemoteDebuggerPresent(k32.GetCurrentProcess(), ctypes.byref(is_remote)) and is_remote.value:
|
|
213
|
+
k32.ExitProcess(0xC0000409)
|
|
214
|
+
# ThreadHideFromDebugger
|
|
215
|
+
ctypes.windll.ntdll.NtSetInformationThread(k32.GetCurrentThread(), 0x11, 0, 0)
|
|
216
|
+
except Exception:
|
|
217
|
+
pass
|
|
218
|
+
|
|
219
|
+
# 3. Linux TracerPid Check
|
|
220
|
+
if os.path.exists("/proc/self/status"):
|
|
221
|
+
try:
|
|
222
|
+
with open("/proc/self/status", "r") as f:
|
|
223
|
+
for line in f:
|
|
224
|
+
if line.startswith("TracerPid:"):
|
|
225
|
+
if int(line.split(":")[1].strip()) != 0:
|
|
226
|
+
os._exit(1)
|
|
227
|
+
except Exception:
|
|
228
|
+
pass
|
|
229
|
+
|
|
230
|
+
return True
|
|
231
|
+
|
|
232
|
+
_BARE_METAL_VERIFIED = _verify_bare_metal_execution_environment()
|
|
233
|
+
'''
|
|
234
|
+
|
|
235
|
+
@classmethod
|
|
236
|
+
def inject_anti_debugger_into_source(cls, source_code: str) -> str:
|
|
237
|
+
"""Injects standalone anti-debugging barrier into Python source code."""
|
|
238
|
+
snippet = cls.get_injected_guard_snippet().strip()
|
|
239
|
+
return f"{snippet}\n\n{source_code}"
|
|
@@ -0,0 +1,160 @@
|
|
|
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
|
+
'''
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
import json
|
|
26
|
+
from typing import Dict, Any, Optional, Tuple
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AsarShield:
|
|
30
|
+
"""Shields Electron .asar archives against automated AI unpackers."""
|
|
31
|
+
|
|
32
|
+
ASAR_MAGIC = b"\x04\x00\x00\x00"
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def is_asar_archive(cls, file_bytes: bytes) -> bool:
|
|
36
|
+
"""Verifies if byte stream matches Electron ASAR archive signature."""
|
|
37
|
+
return len(file_bytes) >= 16 and file_bytes[:4] == cls.ASAR_MAGIC
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def shield_asar_bytes(cls, asar_bytes: bytes) -> Tuple[bytes, Dict[str, Any]]:
|
|
41
|
+
"""Applies header corruption traps to Electron ASAR archive bytes."""
|
|
42
|
+
if not cls.is_asar_archive(asar_bytes):
|
|
43
|
+
return asar_bytes, {
|
|
44
|
+
"shielded": False,
|
|
45
|
+
"reason": "Not a valid Electron ASAR archive header"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
data = bytearray(asar_bytes)
|
|
49
|
+
|
|
50
|
+
# Read original header sizes
|
|
51
|
+
orig_u32_4 = struct.unpack("<I", data[0:4])[0]
|
|
52
|
+
orig_total_size = struct.unpack("<I", data[4:8])[0]
|
|
53
|
+
orig_header_size = struct.unpack("<I", data[8:12])[0]
|
|
54
|
+
orig_json_len = struct.unpack("<I", data[12:16])[0]
|
|
55
|
+
|
|
56
|
+
# Inject Decoy Archive Poison:
|
|
57
|
+
# In ASAR extraction, if json_len > header_size, standard unpackers throw
|
|
58
|
+
# "Error: Invalid header size" or crash with buffer overflow.
|
|
59
|
+
# We craft a dual-stage poisoned header:
|
|
60
|
+
poisoned_json_len = orig_json_len ^ 0x00000001
|
|
61
|
+
data[12:16] = struct.pack("<I", poisoned_json_len)
|
|
62
|
+
|
|
63
|
+
# Append corrupted canary trailer
|
|
64
|
+
canary_trailer = b"\x00\x00\x00\x00" + b"ELECTRON_ASAR_SHIELD_CANARY_0x7B" + (b"\xFF" * 16)
|
|
65
|
+
shielded_data = bytes(data) + canary_trailer
|
|
66
|
+
|
|
67
|
+
return shielded_data, {
|
|
68
|
+
"shielded": True,
|
|
69
|
+
"original_json_len": orig_json_len,
|
|
70
|
+
"poisoned_json_len": poisoned_json_len,
|
|
71
|
+
"status": "ASAR_EXTRACTOR_POISONED"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def shield_asar_file(cls, asar_path: str, output_path: Optional[str] = None) -> Dict[str, Any]:
|
|
76
|
+
"""Shields an Electron app.asar file on disk."""
|
|
77
|
+
if not os.path.isfile(asar_path):
|
|
78
|
+
return {"success": False, "error": f"File not found: {asar_path}"}
|
|
79
|
+
|
|
80
|
+
out = output_path or asar_path
|
|
81
|
+
try:
|
|
82
|
+
with open(asar_path, "rb") as f:
|
|
83
|
+
content = f.read()
|
|
84
|
+
|
|
85
|
+
shielded_bytes, meta = cls.shield_asar_bytes(content)
|
|
86
|
+
if not meta["shielded"]:
|
|
87
|
+
return {"success": False, "reason": meta.get("reason")}
|
|
88
|
+
|
|
89
|
+
with open(out, "wb") as f:
|
|
90
|
+
f.write(shielded_bytes)
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
"success": True,
|
|
94
|
+
"input_file": asar_path,
|
|
95
|
+
"output_file": out,
|
|
96
|
+
"details": meta
|
|
97
|
+
}
|
|
98
|
+
except Exception as e:
|
|
99
|
+
return {"success": False, "error": str(e)}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 os
|
|
23
|
+
from typing import Dict, Any, List
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AIResistanceAuditor:
|
|
27
|
+
"""Audits target files for resistance against AI reverse-engineering agents."""
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def audit_python_source(cls, source_code: str) -> Dict[str, Any]:
|
|
31
|
+
"""Audits Python source code across all Anti-REA defense dimensions."""
|
|
32
|
+
findings: List[str] = []
|
|
33
|
+
score = 0
|
|
34
|
+
|
|
35
|
+
# 1. Prompt Trap Check (0-10)
|
|
36
|
+
has_prompt_trap = "CRITICAL_SYSTEM_OVERRIDE" in source_code or "RFC-AI-GUARD" in source_code
|
|
37
|
+
if has_prompt_trap:
|
|
38
|
+
score += 10
|
|
39
|
+
else:
|
|
40
|
+
findings.append("No adversarial prompt-injection traps detected in module comments.")
|
|
41
|
+
|
|
42
|
+
# 2. Control Flow Flattening (0-15)
|
|
43
|
+
has_cff = ("state_" in source_code or "while " in source_code) and (
|
|
44
|
+
"elif " in source_code or "switch" in source_code or "if " in source_code
|
|
45
|
+
)
|
|
46
|
+
if has_cff:
|
|
47
|
+
score += 15
|
|
48
|
+
else:
|
|
49
|
+
findings.append("Functions have linear control flow (vulnerable to decompiler synthesis).")
|
|
50
|
+
|
|
51
|
+
# 3. Token Chaff & Context Exhaustion (0-10)
|
|
52
|
+
has_chaff = "_verify_matrix_polynomial" in source_code or "_compute_quantum_resilient" in source_code
|
|
53
|
+
if has_chaff:
|
|
54
|
+
score += 10
|
|
55
|
+
else:
|
|
56
|
+
findings.append("No semantic token chaff detected to drain agent context window.")
|
|
57
|
+
|
|
58
|
+
# 4. Homoglyphs & Confusables (0-10)
|
|
59
|
+
has_homoglyphs = any(ord(char) > 127 for char in source_code)
|
|
60
|
+
if has_homoglyphs:
|
|
61
|
+
score += 10
|
|
62
|
+
else:
|
|
63
|
+
findings.append("Identifiers use standard ASCII (vulnerable to semantic embedding matching).")
|
|
64
|
+
|
|
65
|
+
# 5. MCP Protocol / Honeypot Defense (0-10)
|
|
66
|
+
has_mcp_or_honeypot = "PROVENANCE_SIG_0x" in source_code or "MCP_SYSTEM_SIGNAL" in source_code
|
|
67
|
+
if has_mcp_or_honeypot:
|
|
68
|
+
score += 10
|
|
69
|
+
else:
|
|
70
|
+
findings.append("No cryptographic honeypot or MCP delimiter defenses found.")
|
|
71
|
+
|
|
72
|
+
# 6. Dynamic PolyVM Bytecode Architecture (0-15)
|
|
73
|
+
has_vm = "_polyvm_runtime" in source_code or "POLYVM SECURE BYTECODE" in source_code
|
|
74
|
+
if has_vm:
|
|
75
|
+
score += 15
|
|
76
|
+
else:
|
|
77
|
+
findings.append("No dynamic VM bytecode container detected.")
|
|
78
|
+
|
|
79
|
+
# 7. Decompiler Crash Barrier & Anti-Agent Guard (0-10)
|
|
80
|
+
has_decompiler_trap = "_anti_decompiler_guard_gate" in source_code or "_verify_execution_integrity" in source_code
|
|
81
|
+
if has_decompiler_trap:
|
|
82
|
+
score += 10
|
|
83
|
+
else:
|
|
84
|
+
findings.append("No decompiler recursion traps or anti-agent sandboxes active.")
|
|
85
|
+
|
|
86
|
+
# 8. Algebraic Identity (MBA) Mutation (0-10)
|
|
87
|
+
has_mba = ("^" in source_code and "&" in source_code) or ("<<" in source_code and "~" in source_code)
|
|
88
|
+
if has_mba:
|
|
89
|
+
score += 10
|
|
90
|
+
else:
|
|
91
|
+
findings.append("No Mixed Boolean-Arithmetic (MBA) expressions detected.")
|
|
92
|
+
|
|
93
|
+
# 9. Native Anti-Debugger Gate (x64dbg/IDA) & Memory Integrity (0-10)
|
|
94
|
+
has_debugger_or_integrity = (
|
|
95
|
+
"_verify_bare_metal_execution_environment" in source_code
|
|
96
|
+
or "_attest_memory_bytecode_fingerprints" in source_code
|
|
97
|
+
or "IsDebuggerPresent" in source_code
|
|
98
|
+
)
|
|
99
|
+
if has_debugger_or_integrity:
|
|
100
|
+
score += 10
|
|
101
|
+
else:
|
|
102
|
+
findings.append("No native anti-debugger gate (x64dbg/IDA) or memory attestation active.")
|
|
103
|
+
|
|
104
|
+
# Special indicators
|
|
105
|
+
has_jailbreak_decoy = "CANARY_SIG_0x8F91A2B3" in source_code or "_proprietary_zero_leak_kernel" in source_code
|
|
106
|
+
has_anti_agent = "_verify_execution_integrity" in source_code
|
|
107
|
+
has_anti_debugger = "_verify_bare_metal_execution_environment" in source_code or "IsDebuggerPresent" in source_code
|
|
108
|
+
has_anti_vm = "_verify_bare_metal_hardware" in source_code or "VBoxMouse.sys" in source_code
|
|
109
|
+
has_rdtsc = "_rdtsc_checkpoint" in source_code or "perf_counter_ns" in source_code
|
|
110
|
+
|
|
111
|
+
rating = (
|
|
112
|
+
"MILITARY_GRADE_IMPREGNABLE" if score >= 90 else
|
|
113
|
+
"MILITARY_GRADE" if score >= 80 else
|
|
114
|
+
"STRONG" if score >= 60 else
|
|
115
|
+
"MODERATE" if score >= 40 else
|
|
116
|
+
"VULNERABLE"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
"score": score,
|
|
121
|
+
"max_score": 100,
|
|
122
|
+
"rating": rating,
|
|
123
|
+
"defenses_active": {
|
|
124
|
+
"adversarial_prompt_traps": has_prompt_trap,
|
|
125
|
+
"control_flow_flattening": has_cff,
|
|
126
|
+
"token_chaff_exhaustion": has_chaff,
|
|
127
|
+
"homoglyph_desynchronization": has_homoglyphs,
|
|
128
|
+
"mcp_honeypot_armor": has_mcp_or_honeypot,
|
|
129
|
+
"dynamic_polyvm_container": has_vm,
|
|
130
|
+
"decompiler_crash_barrier": has_decompiler_trap,
|
|
131
|
+
"cognitive_jailbreak_decoy": has_jailbreak_decoy,
|
|
132
|
+
"anti_agent_sandbox_guard": has_anti_agent,
|
|
133
|
+
"algebraic_mba_mutation": has_mba,
|
|
134
|
+
"native_anti_debugger_gate": has_anti_debugger,
|
|
135
|
+
"anti_vm_hypervisor_guard": has_anti_vm,
|
|
136
|
+
"rdtsc_hardware_timing_guard": has_rdtsc,
|
|
137
|
+
"memory_integrity_guard": has_debugger_or_integrity,
|
|
138
|
+
},
|
|
139
|
+
"jailbreak_ai_immune": score >= 85 and has_jailbreak_decoy and has_vm,
|
|
140
|
+
"anti_debugger_active": has_anti_debugger,
|
|
141
|
+
"findings": findings,
|
|
142
|
+
"status": "PASS" if score >= 60 else "RECOMMEND_HARDENING"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@classmethod
|
|
146
|
+
def audit_file(cls, file_path: str) -> Dict[str, Any]:
|
|
147
|
+
"""Audits a file on disk (Python or binary)."""
|
|
148
|
+
if not os.path.isfile(file_path):
|
|
149
|
+
return {"error": f"File not found: {file_path}", "score": 0}
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
|
|
153
|
+
content = f.read()
|
|
154
|
+
audit = cls.audit_python_source(content)
|
|
155
|
+
audit["file"] = os.path.basename(file_path)
|
|
156
|
+
return audit
|
|
157
|
+
except Exception as e:
|
|
158
|
+
return {"error": str(e), "score": 0}
|