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,84 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Anti-REA: Military-Grade AI Reverse Engineering & Anti-Debugger Defense Engine.
|
|
3
|
-
|
|
4
|
-
World-class, 24-tier anti-reverse-engineering defense matrix against autonomous
|
|
5
|
-
AI agents (morluto/rea, Ghidra MCP, pyinstxtractor, IDA LLM) and uncensored/jailbroken LLMs.
|
|
6
|
-
Includes native Ring-3 anti-debugging against x64dbg, IDA Pro, WinDbg, and Cheat Engine,
|
|
7
|
-
opt-in tamper alert webhook, in-flight string vault, and Electron asar shielding.
|
|
8
|
-
|
|
9
|
-
Developer: Toprak Ahmet Aydoğmuş (Siber Akademi)
|
|
10
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
11
|
-
License: MIT
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
__version__ = "5.0.0"
|
|
15
|
-
__author__ = "Toprak Ahmet Aydoğmuş"
|
|
16
|
-
__license__ = "MIT"
|
|
17
|
-
|
|
18
|
-
from .engine import AntiREAEngine
|
|
19
|
-
from .traps import AdversarialTrapGenerator
|
|
20
|
-
from .extractor_shield import ExtractorShield
|
|
21
|
-
from .flattener import ControlFlowFlattener
|
|
22
|
-
from .token_bomb import TokenBombGenerator
|
|
23
|
-
from .confusables import HomoglyphDesynchronizer
|
|
24
|
-
from .honeypot import HoneypotGenerator
|
|
25
|
-
from .mcp_poison import MCPProtocolPoisoner
|
|
26
|
-
from .sybil_network import SybilNetworkGenerator
|
|
27
|
-
from .timing_guard import TimingGuard
|
|
28
|
-
from .auditor import AIResistanceAuditor
|
|
29
|
-
from .vm_obfuscator import DynamicVMObfuscator
|
|
30
|
-
from .bytecode_trap import BytecodeTrap
|
|
31
|
-
from .jailbreak_decoy import CognitiveJailbreakDecoy
|
|
32
|
-
from .anti_agent_guard import AntiAgentGuard
|
|
33
|
-
from .algebraic_mutator import AlgebraicMutator
|
|
34
|
-
from .integrity_guard import MemoryIntegrityGuard
|
|
35
|
-
from .bpe_disrupter import BPETokenDisrupter
|
|
36
|
-
from .native_bridge import NativeBridge
|
|
37
|
-
from .anti_debugger import AntiDebugger
|
|
38
|
-
from .canary_beacon import CanaryBeacon
|
|
39
|
-
from .string_vault import StringVault
|
|
40
|
-
from .asar_shield import AsarShield
|
|
41
|
-
from .anti_vm import AntiVMGuard
|
|
42
|
-
from .rdtsc_guard import RDTSCTimingGuard
|
|
43
|
-
from .crypto_loader import CryptoBytecodeEnvelope
|
|
44
|
-
from .tier_catalog import (
|
|
45
|
-
ANTI_REA_DOMAINS,
|
|
46
|
-
ANTI_REA_TIERS,
|
|
47
|
-
TOTAL_TIER_COUNT,
|
|
48
|
-
get_tier_catalog,
|
|
49
|
-
evaluate_static_tier_coverage,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
__all__ = [
|
|
53
|
-
"AntiREAEngine",
|
|
54
|
-
"AdversarialTrapGenerator",
|
|
55
|
-
"ExtractorShield",
|
|
56
|
-
"ControlFlowFlattener",
|
|
57
|
-
"TokenBombGenerator",
|
|
58
|
-
"HomoglyphDesynchronizer",
|
|
59
|
-
"HoneypotGenerator",
|
|
60
|
-
"MCPProtocolPoisoner",
|
|
61
|
-
"SybilNetworkGenerator",
|
|
62
|
-
"TimingGuard",
|
|
63
|
-
"AIResistanceAuditor",
|
|
64
|
-
"DynamicVMObfuscator",
|
|
65
|
-
"BytecodeTrap",
|
|
66
|
-
"CognitiveJailbreakDecoy",
|
|
67
|
-
"AntiAgentGuard",
|
|
68
|
-
"AlgebraicMutator",
|
|
69
|
-
"MemoryIntegrityGuard",
|
|
70
|
-
"BPETokenDisrupter",
|
|
71
|
-
"NativeBridge",
|
|
72
|
-
"AntiDebugger",
|
|
73
|
-
"CanaryBeacon",
|
|
74
|
-
"StringVault",
|
|
75
|
-
"AsarShield",
|
|
76
|
-
"AntiVMGuard",
|
|
77
|
-
"RDTSCTimingGuard",
|
|
78
|
-
"CryptoBytecodeEnvelope",
|
|
79
|
-
"ANTI_REA_DOMAINS",
|
|
80
|
-
"ANTI_REA_TIERS",
|
|
81
|
-
"TOTAL_TIER_COUNT",
|
|
82
|
-
"get_tier_catalog",
|
|
83
|
-
"evaluate_static_tier_coverage",
|
|
84
|
-
]
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""Tier 76-90 (Domain D06): Type-Safe AST Algebraic Identity & MBA Mutator.
|
|
3
|
-
|
|
4
|
-
Transforms integer arithmetic expressions (+, -, *) into Mixed Boolean-Arithmetic
|
|
5
|
-
(MBA) equivalents while guaranteeing 100% runtime compatibility for strings, floats,
|
|
6
|
-
lists, booleans, and custom objects via strict runtime type guards:
|
|
7
|
-
int + int ==> (x ^ y) + ((x & y) << 1)
|
|
8
|
-
int - int ==> (x ^ y) - (((~x) & y) << 1)
|
|
9
|
-
int * 2 ==> (x << 1)
|
|
10
|
-
|
|
11
|
-
Developer: Toprak Ahmet Aydogmus (Siber Akademi)
|
|
12
|
-
Part of Siber Akademi T-Zero Security Suite.
|
|
13
|
-
License: MIT
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import ast
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_MBA_RUNTIME_HEADER = '''# --- SIBER AKADEMI TYPE-SAFE MBA ARITHMETIC ENGINE (D06: REA-076..090) ---
|
|
20
|
-
def _tzero_mba_add(_a, _b):
|
|
21
|
-
if type(_a) is int and type(_b) is int:
|
|
22
|
-
return (_a ^ _b) + ((_a & _b) << 1)
|
|
23
|
-
return _a + _b
|
|
24
|
-
|
|
25
|
-
def _tzero_mba_sub(_a, _b):
|
|
26
|
-
if type(_a) is int and type(_b) is int:
|
|
27
|
-
return (_a ^ _b) - (((~_a) & _b) << 1)
|
|
28
|
-
return _a - _b
|
|
29
|
-
'''
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class AlgebraicIdentityTransformer(ast.NodeTransformer):
|
|
33
|
-
"""AST transformer converting pure/typed arithmetic into MBA representations safely."""
|
|
34
|
-
|
|
35
|
-
@staticmethod
|
|
36
|
-
def _is_pure_int_const(node: ast.AST) -> bool:
|
|
37
|
-
return isinstance(node, ast.Constant) and type(node.value) is int
|
|
38
|
-
|
|
39
|
-
@staticmethod
|
|
40
|
-
def _is_eligible_operand(node: ast.AST) -> bool:
|
|
41
|
-
return isinstance(node, (ast.Name, ast.BinOp, ast.Call)) or (
|
|
42
|
-
isinstance(node, ast.Constant) and type(node.value) is int
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
def visit_BinOp(self, node: ast.BinOp) -> ast.AST:
|
|
46
|
-
self.generic_visit(node)
|
|
47
|
-
|
|
48
|
-
if isinstance(node.op, ast.Add):
|
|
49
|
-
if self._is_pure_int_const(node.left) and self._is_pure_int_const(node.right):
|
|
50
|
-
xor_part = ast.BinOp(left=node.left, op=ast.BitXor(), right=node.right)
|
|
51
|
-
and_part = ast.BinOp(left=node.left, op=ast.BitAnd(), right=node.right)
|
|
52
|
-
shifted = ast.BinOp(left=and_part, op=ast.LShift(), right=ast.Constant(value=1))
|
|
53
|
-
return ast.copy_location(ast.BinOp(left=xor_part, op=ast.Add(), right=shifted), node)
|
|
54
|
-
if self._is_eligible_operand(node.left) and self._is_eligible_operand(node.right):
|
|
55
|
-
return ast.copy_location(
|
|
56
|
-
ast.Call(
|
|
57
|
-
func=ast.Name(id="_tzero_mba_add", ctx=ast.Load()),
|
|
58
|
-
args=[node.left, node.right],
|
|
59
|
-
keywords=[],
|
|
60
|
-
),
|
|
61
|
-
node,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
elif isinstance(node.op, ast.Sub):
|
|
65
|
-
if self._is_pure_int_const(node.left) and self._is_pure_int_const(node.right):
|
|
66
|
-
xor_part = ast.BinOp(left=node.left, op=ast.BitXor(), right=node.right)
|
|
67
|
-
inv_left = ast.UnaryOp(op=ast.Invert(), operand=node.left)
|
|
68
|
-
and_part = ast.BinOp(left=inv_left, op=ast.BitAnd(), right=node.right)
|
|
69
|
-
shifted = ast.BinOp(left=and_part, op=ast.LShift(), right=ast.Constant(value=1))
|
|
70
|
-
return ast.copy_location(ast.BinOp(left=xor_part, op=ast.Sub(), right=shifted), node)
|
|
71
|
-
if self._is_eligible_operand(node.left) and self._is_eligible_operand(node.right):
|
|
72
|
-
return ast.copy_location(
|
|
73
|
-
ast.Call(
|
|
74
|
-
func=ast.Name(id="_tzero_mba_sub", ctx=ast.Load()),
|
|
75
|
-
args=[node.left, node.right],
|
|
76
|
-
keywords=[],
|
|
77
|
-
),
|
|
78
|
-
node,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
elif isinstance(node.op, ast.Mult):
|
|
82
|
-
# Shift optimization ONLY when one operand is 2/4/8 AND the other is provably an int literal
|
|
83
|
-
if self._is_pure_int_const(node.right) and node.right.value in (2, 4, 8) and self._is_pure_int_const(node.left):
|
|
84
|
-
shift = {2: 1, 4: 2, 8: 3}[node.right.value]
|
|
85
|
-
return ast.copy_location(ast.BinOp(left=node.left, op=ast.LShift(), right=ast.Constant(value=shift)), node)
|
|
86
|
-
if self._is_pure_int_const(node.left) and node.left.value in (2, 4, 8) and self._is_pure_int_const(node.right):
|
|
87
|
-
shift = {2: 1, 4: 2, 8: 3}[node.left.value]
|
|
88
|
-
return ast.copy_location(ast.BinOp(left=node.right, op=ast.LShift(), right=ast.Constant(value=shift)), node)
|
|
89
|
-
|
|
90
|
-
return node
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class AlgebraicMutator:
|
|
94
|
-
"""Public interface for applying type-safe Mixed Boolean-Arithmetic (MBA) AST mutations."""
|
|
95
|
-
|
|
96
|
-
@classmethod
|
|
97
|
-
def mutate_source_code(cls, source_code: str) -> str:
|
|
98
|
-
"""Applies type-safe algebraic identity mutation across expressions cleanly."""
|
|
99
|
-
try:
|
|
100
|
-
tree = ast.parse(source_code)
|
|
101
|
-
transformer = AlgebraicIdentityTransformer()
|
|
102
|
-
mutated_tree = transformer.visit(tree)
|
|
103
|
-
ast.fix_missing_locations(mutated_tree)
|
|
104
|
-
mutated = ast.unparse(mutated_tree)
|
|
105
|
-
return f"{_MBA_RUNTIME_HEADER}\n{mutated}"
|
|
106
|
-
except Exception:
|
|
107
|
-
return source_code
|
|
@@ -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}"
|