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: classify kerberoast tgs timeout with candidates

Mafifrizi6a82edb3d58a
diff --git a/ares/core/engine.py b/ares/core/engine.py
index 82e7ba2..ff9c1c4 100644
--- a/ares/core/engine.py
+++ b/ares/core/engine.py
@@ -79,13 +79,18 @@ def normalize_module_outcome(
"operator_error",
"Kerberos clock skew too great; sync the operator host and domain controller time, then rerun.",
)
+ error_text = str(error or "").strip()
+ if (
+ "ldap/spn enumeration succeeded and found" in error_text.lower()
+ and "before a hash was confirmed" in error_text.lower()
+ ):
+ return "network_error", error_text
if raw_outcome in MODULE_OUTCOMES:
if raw_message:
return raw_outcome, raw_message
return raw_outcome, raw_outcome.replace("_", " ").capitalize() + "."
status_value = status.value if isinstance(status, ModuleStatus) else str(status)
- error_text = str(error or "").strip()
lowered = error_text.lower()
if status_value == ModuleStatus.TIMEOUT.value or any(
marker in lowered
@@ -193,6 +198,10 @@ class EngineModuleResult(BaseModel):
self.operator_next_steps = [
"Synchronize the operator host and domain controller clocks, then rerun the module."
]
+ elif self.outcome == "network_error" and "before a hash was confirmed" in self.outcome_message.lower():
+ self.operator_next_steps = [
+ "Verify DC/KDC reachability on port 88, clock synchronization, and Kerberos service health, then rerun."
+ ]
@property
def confirmed_findings(self) -> list[Finding]:
diff --git a/ares/modules/ad/kerberoast.py b/ares/modules/ad/kerberoast.py
index a5c904b..1ec2898 100644
--- a/ares/modules/ad/kerberoast.py
+++ b/ares/modules/ad/kerberoast.py
@@ -21,6 +21,17 @@ from ares.modules.ad.dependencies import (
)
+KERBEROS_TGS_TIMEOUT_SECONDS = 30
+
+
+def format_kerberoast_tgs_timeout(candidate_count: int) -> str:
+ return (
+ f"LDAP/SPN enumeration succeeded and found {candidate_count} "
+ "Kerberoastable candidate account(s), but the Kerberos TGS request "
+ "timed out before a hash was confirmed."
+ )
+
+
def _format_krb5tgs_hash(tgs: bytes, cipher: "Any", spn: str, domain: str) -> str:
"""
Convert raw impacket TGS response to $krb5tgs$ format for hashcat mode 13100/19700.
@@ -168,6 +179,7 @@ class KerberoastModule(BaseModule):
return [], {"skipped": True, "reason": "stealth_profile_too_noisy"}
await self.before_request(dc, "kerberos_tgs")
logger.info("kerberoast_start", dc=dc, domain=domain, target=target_user)
+ self._last_candidate_count = 0
self._last_spn_count = 0
self._last_tgs_failures = 0
try:
@@ -193,7 +205,7 @@ class KerberoastModule(BaseModule):
}
if not hashes:
category, message = classify_kerberoast_outcome(
- self._last_spn_count,
+ self._last_candidate_count,
len(hashes),
self._last_tgs_failures,
)
@@ -260,6 +272,7 @@ class KerberoastModule(BaseModule):
spn_list: list[str] = []
if target_user:
spn_list = [target_user]
+ self._last_candidate_count = 1
else:
# Get SPNs from enum_spn output if available, else query LDAP directly
try:
@@ -270,7 +283,9 @@ class KerberoastModule(BaseModule):
noise=self.noise,
).run(dc=dc, username=username, password=password, domain=domain)
_, spn_raw = spn_data
- for acct in spn_raw.get("spn_list", spn_raw.get("spns", [])):
+ candidate_accounts = spn_raw.get("spn_list", spn_raw.get("spns", []))
+ self._last_candidate_count = len(candidate_accounts)
+ for acct in candidate_accounts:
spn_values = acct.get("spn_list") or acct.get("spns") or []
spn_list.extend(spn_values)
except Exception as exc:
@@ -301,8 +316,9 @@ class KerberoastModule(BaseModule):
for i, spn in enumerate(spn_list):
try:
- tgs, tgs_cipher, _, tgs_sk = await loop.run_in_executor(
- None, _get_tgs, spn
+ tgs, tgs_cipher, _, tgs_sk = await asyncio.wait_for(
+ loop.run_in_executor(None, _get_tgs, spn),
+ timeout=KERBEROS_TGS_TIMEOUT_SECONDS,
)
# Format as $krb5tgs$ hash for hashcat
hash_str = _format_krb5tgs_hash(tgs, tgs_cipher, spn, domain)
@@ -313,6 +329,12 @@ class KerberoastModule(BaseModule):
"spn": spn,
"hash": hash_str[:60] + "...",
})
+ except asyncio.TimeoutError as exc:
+ raise ModuleValidationError(
+ format_kerberoast_tgs_timeout(self._last_candidate_count),
+ module_id=self.MODULE_ID,
+ field="kerberos_tgs",
+ ) from exc
except Exception as exc:
self._last_tgs_failures += 1
logger.debug("kerberoast_tgs_failed", spn=spn, error=str(exc)[:80])
diff --git a/tests/unit/test_ad_bind_behavior.py b/tests/unit/test_ad_bind_behavior.py
index 7c9a533..69d2bd4 100644
--- a/tests/unit/test_ad_bind_behavior.py
+++ b/tests/unit/test_ad_bind_behavior.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import sys
+import time
import types
import pytest
@@ -83,13 +84,15 @@ def _install_fake_ldap3(monkeypatch, *, bind_outcomes=None):
return FakeConnection
-def _install_fake_kerberos(monkeypatch, *, tgt_error=None):
+def _install_fake_kerberos(monkeypatch, *, tgt_error=None, tgs_delay=0):
def get_kerberos_tgt(**kwargs):
if tgt_error is not None:
raise tgt_error
return b"tgt", "cipher", b"old_session", b"session"
def get_kerberos_tgs(**kwargs):
+ if tgs_delay:
+ time.sleep(tgs_delay)
return b"tgs", "tgs_cipher", b"old", b"tgs_session"
class _PrincipalNameTypeValue:
@@ -333,3 +336,38 @@ async def test_kerberoast_spn_lookup_consumes_enum_spn_output_key(monkeypatch):
assert hashes == ["$krb5tgs$23$fake"]
assert accounts[0]["spn"] == "HTTP/web.lab.local"
+
+
+async def test_kerberoast_tgs_timeout_after_spn_enumeration_is_actionable(monkeypatch):
+ import ares.modules.ad.kerberoast as kerberoast_mod
+ from ares.modules.ad.enum_spn import ADEnumSPNModule
+ from ares.modules.ad.kerberoast import KerberoastModule
+
+ _install_fake_kerberos(monkeypatch, tgs_delay=0.05)
+ monkeypatch.setattr(kerberoast_mod, "KERBEROS_TGS_TIMEOUT_SECONDS", 0.01)
+
+ async def fake_enum_spn_run(*args, **kwargs):
+ return [], {
+ "spn_list": [
+ {"name": "svc-web", "spn_list": ["HTTP/web.lab.local"]},
+ {"name": "svc-sql", "spn_list": ["MSSQLSvc/sql.lab.local"]},
+ ]
+ }
+
+ monkeypatch.setattr(ADEnumSPNModule, "run", fake_enum_spn_run)
+ module, _ = _make_module(KerberoastModule)
+
+ with pytest.raises(ModuleValidationError) as exc_info:
+ await module._request_tickets(
+ "10.0.0.5",
+ "Password1!",
+ "lab.local",
+ None,
+ )
+
+ assert exc_info.value.action == "abort"
+ assert "LDAP/SPN enumeration succeeded and found 2 Kerberoastable candidate account(s)" in str(exc_info.value)
+ assert "Kerberos TGS request timed out before a hash was confirmed" in str(exc_info.value)
+ assert "Password1!" not in str(exc_info.value)
diff --git a/tests/unit/test_engine.py b/tests/unit/test_engine.py
index 612933b..bd44d65 100644
--- a/tests/unit/test_engine.py
+++ b/tests/unit/test_engine.py
@@ -145,6 +145,51 @@ class TestAsyncEngine:
assert result.status == ModuleStatus.FAILED
assert "blocked in STEALTH profile" in (result.error or "")
+ @pytest.mark.asyncio
+ async def test_kerberoast_classified_tgs_timeout_does_not_retry(
+ self, settings: AresSettings, campaign: Campaign
+ ) -> None:
+ from ares.core.errors import ModuleValidationError
+ from ares.modules.ad.kerberoast import (
+ KerberoastModule,
+ format_kerberoast_tgs_timeout,
+ )
+
+ engine = AresEngine(settings=settings)
+ engine.load_modules()
+ calls = 0
+
+ async def classified_timeout(self_unused: Any, ctx: Any) -> Any:
+ nonlocal calls
+ calls += 1
+ raise ModuleValidationError(
+ format_kerberoast_tgs_timeout(2),
+ module_id="ad.kerberoast",
+ field="kerberos_tgs",
+ )
+
+ params = {
+ "dc": "10.0.0.5",
+ "domain": "corp.local",
+ "username": "svc-roast",
+ "password": "Passw0rd!",
+ "target_user": "sqlsvc",
+ }
+ with patch.object(KerberoastModule, "execute", classified_timeout), \
+ patch("ares.core.engine.asyncio.sleep", new=AsyncMock()) as retry_sleep:
+ result = await engine.run_module(
+ "ad.kerberoast",
+ campaign,
+ params,
+ actor_role="team_lead",
+ )
+
+ assert calls == 1
+ assert retry_sleep.await_count == 0
+ assert result.outcome == "network_error"
+ assert "found 2 Kerberoastable candidate account(s)" in result.outcome_message
+ assert "Kerberos TGS request timed out" in result.outcome_message
+
@pytest.mark.asyncio
async def test_run_module_timeout(
self, settings: AresSettings, campaign: Campaign
diff --git a/tests/unit/test_module_contracts.py b/tests/unit/test_module_contracts.py
index 934cbce..d03ba4f 100644
--- a/tests/unit/test_module_contracts.py
+++ b/tests/unit/test_module_contracts.py
@@ -230,9 +230,13 @@ def test_engine_done_without_findings_has_explicit_outcome():
def test_ad_empty_results_have_operator_facing_classification():
+ from ares.core.engine import EngineModuleResult, ModuleStatus
from ares.modules.ad.asreproast import classify_asrep_outcome
from ares.modules.ad.enum_spn import classify_enum_spn_outcome
- from ares.modules.ad.kerberoast import classify_kerberoast_outcome
+ from ares.modules.ad.kerberoast import (
+ classify_kerberoast_outcome,
+ format_kerberoast_tgs_timeout,
+ )
assert classify_asrep_outcome("authenticated", 1, 0)[0] == "completed_no_findings"
assert "candidate" in classify_asrep_outcome("authenticated", 1, 0)[1]
@@ -240,3 +244,16 @@ def test_ad_empty_results_have_operator_facing_classification():
assert classify_kerberoast_outcome(1, 0, 1)[0] == "network_error"
assert classify_kerberoast_outcome(1, 0, 0)[0] == "completed_no_findings"
assert classify_enum_spn_outcome(0)[0] == "completed_no_findings"
+
+ timeout_message = format_kerberoast_tgs_timeout(2)
+ timeout = EngineModuleResult(
+ module_id="ad.kerberoast",
+ status=ModuleStatus.FAILED,
+ error=timeout_message,
+ )
+ assert timeout.outcome == "network_error"
+ assert timeout.outcome != "module_error"
+ assert timeout.outcome_message == timeout_message
+ assert timeout.operator_next_steps == [
+ "Verify DC/KDC reachability on port 88, clock synchronization, and Kerberos service health, then rerun."
+ ]