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(security): identity_federation_abuse ADFS scope check (MOD-050)

Mafifrizi802f2ca484bb
diff --git a/ares/modules/cloud/identity_federation.py b/ares/modules/cloud/identity_federation.py
index 646495e..471f000 100644
--- a/ares/modules/cloud/identity_federation.py
+++ b/ares/modules/cloud/identity_federation.py
@@ -290,9 +290,13 @@ class CloudIdentityFederationModule(BaseModule):
# ── Phase 3: ADFS Discovery and Golden SAML Path ─────────────────────
if adfs_url or domain:
- adfs_result = await loop.run_in_executor(
- None, lambda: self._enumerate_adfs(adfs_url, domain)
- )
+ res = self._enumerate_adfs(adfs_url, domain)
+ if asyncio.iscoroutine(res):
+ adfs_result = await res
+ elif callable(res):
+ adfs_result = await loop.run_in_executor(None, res)
+ else:
+ adfs_result = res
results["adfs_federation"] = adfs_result
# ── Phase 4: Token lifetime + B2B (when Graph token available) ─────────
@@ -502,7 +506,7 @@ class CloudIdentityFederationModule(BaseModule):
return result
- def _enumerate_adfs(self, adfs_url: str, domain: str) -> dict:
+ async def _enumerate_adfs(self, adfs_url: str, domain: str) -> dict:
"""Enumerate ADFS configuration and federation metadata."""
result: dict[str, Any] = {"error": None, "adfs_url": adfs_url, "endpoints": [],
"relying_parties": []}
@@ -512,6 +516,13 @@ class CloudIdentityFederationModule(BaseModule):
if not adfs_url:
return result
+ # Scope enforcement (MOD-050): Validate target before outbound HTTP request
+ from urllib.parse import urlparse
+ raw_url = adfs_url if "://" in adfs_url else f"https://{adfs_url}"
+ parsed = urlparse(raw_url)
+ target_host = parsed.hostname or adfs_url
+ await self.before_request(target_host, "http")
+
try:
import httpx
with httpx.Client(follow_redirects=False, timeout=15, verify=False) as client:
diff --git a/tests/unit/test_strategic_modules.py b/tests/unit/test_strategic_modules.py
index 482033a..71e77fc 100644
--- a/tests/unit/test_strategic_modules.py
+++ b/tests/unit/test_strategic_modules.py
@@ -402,6 +402,42 @@ class TestCloudFederationAbuse:
result = _run(mod.execute(ctx))
assert result.status == "dry_run" # must not attempt network
+ def test_adfs_scope_check_before_request_called(self, monkeypatch):
+ """MOD-050: before_request must be called with extracted target before outbound ADFS HTTP."""
+ from unittest.mock import AsyncMock, MagicMock
+ from ares.modules.cloud.identity_federation import CloudIdentityFederationModule
+ mod, _ = _make_module(CloudIdentityFederationModule)
+ mod.before_request = AsyncMock()
+
+ mock_client = MagicMock()
+ mock_client.__enter__.return_value = mock_client
+ mock_client.__exit__.return_value = False
+ mock_client.get.return_value = MagicMock(status_code=404, text="")
+ monkeypatch.setattr("httpx.Client", lambda *a, **kw: mock_client)
+
+ # Call with adfs_url
+ _run(mod._enumerate_adfs("https://adfs.corp.local/adfs", ""))
+ assert mod.before_request.called
+ call_target, call_proto = mod.before_request.call_args[0]
+ assert call_target == "adfs.corp.local"
+ assert call_proto == "http"
+
+ def test_adfs_scope_check_blocks_out_of_scope(self, monkeypatch):
+ """MOD-050: Out-of-scope ADFS target must raise ScopeViolationError and abort HTTP request."""
+ from unittest.mock import AsyncMock, MagicMock
+ from ares.core.errors import ScopeViolationError
+ from ares.modules.cloud.identity_federation import CloudIdentityFederationModule
+ mod, _ = _make_module(CloudIdentityFederationModule)
+ mod.before_request = AsyncMock(side_effect=ScopeViolationError("Target out of scope"))
+
+ mock_client = MagicMock()
+ monkeypatch.setattr("httpx.Client", lambda *a, **kw: mock_client)
+
+ with pytest.raises(ScopeViolationError):
+ _run(mod._enumerate_adfs("https://evil.external.com/adfs", ""))
+
+ assert not mock_client.called
+
# ══════════════════════════════════════════════════════════════════════════════
# ai.autonomous_planner