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: make Windows validator logs and LDAPS status safe

Mafifrizi1454a9803c92
diff --git a/ares/core/validator.py b/ares/core/validator.py
index 98a885f..6cc019b 100644
--- a/ares/core/validator.py
+++ b/ares/core/validator.py
@@ -108,7 +108,7 @@ class FindingValidator:
finding.mark_false_positive(f"Confidence too low: {final_confidence:.2f}")
logger.info(
- f"[validator] Finding '{finding.title}' → "
+ f"[validator] Finding '{finding.title}' -> "
f"confidence={result.confidence:.2f} passed={result.passed}"
)
return result
diff --git a/ares/modules/ad/enum_computers.py b/ares/modules/ad/enum_computers.py
index 88b1740..e230860 100644
--- a/ares/modules/ad/enum_computers.py
+++ b/ares/modules/ad/enum_computers.py
@@ -196,7 +196,12 @@ class ADEnumComputersModule(BaseModule):
field="use_ldaps",
target=dc,
) from exc
- raise NetworkError(message, module_id=self.MODULE_ID, target=dc) from exc
+ network_message = message.replace(
+ "ad.enum_computers ", "ad.enum_computers network ", 1
+ )
+ raise NetworkError(
+ network_message, module_id=self.MODULE_ID, target=dc
+ ) from exc
base = ",".join(f"DC={p}" for p in domain.upper().split("."))
try:
conn.search(base, "(objectClass=computer)", search_scope=SUBTREE,
diff --git a/tests/unit/core/test_core.py b/tests/unit/core/test_core.py
index f1ba3f3..f4fb2a3 100644
--- a/tests/unit/core/test_core.py
+++ b/tests/unit/core/test_core.py
@@ -144,6 +144,40 @@ class TestSecurity:
# ── Validator tests ───────────────────────────────────────────────────────────
class TestValidator:
+ @pytest.mark.asyncio
+ async def test_validator_confidence_log_is_ascii_safe(self, monkeypatch):
+ import ares.core.validator as validator_module
+ from unittest.mock import Mock
+
+ logger_info = Mock()
+ monkeypatch.setattr(validator_module.logger, "info", logger_info)
+
+ async def always_pass(finding: Finding, context: dict) -> tuple[bool, float, str]:
+ return True, 0.95, "confirmed"
+
+ validator = FindingValidator()
+ validator.register("test.ascii_log", [
+ ValidationCheck(
+ stage=ValidationStage.EXISTENCE,
+ name="ascii_check",
+ check=always_pass,
+ )
+ ])
+ finding = Finding(
+ title="ASREPRoast Hashes Captured (1)",
+ description="Captured hash evidence",
+ severity=Severity.HIGH,
+ module_id="test.ascii_log",
+ )
+
+ result = await validator.validate(finding, {})
+
+ logged_message = logger_info.call_args.args[0]
+ assert logged_message.isascii()
+ assert " -> " in logged_message
+ assert "confidence=0.95" in logged_message
+ assert result.confidence == 0.95
+
@pytest.mark.asyncio
async def test_no_checks_defaults_to_medium_confidence(self):
v = FindingValidator()
diff --git a/tests/unit/test_ad_bind_behavior.py b/tests/unit/test_ad_bind_behavior.py
index 9aee4a0..1b37a69 100644
--- a/tests/unit/test_ad_bind_behavior.py
+++ b/tests/unit/test_ad_bind_behavior.py
@@ -608,7 +608,7 @@ async def test_asreproast_candidate_hash_is_confirmed_with_high_confidence(monke
assert validation.confidence >= 0.90
-def _install_fake_ldap3_ssl_close(monkeypatch):
+def _install_fake_ldap3_ssl_close(monkeypatch, error_message=None):
class FakeTls:
def __init__(self, *args, **kwargs):
self.args = args
@@ -622,8 +622,11 @@ def _install_fake_ldap3_ssl_close(monkeypatch):
class FakeConnection:
def __init__(self, *args, **kwargs):
raise OSError(
- "socket ssl wrapping error: [WinError 10054] "
- "An existing connection was forcibly closed by the remote host"
+ error_message
+ or (
+ "socket ssl wrapping error: [WinError 10054] "
+ "An existing connection was forcibly closed by the remote host"
+ )
)
ldap3_mod = types.ModuleType("ldap3")
@@ -710,6 +713,50 @@ async def test_enum_computers_config_error_does_not_retry(monkeypatch, minimal_c
assert "389" in result.outcome_message and "636" in result.outcome_message
+async def test_enum_computers_ldaps_network_failure_is_not_module_error(
+ monkeypatch, minimal_campaign
+):
+ from unittest.mock import AsyncMock, patch
+
+ from ares.core.config import AresSettings
+ from ares.core.engine import AresEngine
+ from ares.core.noise import JitterEngine
+
+ engine = AresEngine(settings=AresSettings())
+ engine.load_modules()
+ _install_fake_ldap3_ssl_close(
+ monkeypatch,
+ error_message=(
+ "socket connection error while opening: [WinError 10060] "
+ "A connection attempt failed because the connected party did not "
+ "properly respond"
+ ),
+ )
+
+ async def no_noise_sleep(*args, **kwargs):
+ return None
+
+ monkeypatch.setattr(JitterEngine, "sleep", no_noise_sleep)
+ params = {
+ "dc": "10.0.0.5",
+ "domain": "lab.local",
+ "username": "[email protected]",
+ "password": "Password1!",
+ "use_ldaps": True,
+ }
+ with patch("ares.core.engine.asyncio.sleep", new=AsyncMock()):
+ result = await engine.run_module("ad.enum_computers", minimal_campaign, params)
+
+ assert result.outcome == "network_error"
+ assert result.findings == []
+ assert "module_error" not in result.outcome_message
+ assert "use_ldaps=true" in result.outcome_message
+ assert "389" in result.outcome_message and "636" in result.outcome_message
+ assert "certificate/LDAPS configuration" in result.outcome_message
+ assert "Password1!" not in result.outcome_message
+
+
@pytest.mark.asyncio
async def test_asreproast_candidate_kerberos_failure_is_candidate_aware(monkeypatch):
import ares.modules.ad.asreproast as asreproast_mod