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(robustness): registry_enum and scheduled_tasks_enum pre-flight validation (MOD-069)

Mafifrizi6e10f8fa7dcb
diff --git a/ares/modules/windows/registry_enum.py b/ares/modules/windows/registry_enum.py
index 9863269..324a599 100644
--- a/ares/modules/windows/registry_enum.py
+++ b/ares/modules/windows/registry_enum.py
@@ -238,6 +238,27 @@ class RegistryEnumModule(BaseModule):
f"{self.MODULE_ID} requires 'target' - IP or hostname.",
module_id=self.MODULE_ID, field="target",
)
+ username = (
+ ctx.params.get("username", "")
+ if isinstance(ctx.params, dict)
+ else getattr(ctx.params, "username", "")
+ )
+ if not username and hasattr(ctx, "best_credential"):
+ cred = ctx.best_credential()
+ if cred and cred.username:
+ username = cred.username
+ if isinstance(ctx.params, dict):
+ ctx.params["username"] = username
+ elif hasattr(ctx.params, "username"):
+ try:
+ ctx.params.username = username
+ except Exception:
+ pass
+ if not username:
+ raise ModuleValidationError(
+ f"{self.MODULE_ID} requires 'username' - credential username for authentication.",
+ module_id=self.MODULE_ID, field="username",
+ )
await super().validate(ctx)
async def execute(self, ctx: "Any") -> "ModuleResult":
@@ -360,6 +381,11 @@ class RegistryEnumModule(BaseModule):
dry_run = kwargs.get("dry_run", False)
if not target or not username:
+ logger.warning(
+ "registry_enum_missing_params",
+ target=target,
+ has_username=bool(username),
+ )
return [], {"error": "target and username required"}
if dry_run:
return [], {"dry_run": True}
@@ -374,6 +400,7 @@ class RegistryEnumModule(BaseModule):
hBaseRegCloseKey, DCERPCException,
)
except ImportError:
+ logger.warning("registry_enum_impacket_missing", target=target)
return [], {"error": "impacket not installed - pip install ares-redteam[ad]"}
logger.info("registry_enum_start", target=target, username=username)
@@ -516,6 +543,7 @@ class RegistryEnumModule(BaseModule):
errs.append(f"PuTTY sessions: {e!s:.80}")
except Exception as e:
+ logger.warning("registry_enum_connection_error", target=target, error=str(e))
errs.append(str(e)[:200])
finally:
if dce:
diff --git a/ares/modules/windows/scheduled_tasks_enum.py b/ares/modules/windows/scheduled_tasks_enum.py
index 20c1d9e..2c45ad2 100644
--- a/ares/modules/windows/scheduled_tasks_enum.py
+++ b/ares/modules/windows/scheduled_tasks_enum.py
@@ -198,6 +198,27 @@ class ScheduledTasksEnumModule(BaseModule):
f"{self.MODULE_ID} requires 'target' - IP or hostname.",
module_id=self.MODULE_ID, field="target",
)
+ username = (
+ ctx.params.get("username", "")
+ if isinstance(ctx.params, dict)
+ else getattr(ctx.params, "username", "")
+ )
+ if not username and hasattr(ctx, "best_credential"):
+ cred = ctx.best_credential()
+ if cred and cred.username:
+ username = cred.username
+ if isinstance(ctx.params, dict):
+ ctx.params["username"] = username
+ elif hasattr(ctx.params, "username"):
+ try:
+ ctx.params.username = username
+ except Exception:
+ pass
+ if not username:
+ raise ModuleValidationError(
+ f"{self.MODULE_ID} requires 'username' - credential username for authentication.",
+ module_id=self.MODULE_ID, field="username",
+ )
await super().validate(ctx)
async def execute(self, ctx: "Any") -> "ModuleResult":
@@ -313,6 +334,11 @@ class ScheduledTasksEnumModule(BaseModule):
dry_run = kwargs.get("dry_run", False)
if not target or not username:
+ logger.warning(
+ "scheduled_tasks_enum_missing_params",
+ target=target,
+ has_username=bool(username),
+ )
return [], {"error": "target and username required"}
if dry_run:
return [], {"dry_run": True}
@@ -324,6 +350,7 @@ class ScheduledTasksEnumModule(BaseModule):
TASK_ENUM_HIDDEN,
)
except ImportError:
+ logger.warning("scheduled_tasks_enum_impacket_missing", target=target)
return [], {"error": "impacket not installed - pip install ares-redteam[ad]"}
logger.info("scheduled_tasks_enum_start", target=target, username=username)
@@ -399,6 +426,7 @@ class ScheduledTasksEnumModule(BaseModule):
dce.disconnect()
except Exception as e:
+ logger.warning("scheduled_tasks_enum_connection_error", target=target, error=str(e))
errors.append(str(e)[:200])
return {"tasks": tasks, "errors": errors}
diff --git a/tests/unit/modules/test_windows_enum_preflight_mod069.py b/tests/unit/modules/test_windows_enum_preflight_mod069.py
new file mode 100644
index 0000000..4e67a71
--- /dev/null
+++ b/tests/unit/modules/test_windows_enum_preflight_mod069.py
@@ -0,0 +1,102 @@
+"""
+Tests for MOD-069: Pre-flight parameter validation in validate()
+and non-silent logging in run() for windows.registry_enum and windows.scheduled_tasks_enum.
+"""
+
+from unittest.mock import MagicMock, patch
+import pytest
+
+from ares.core.campaign import Campaign, NoiseProfile, ScopeEntry
+from ares.core.config import AresSettings
+from ares.core.context import ExecutionContext
+from ares.core.errors import ModuleValidationError
+from ares.core.noise import NoiseController
+from ares.modules.windows.registry_enum import RegistryEnumModule
+from ares.modules.windows.scheduled_tasks_enum import ScheduledTasksEnumModule
+
+
+def _make_context_deps():
+ settings = AresSettings(
+ ares_secret_key="test-secret-key-32chars-minimum!!",
+ ares_encryption_key="test-encryption-key-32chars-min!!",
+ )
+ campaign = Campaign(
+ name="Windows-Enum-Preflight-Test",
+ client="Unit-Testing",
+ scope=[ScopeEntry(cidr="192.168.0.0/16")],
+ noise_profile=NoiseProfile.NORMAL,
+ )
+ noise = NoiseController(campaign)
+ return settings, campaign, noise
+
+
+async def test_registry_enum_validate_fails_without_username():
+ """Verify registry_enum fails fast in validate() when username is missing."""
+ settings, campaign, noise = _make_context_deps()
+ mod = RegistryEnumModule(settings=settings, campaign=campaign, noise=noise)
+ ctx = ExecutionContext(target="192.168.1.50", params={"target": "192.168.1.50"})
+
+ with pytest.raises(ModuleValidationError) as exc_info:
+ await mod.validate(ctx)
+
+ assert "username" in str(exc_info.value).lower()
+ assert exc_info.value.field == "username"
+
+
+async def test_registry_enum_validate_succeeds_with_credentials():
+ """Verify registry_enum validate() passes when username and target are provided."""
+ settings, campaign, noise = _make_context_deps()
+ mod = RegistryEnumModule(settings=settings, campaign=campaign, noise=noise)
+ ctx = ExecutionContext(
+ target="192.168.1.50",
+ params={"target": "192.168.1.50", "username": "Administrator"},
+ )
+ await mod.validate(ctx)
+
+
+async def test_scheduled_tasks_enum_validate_fails_without_username():
+ """Verify scheduled_tasks_enum fails fast in validate() when username is missing."""
+ settings, campaign, noise = _make_context_deps()
+ mod = ScheduledTasksEnumModule(settings=settings, campaign=campaign, noise=noise)
+ ctx = ExecutionContext(target="192.168.1.50", params={"target": "192.168.1.50"})
+
+ with pytest.raises(ModuleValidationError) as exc_info:
+ await mod.validate(ctx)
+
+ assert "username" in str(exc_info.value).lower()
+ assert exc_info.value.field == "username"
+
+
+async def test_scheduled_tasks_enum_validate_succeeds_with_credentials():
+ """Verify scheduled_tasks_enum validate() passes when username and target are provided."""
+ settings, campaign, noise = _make_context_deps()
+ mod = ScheduledTasksEnumModule(settings=settings, campaign=campaign, noise=noise)
+ ctx = ExecutionContext(
+ target="192.168.1.50",
+ params={"target": "192.168.1.50", "username": "Administrator"},
+ )
+ await mod.validate(ctx)
+
+
+async def test_enum_run_logs_warning_on_missing_params():
+ """Verify run() logs a structured warning when invoked without required params instead of silent abort."""
+ settings, campaign, noise = _make_context_deps()
+ mod_reg = RegistryEnumModule(settings=settings, campaign=campaign, noise=noise)
+ mod_tasks = ScheduledTasksEnumModule(settings=settings, campaign=campaign, noise=noise)
+
+ with patch("ares.modules.windows.registry_enum.logger.warning") as mock_reg_warn:
+ findings, raw = await mod_reg.run(target="192.168.1.50", username="")
+ assert findings == []
+ assert "error" in raw
+ mock_reg_warn.assert_called_once()
+
+ with patch("ares.modules.windows.scheduled_tasks_enum.logger.warning") as mock_tasks_warn:
+ findings, raw = await mod_tasks.run(target="192.168.1.50", username="")
+ assert findings == []
+ assert "error" in raw
+ mock_tasks_warn.assert_called_once()