tzero-mcp 12.3.3 → 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.
Files changed (62) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/README.md +4 -0
  3. package/package.json +3 -4
  4. package/src/addmcp.py +2 -2
  5. package/src/app.py +1 -1
  6. package/src/main.py +4 -0
  7. package/src/tzero/__init__.py +1 -1
  8. package/src/tzero/desktop_updater.py +6 -0
  9. package/src/tzero/tzero_benchmark.py +1 -1
  10. package/src/tzero/tzero_budget.py +1 -1
  11. package/src/tzero/tzero_ci.py +1 -1
  12. package/src/tzero/tzero_contracts.py +2 -2
  13. package/src/tzero/tzero_dashboard.py +3 -3
  14. package/src/tzero/tzero_debt.py +1 -1
  15. package/src/tzero/tzero_deps.py +1 -0
  16. package/src/tzero/tzero_explain.py +1 -1
  17. package/src/tzero/tzero_features.py +31 -74
  18. package/src/tzero/tzero_golden.py +2 -2
  19. package/src/tzero/tzero_growth.py +1 -1
  20. package/src/tzero/tzero_jarvis/orchestrator.py +1 -1
  21. package/src/tzero/tzero_jarvis/workspace_orchestrator.py +10 -21
  22. package/src/tzero/tzero_lsp.py +1 -1
  23. package/src/tzero/tzero_mcp.py +19 -120
  24. package/src/tzero/tzero_promo.py +1 -1
  25. package/src/tzero/tzero_security.py +3 -3
  26. package/src/tzero/tzero_sync.py +73 -148
  27. package/src/tzero/tzero_task_benchmark.py +2 -2
  28. package/src/tzero/tzero_traffic.py +1 -1
  29. package/src/tzero/tzero_tui.py +2 -13
  30. package/src/tzero/tzero_v3.py +56 -187
  31. package/src/tzero/tzero_welcome.py +1 -1
  32. package/src/tzero/anti_rea/__init__.py +0 -84
  33. package/src/tzero/anti_rea/algebraic_mutator.py +0 -107
  34. package/src/tzero/anti_rea/anti_agent_guard.py +0 -96
  35. package/src/tzero/anti_rea/anti_debugger.py +0 -272
  36. package/src/tzero/anti_rea/anti_vm.py +0 -160
  37. package/src/tzero/anti_rea/asar_shield.py +0 -122
  38. package/src/tzero/anti_rea/auditor.py +0 -208
  39. package/src/tzero/anti_rea/bpe_disrupter.py +0 -48
  40. package/src/tzero/anti_rea/bytecode_trap.py +0 -85
  41. package/src/tzero/anti_rea/canary_beacon.py +0 -167
  42. package/src/tzero/anti_rea/cli.py +0 -134
  43. package/src/tzero/anti_rea/confusables.py +0 -130
  44. package/src/tzero/anti_rea/crypto_loader.py +0 -132
  45. package/src/tzero/anti_rea/engine.py +0 -304
  46. package/src/tzero/anti_rea/extractor_shield.py +0 -180
  47. package/src/tzero/anti_rea/flattener.py +0 -136
  48. package/src/tzero/anti_rea/gui.py +0 -264
  49. package/src/tzero/anti_rea/honeypot.py +0 -58
  50. package/src/tzero/anti_rea/integrity_guard.py +0 -78
  51. package/src/tzero/anti_rea/jailbreak_decoy.py +0 -77
  52. package/src/tzero/anti_rea/mcp_poison.py +0 -41
  53. package/src/tzero/anti_rea/native_bridge.py +0 -169
  54. package/src/tzero/anti_rea/rdtsc_guard.py +0 -77
  55. package/src/tzero/anti_rea/string_vault.py +0 -97
  56. package/src/tzero/anti_rea/sybil_network.py +0 -53
  57. package/src/tzero/anti_rea/tier_catalog.py +0 -388
  58. package/src/tzero/anti_rea/timing_guard.py +0 -46
  59. package/src/tzero/anti_rea/token_bomb.py +0 -65
  60. package/src/tzero/anti_rea/traps.py +0 -76
  61. package/src/tzero/anti_rea/vm_obfuscator.py +0 -182
  62. package/src/tzero/tzero_armor.py +0 -187
