Skip to content

armgit / ARES

Public Imported from GitHub
0

ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.

fix(integrity): block golden_ticket fallback - invalid PAC-less ticket construction (MOD-035)

Mafifrizi9552b343b0d4
diff --git a/ares/core/errors.py b/ares/core/errors.py
index f6b05bc..37f2828 100644
--- a/ares/core/errors.py
+++ b/ares/core/errors.py
@@ -122,6 +122,15 @@ class ModuleValidationError(ModuleError):
self.field = field
+class ModuleExecutionError(ModuleError):
+ """
+ Module execution failed at runtime.
+ Raised when an underlying execution step or dependency is invalid or unavailable.
+ """
+
+ default_action = AresError.ABORT
+
+
class ModuleTimeoutError(ModuleError):
"""
Module exceeded wall-clock or CPU time limit.
diff --git a/ares/modules/credential/golden_ticket.py b/ares/modules/credential/golden_ticket.py
index dccbbf9..b0e33b6 100644
--- a/ares/modules/credential/golden_ticket.py
+++ b/ares/modules/credential/golden_ticket.py
@@ -15,6 +15,7 @@ import os
import tempfile
from typing import Any
+from ares.core.errors import ModuleExecutionError, ModuleValidationError
from ares.core.logger import get_logger, audit
from ares.core.campaign import Finding, Severity
from ares.modules.params import GoldenTicketParams
@@ -182,6 +183,16 @@ class GoldenTicketModule(BaseModule[GoldenTicketParams, ModuleResult]):
"Expected: S-1-5-21-<sub1>-<sub2>-<sub3>",
module_id=self.MODULE_ID, field="domain_sid",
)
+ try:
+ from impacket.krb5.ticket import Ticket # noqa: F401
+ from impacket.krb5 import constants # noqa: F401
+ from impacket.krb5.types import Principal # noqa: F401
+ except ImportError as e:
+ raise ModuleValidationError(
+ f"credential.golden_ticket requires impacket: {e}. "
+ "Install via: pip install impacket",
+ module_id=self.MODULE_ID,
+ ) from e
await super().validate(ctx)
async def execute(self, ctx: "Any") -> "ModuleResult":
@@ -404,31 +415,38 @@ class GoldenTicketModule(BaseModule[GoldenTicketParams, ModuleResult]):
_shutil.move(default_local, dst)
return True, dst, ""
return False, "", "Ticket file not created"
- except (ImportError, AttributeError, TypeError):
- pass
-
- # Fallback: write ccache using raw KRB5 ticket construction
- from ares.core.security import secure_mkstemp as _secure_mkstemp
- tmp_path, _fd = _secure_mkstemp(suffix=".ccache", prefix="ares_gt_")
- _os.close(_fd)
-
- # Build minimal valid TGT structure
- cipher_type = constants.EncryptionTypes.rc4_hmac.value # 23
- key = Key(cipher_type, nt_hash)
-
- # Create ccache with forged TGT credentials entry
- cc = CCache()
- cc.fromKRBCRED(
- cc.toKRBCRED(
- user_principal,
- Principal(f"krbtgt/{domain_upper}",
- type=constants.PrincipalNameType.NT_SRV_INST.value),
- domain_upper, key, ticket_session_key=None,
- )
- )
- cc.saveFile(tmp_path)
- return True, tmp_path, ""
-
+ except (ImportError, AttributeError, TypeError) as ticketer_err:
+ # MOD-035: Fallback path blocked.
+ # The previous fallback used CCache.fromKRBCRED() to construct a ticket
+ # without a valid PAC and KDC signature. Such tickets fail AD Kerberos validation
+ # and produce false positives. Hard dependency on impacket TICKETER is required.
+ #
+ # --- DISABLED FALLBACK CODE (DO NOT RE-ENABLE) ---
+ # from ares.core.security import secure_mkstemp as _secure_mkstemp
+ # tmp_path, _fd = _secure_mkstemp(suffix=".ccache", prefix="ares_gt_")
+ # _os.close(_fd)
+ # cipher_type = constants.EncryptionTypes.rc4_hmac.value # 23
+ # key = Key(cipher_type, nt_hash)
+ # cc = CCache()
+ # cc.fromKRBCRED(
+ # cc.toKRBCRED(
+ # user_principal,
+ # Principal(f"krbtgt/{domain_upper}",
+ # type=constants.PrincipalNameType.NT_SRV_INST.value),
+ # domain_upper, key, ticket_session_key=None,
+ # )
+ # )
+ # cc.saveFile(tmp_path)
+ # return True, tmp_path, ""
+ # ------------------------------------------------
+ raise ModuleExecutionError(
+ "impacket ticketer unavailable — fallback ticket construction "
+ "disabled: would produce invalid ticket without PAC/KDC signature. "
+ "Ensure impacket is properly installed. (MOD-035)"
+ ) from ticketer_err
+
+ except ModuleExecutionError:
+ raise
except Exception as exc:
return False, "", str(exc)[:300]
diff --git a/ares/modules/sdk.py b/ares/modules/sdk.py
index fbef4d9..f3fcac1 100644
--- a/ares/modules/sdk.py
+++ b/ares/modules/sdk.py
@@ -73,6 +73,7 @@ from ares.core.context import ExecutionContext
from ares.core.errors import (
AresError,
ModuleError,
+ ModuleExecutionError,
ModuleValidationError,
ModuleTimeoutError,
NetworkError,
@@ -353,6 +354,7 @@ __all__ = [
# Errors
"AresError",
"ModuleError",
+ "ModuleExecutionError",
"ModuleValidationError",
"ModuleTimeoutError",
"NetworkError",
diff --git a/ares/sdk/__init__.py b/ares/sdk/__init__.py
index 343cfac..488350f 100644
--- a/ares/sdk/__init__.py
+++ b/ares/sdk/__init__.py
@@ -39,6 +39,7 @@ from ares.modules.sdk import (
InsufficientPrivilege,
InvalidContext,
ModuleError,
+ ModuleExecutionError,
ModuleResult,
ModuleTestHelper,
ModuleTimeoutError,
@@ -159,6 +160,7 @@ __all__ = [
# Errors
"AresError",
"ModuleError",
+ "ModuleExecutionError",
"ModuleValidationError",
"ModuleTimeoutError",
"NetworkError",
diff --git a/tests/unit/modules/test_golden_ticket.py b/tests/unit/modules/test_golden_ticket.py
new file mode 100644
index 0000000..d869fa2
--- /dev/null
+++ b/tests/unit/modules/test_golden_ticket.py
@@ -0,0 +1,152 @@
+from __future__ import annotations
+
+import asyncio
+import types
+from unittest.mock import MagicMock, patch
+import pytest
+
+from ares.core.config import AresSettings
+from ares.core.campaign import Campaign, NoiseProfile, ScopeEntry
+from ares.core.context import ExecutionContext
+from ares.core.errors import ModuleExecutionError, ModuleValidationError
+from ares.core.noise import NoiseController
+from ares.modules.credential.golden_ticket import GoldenTicketModule
+
+
+def make_module(cls):
+ settings = AresSettings()
+ campaign = Campaign(
+ name="GT-Test",
+ client="TestClient",
+ operator="tester",
+ scope=[ScopeEntry(cidr="10.0.0.0/8")],
+ domain="corp.local",
+ targets=["corp.local"],
+ noise_profile=NoiseProfile.NORMAL,
+ )
+ noise = NoiseController(campaign)
+ return cls(settings=settings, campaign=campaign, noise=noise)
+
+
+def _run(coro):
+ return asyncio.run(coro)
+
+
+def _setup_impacket_mock_modules(ticketer_available: bool = True, ticketer_cls: Any = None):
+ mods: dict[str, Any] = {}
+ names = [
+ "impacket",
+ "impacket.krb5",
+ "impacket.krb5.asn1",
+ "impacket.krb5.ccache",
+ "impacket.krb5.crypto",
+ "impacket.krb5.constants",
+ "impacket.krb5.types",
+ "impacket.krb5.kerberosv5",
+ "impacket.krb5.pac",
+ "impacket.krb5.ticket",
+ "impacket.examples",
+ ]
+ for n in names:
+ m = types.ModuleType(n)
+ m.__dict__.update({
+ "AS_REP": MagicMock(),
+ "EncTicketPart": MagicMock(),
+ "TGS_REP": MagicMock(),
+ "CCache": MagicMock(),
+ "Key": MagicMock(),
+ "_enctype_table": MagicMock(),
+ "EncryptionTypes": MagicMock(),
+ "PrincipalNameType": MagicMock(),
+ "ApplicationTagNumbers": MagicMock(),
+ "Principal": MagicMock(),
+ "KerberosTime": MagicMock(),
+ "constants": MagicMock(),
+ "getKerberosTGT": MagicMock(),
+ "PACTYPE": MagicMock(),
+ "PAC_INFO_BUFFER": MagicMock(),
+ "PAC_CREDENTIAL_DATA": MagicMock(),
+ "Ticket": MagicMock(),
+ })
+ mods[n] = m
+
+ if ticketer_available:
+ tick_mod = types.ModuleType("impacket.examples.ticketer")
+ tick_mod.TICKETER = ticketer_cls or MagicMock()
+ mods["impacket.examples.ticketer"] = tick_mod
+ else:
+ mods["impacket.examples.ticketer"] = None
+ return mods
+
+
+def test_golden_ticket_validate_fails_without_impacket():
+ mod = make_module(GoldenTicketModule)
+ ctx = ExecutionContext(
+ target="10.0.0.5",
+ domain="corp.local",
+ params={
+ "target": "10.0.0.5",
+ "domain": "corp.local",
+ "username": "Administrator",
+ "krbtgt_hash": "0123456789abcdef0123456789abcdef",
+ "domain_sid": "S-1-5-21-1111111111-2222222222-3333333333",
+ },
+ )
+ with patch.dict("sys.modules", {"impacket.krb5.ticket": None}):
+ with pytest.raises(ModuleValidationError) as excinfo:
+ _run(mod.validate(ctx))
+ assert "requires impacket" in str(excinfo.value)
+
+
+def test_golden_ticket_fallback_raises_module_execution_error():
+ mod = make_module(GoldenTicketModule)
+ mock_mods = _setup_impacket_mock_modules(ticketer_available=False)
+
+ with patch.dict("sys.modules", mock_mods):
+ with pytest.raises(ModuleExecutionError) as excinfo:
+ _run(
+ mod.run(
+ domain="corp.local",
+ username="Administrator",
+ krbtgt_hash="0123456789abcdef0123456789abcdef",
+ domain_sid="S-1-5-21-1111111111-2222222222-3333333333",
+ )
+ )
+ assert (
+ "impacket ticketer unavailable — fallback ticket construction disabled"
+ in str(excinfo.value)
+ )
+ assert "MOD-035" in str(excinfo.value)
+
+
+def test_golden_ticket_primary_path_success():
+ mod = make_module(GoldenTicketModule)
+
+ mock_ticketer_cls = MagicMock()
+ mock_instance = MagicMock()
+ mock_ticketer_cls.return_value = mock_instance
+
+ def side_effect_run():
+ opts = mock_ticketer_cls.call_args[1]["options"]
+ with open(opts.filename, "wb") as f:
+ f.write(b"ccache_content_here")
+
+ mock_instance.run = side_effect_run
+
+ mock_mods = _setup_impacket_mock_modules(
+ ticketer_available=True, ticketer_cls=mock_ticketer_cls
+ )
+
+ with patch.dict("sys.modules", mock_mods):
+ findings, raw = _run(
+ mod.run(
+ domain="corp.local",
+ username="Administrator",
+ krbtgt_hash="0123456789abcdef0123456789abcdef",
+ domain_sid="S-1-5-21-1111111111-2222222222-3333333333",
+ )
+ )
+
+ assert raw["success"] is True
+ assert len(findings) == 1
+ assert "Golden Ticket Forged" in findings[0].title
diff --git a/tests/unit/test_module_coverage.py b/tests/unit/test_module_coverage.py
index 69018c7..ab9b487 100644
--- a/tests/unit/test_module_coverage.py
+++ b/tests/unit/test_module_coverage.py
@@ -586,22 +586,33 @@ class TestDashboardModuleSchemaContracts:
assert captured["listener"] == "10.0.0.10"
def test_golden_ticket_form_fields_satisfy_shared_credential_requires(self):
+ from unittest.mock import MagicMock, patch
from ares.modules.credential.golden_ticket import GoldenTicketModule
mod, _ = _make_module(GoldenTicketModule)
- _run(
- mod.validate(
- _ctx(
- params={
- "target": "10.0.0.5",
- "domain": "corp.local",
- "username": "Administrator",
- "krbtgt_hash": "0123456789abcdef0123456789abcdef",
- "domain_sid": "S-1-5-21-1111111111-2222222222-3333333333",
- }
+ with patch.dict(
+ "sys.modules",
+ {
+ "impacket": MagicMock(),
+ "impacket.krb5": MagicMock(),
+ "impacket.krb5.ticket": MagicMock(),
+ "impacket.krb5.constants": MagicMock(),
+ "impacket.krb5.types": MagicMock(),
+ },
+ ):
+ _run(
+ mod.validate(
+ _ctx(
+ params={
+ "target": "10.0.0.5",
+ "domain": "corp.local",
+ "username": "Administrator",
+ "krbtgt_hash": "0123456789abcdef0123456789abcdef",
+ "domain_sid": "S-1-5-21-1111111111-2222222222-3333333333",
+ }
+ )
)
)
- )
@pytest.mark.parametrize(
"module_path,class_name",