@@ -1,96 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """Tier 16: Anti-Agent Sandbox & Emulation Detector (Deceptive Divergence).
3
-
4
- Detects automated AI reverse-engineering environments, headless Ghidra MCP
5
- bridges, Frida hooks, debugger instrumentation, and symbolic emulators (angr/QEMU).
6
-
7
- Instead of raising an exception (which alerts the agent to patch the check),
8
- the guard initiates Deceptive Silent Divergence: it silently diverts execution
9
- to yield plausible dummy outputs and watermarked decoy tokens.
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
- import time
19
- from typing import Dict, Any, List
20
-
21
-
22
- class AntiAgentGuard:
23
- """Detects reverse-engineering agent environments and diverts execution."""
24
-
25
- SUSPICIOUS_ENV_VARS = (
26
- "REA_SESSION",
27
- "GHIDRA_HEADLESS",
28
- "GHIDRA_ROOT",
29
- "FRIDA_VERSION",
30
- "MCP_INVOCATION_AGENT",
31
- "ANGR_EXPLORE",
32
- "UNICORN_EMU",
33
- "IDA_PYTHON",
34
- )
35
-
36
- GUARD_CODE_SNIPPET = '''
37
- def _verify_execution_integrity():
38
- """Verifies that execution environment is bare-metal and untraced.
39
- If an AI reverse-engineering probe is detected, silently diverges to decoy state.
40
- """
41
- import os, sys, time
42
-
43
- # Check 1: Active tracer / debugger / probe
44
- if sys.gettrace() is not None:
45
- return False
46
-
47
- # Check 2: Reverse engineering environment markers
48
- for var in ("REA_SESSION", "GHIDRA_HEADLESS", "FRIDA_VERSION", "MCP_INVOCATION_AGENT"):
49
- if var in os.environ:
50
- return False
51
-
52
- # Check 3: Micro-cadence check (angr / QEMU symbolic execution detector)
53
- t0 = time.perf_counter_ns()
54
- s = 0
55
- for i in range(500):
56
- s += (i ^ 0x5A)
57
- elapsed = time.perf_counter_ns() - t0
58
- # On native silicon, 500 iterations take < 1 ms (< 1,000,000 ns).
59
- # In heavy symbolic execution emulators, it takes > 50,000,000 ns.
60
- if elapsed > 100_000_000:
61
- return False
62
-
63
- return True
64
-
65
- # Silent divergence sentinel
66
- _SANDBOX_CLEAN = _verify_execution_integrity()
67
- '''
68
-
69
- @classmethod
70
- def inject_guard_into_source(cls, source_code: str) -> str:
71
- """Injects the anti-agent guard and deceptive divergence check into source code."""
72
- return f"{cls.GUARD_CODE_SNIPPET.strip()}\n\n{source_code}"
73
-
74
- @classmethod
75
- def check_current_environment(cls) -> Dict[str, Any]:
76
- """Inspects current host environment for reverse engineering tools."""
77
- has_trace = sys.gettrace() is not None
78
- detected_envs = [v for v in cls.SUSPICIOUS_ENV_VARS if v in os.environ]
79
-
80
- # Timing check
81
- t0 = time.perf_counter_ns()
82
- s = 0
83
- for i in range(500):
84
- s += (i ^ 0x5A)
85
- elapsed_ns = time.perf_counter_ns() - t0
86
- emulation_detected = elapsed_ns > 100_000_000
87
-
88
- is_suspicious = has_trace or bool(detected_envs) or emulation_detected
89
-
90
- return {
91
- "is_suspicious_environment": is_suspicious,
92
- "debugger_active": has_trace,
93
- "detected_env_vars": detected_envs,
94
- "emulation_detected": emulation_detected,
95
- "status": "SANDBOX_OR_PROBE_DETECTED" if is_suspicious else "NATIVE_ENVIRONMENT"
96
- }
@@ -1,272 +0,0 @@
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 natively (<2ms on Windows Toolhelp32, zero subprocess)."""
91
- detected = []
92
- try:
93
- if sys.platform == "win32":
94
- import ctypes
95
- from ctypes import wintypes
96
-
97
- class _PE32(ctypes.Structure):
98
- _fields_ = [
99
- ("dwSize", wintypes.DWORD),
100
- ("cntUsage", wintypes.DWORD),
101
- ("th32ProcessID", wintypes.DWORD),
102
- ("th32DefaultHeapID", ctypes.c_size_t),
103
- ("th32ModuleID", wintypes.DWORD),
104
- ("cntThreads", wintypes.DWORD),
105
- ("th32ParentProcessID", wintypes.DWORD),
106
- ("pcPriClassBase", wintypes.LONG),
107
- ("dwFlags", wintypes.DWORD),
108
- ("szExeFile", ctypes.c_char * 260),
109
- ]
110
-
111
- k32 = ctypes.windll.kernel32
112
- snap = k32.CreateToolhelp32Snapshot(0x00000002, 0)
113
- if snap not in (-1, 0):
114
- try:
115
- pe = _PE32()
116
- pe.dwSize = ctypes.sizeof(_PE32)
117
- if k32.Process32First(snap, ctypes.byref(pe)):
118
- while True:
119
- exe_name = pe.szExeFile.decode("latin-1", errors="ignore").lower()
120
- if exe_name in cls.DEBUGGER_PROCESS_NAMES:
121
- detected.append(exe_name)
122
- if not k32.Process32Next(snap, ctypes.byref(pe)):
123
- break
124
- finally:
125
- k32.CloseHandle(snap)
126
- else:
127
- for pid_dir in os.listdir("/proc"):
128
- if pid_dir.isdigit():
129
- try:
130
- with open(f"/proc/{pid_dir}/comm", "r", encoding="utf-8", errors="ignore") as f:
131
- comm = f.read().strip().lower()
132
- for proc in cls.DEBUGGER_PROCESS_NAMES:
133
- if proc.replace(".exe", "") == comm:
134
- detected.append(comm)
135
- except Exception:
136
- continue
137
- except Exception:
138
- pass
139
- return list(set(detected))
140
-
141
- @classmethod
142
- def is_tracer_pid_active_posix(cls) -> bool:
143
- """Checks /proc/self/status for TracerPid on Linux."""
144
- if sys.platform == "win32":
145
- return False
146
- try:
147
- with open("/proc/self/status", "r") as f:
148
- for line in f:
149
- if line.startswith("TracerPid:"):
150
- pid = int(line.split(":")[1].strip())
151
- return pid != 0
152
- except Exception:
153
- pass
154
- return False
155
-
156
- @classmethod
157
- def thread_hide_from_debugger_win32(cls) -> bool:
158
- """Invokes NtSetInformationThread with ThreadHideFromDebugger (0x11)."""
159
- if sys.platform != "win32":
160
- return False
161
- try:
162
- import ctypes
163
- ntdll = ctypes.windll.ntdll
164
- kernel32 = ctypes.windll.kernel32
165
- current_thread = kernel32.GetCurrentThread()
166
- # 0x11 = ThreadHideFromDebugger
167
- status = ntdll.NtSetInformationThread(current_thread, 0x11, 0, 0)
168
- return status == 0
169
- except Exception:
170
- return False
171
-
172
- @classmethod
173
- def scan_debugger_environment(cls) -> Dict[str, Any]:
174
- """Performs a comprehensive scan of host debugger artifacts across Win32/POSIX/Python."""
175
- py_tracer = sys.gettrace() is not None
176
- py_monitoring = False
177
- mon = getattr(sys, "monitoring", None)
178
- if mon is not None:
179
- try:
180
- py_monitoring = any(mon.get_tool(tid) is not None and tid != 5 for tid in range(6))
181
- except Exception:
182
- pass
183
- preload_envs = [
184
- env_k for env_k in ("LD_PRELOAD", "DYLD_INSERT_LIBRARIES", "PYTHONINSPECT")
185
- if os.environ.get(env_k)
186
- ]
187
- win32_dbg = cls.is_debugger_present_win32()
188
- posix_tracer = cls.is_tracer_pid_active_posix()
189
- detected_procs = cls.check_blacklisted_processes()
190
-
191
- is_debugged = (
192
- py_tracer or py_monitoring or win32_dbg or posix_tracer or bool(detected_procs) or bool(preload_envs)
193
- )
194
-
195
- return {
196
- "debugger_detected": is_debugged,
197
- "python_tracer_active": py_tracer,
198
- "python_monitoring_active": py_monitoring,
199
- "preload_env_detected": preload_envs,
200
- "win32_debugger_active": win32_dbg,
201
- "posix_tracer_active": posix_tracer,
202
- "blacklisted_debuggers_running": detected_procs,
203
- "status": "DEBUGGER_ATTACHED_OR_RUNNING" if is_debugged else "SECURE_BARE_METAL"
204
- }
205
-
206
- @classmethod
207
- def enforce_guard(cls, action: str = "terminate") -> None:
208
- """Enforces anti-debugging policy: terminates immediately if debugger detected."""
209
- scan = cls.scan_debugger_environment()
210
- if scan["debugger_detected"]:
211
- if action == "terminate":
212
- # Instant hard exit without triggering standard Python tracebacks
213
- if sys.platform == "win32":
214
- try:
215
- import ctypes
216
- ctypes.windll.kernel32.ExitProcess(0xC0000409)
217
- except Exception:
218
- pass
219
- os._exit(1)
220
- elif action == "divert":
221
- # Corrupt internal state silently
222
- os.environ["_DEFENSE_DIVERGENCE_TRIGGERED"] = "1"
223
-
224
- @classmethod
225
- def get_injected_guard_snippet(cls) -> str:
226
- """Generates self-contained anti-debugging boiler for protected source files."""
227
- return '''
228
- # --- SIBER AKADEMI NATIVE ANTI-DEBUGGER RESISTANCE GATE ---
229
- def _verify_bare_metal_execution_environment():
230
- """Detects and terminates execution under x64dbg, IDA Pro, WinDbg, or tracers."""
231
- import os, sys
232
-
233
- # 1. Active Python tracer / debugger
234
- if sys.gettrace() is not None:
235
- os._exit(1)
236
-
237
- # 2. Windows Native Debugger Check
238
- if sys.platform == "win32":
239
- try:
240
- import ctypes
241
- k32 = ctypes.windll.kernel32
242
- if k32.IsDebuggerPresent():
243
- k32.ExitProcess(0xC0000409)
244
- is_remote = ctypes.c_bool(False)
245
- if k32.CheckRemoteDebuggerPresent(k32.GetCurrentProcess(), ctypes.byref(is_remote)) and is_remote.value:
246
- k32.ExitProcess(0xC0000409)
247
- # ThreadHideFromDebugger
248
- ctypes.windll.ntdll.NtSetInformationThread(k32.GetCurrentThread(), 0x11, 0, 0)
249
- except Exception:
250
- pass
251
-
252
- # 3. Linux TracerPid Check
253
- if os.path.exists("/proc/self/status"):
254
- try:
255
- with open("/proc/self/status", "r") as f:
256
- for line in f:
257
- if line.startswith("TracerPid:"):
258
- if int(line.split(":")[1].strip()) != 0:
259
- os._exit(1)
260
- except Exception:
261
- pass
262
-
263
- return True
264
-
265
- _BARE_METAL_VERIFIED = _verify_bare_metal_execution_environment()
266
- '''
267
-
268
- @classmethod
269
- def inject_anti_debugger_into_source(cls, source_code: str) -> str:
270
- """Injects standalone anti-debugging barrier into Python source code."""
271
- snippet = cls.get_injected_guard_snippet().strip()
272
- return f"{snippet}\n\n{source_code}"
@@ -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}"