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): remove operator IMDS probe from cloud discovery modules - false finding + token leak (MOD-064)

Mafifrizid86750be90ac
diff --git a/ares/modules/cloud/aws.py b/ares/modules/cloud/aws.py
index 6af76da..1489fae 100644
--- a/ares/modules/cloud/aws.py
+++ b/ares/modules/cloud/aws.py
@@ -203,7 +203,6 @@ class AWSEnumModule(BaseModule):
("iam", partial(self._enum_iam, session)),
("s3", partial(self._enum_s3, session, region)),
("security_groups", partial(self._enum_security_groups, session, region)),
- ("imds", self._check_imds),
]:
try:
raw[label] = await loop.run_in_executor(None, fn)
@@ -299,18 +298,15 @@ class AWSEnumModule(BaseModule):
r["error"] = str(e)[:100]
return r
- def _check_imds(self) -> dict:
- import urllib.request, urllib.error
- r: dict = {"imdsv1_available": False}
- try:
- req = urllib.request.Request("http://169.254.169.254/latest/meta-data/iam/security-credentials/")
- with urllib.request.urlopen(req, timeout=3) as resp:
- r["imdsv1_available"] = True; r["credential_roles"] = resp.read().decode().strip().splitlines()
- except Exception: pass
- return r
+ # REMOVED (MOD-064): IMDS probing belongs in post-exploitation modules
+ # executed ON TARGET via remote command runner, not from operator machine.
+ # Probing 169.254.169.254 from operator host leaks operator IAM credentials
+ # and generates false findings attributed to engagement target.
+ # def _check_imds(self) -> dict:
+ # ...
def _analyze(self, raw):
- iam,s3,sgs,imds = raw.get("iam",{}),raw.get("s3",{}),raw.get("security_groups",{}),raw.get("imds",{})
+ iam,s3,sgs = raw.get("iam",{}),raw.get("s3",{}),raw.get("security_groups",{})
if not iam.get("root_mfa_enabled"):
self.finding(title="Root Account MFA Disabled",description="AWS root account lacks MFA. Unrestricted access risk.",
severity=Severity.CRITICAL,mitre_technique="T1078.004",mitre_tactic="Persistence",
@@ -336,12 +332,7 @@ class AWSEnumModule(BaseModule):
description=f"{len(open_sgs)} rules expose sensitive ports to 0.0.0.0/0.",
severity=Severity.HIGH,mitre_technique="T1046",mitre_tactic="Discovery",
evidence={"rules":open_sgs[:10]},remediation="Restrict ingress. Use VPN or SSM Session Manager.")
- if imds.get("imdsv1_available"):
- self.finding(title="IMDSv1 Available - SSRF → Credential Theft",
- description="EC2 IMDSv1 accessible without token. SSRF can extract IAM credentials.",
- severity=Severity.HIGH,mitre_technique="T1552.005",mitre_tactic="Credential Access",
- evidence={"roles":imds.get("credential_roles",[])},
- remediation="Require IMDSv2: aws ec2 modify-instance-metadata-options --http-tokens required.")
+ # REMOVED (MOD-064): Operator IMDS probe finding removed.
# Backward-compat alias - was AWSModule before v3.0.1
AWSModule = AWSEnumModule # noqa
diff --git a/ares/modules/cloud/gcp.py b/ares/modules/cloud/gcp.py
index e8be12b..af2db29 100644
--- a/ares/modules/cloud/gcp.py
+++ b/ares/modules/cloud/gcp.py
@@ -232,14 +232,10 @@ class GCPModule(BaseModule):
("iam", partial(self._check_iam_bindings, credentials, project_id)),
("gcs", partial(self._check_gcs_buckets, credentials, project_id)),
("service_accounts", partial(self._check_sa_keys, credentials, project_id)),
- ("metadata", self._check_metadata_server),
]:
await self.noise.rate_limiter.acquire("cloud_api")
try:
- if label == "metadata":
- raw[label] = await loop.run_in_executor(None, fn)
- else:
- raw[label] = await loop.run_in_executor(None, fn)
+ raw[label] = await loop.run_in_executor(None, fn)
except Exception as exc:
logger.warning(f"gcp_{label}_failed", error=str(exc)[:150])
raw[label] = {"error": str(exc)[:200]}
@@ -585,64 +581,9 @@ class GCPModule(BaseModule):
"total_accounts": len(service_accounts),
}
- # ── GCE Metadata Server ───────────────────────────────────────────────────
-
- def _check_metadata_server(self) -> dict[str, Any]:
- """
- Check if the GCE metadata server is reachable from this execution context.
- Accessible metadata server = SSRF → credential theft risk.
- Uses httpx (already in deps) instead of requests for consistency.
- """
- import httpx # type: ignore[import]
-
- metadata_url = "http://metadata.google.internal/computeMetadata/v1/instance/"
- try:
- with httpx.Client(follow_redirects=False, timeout=2) as client:
- resp = client.get(
- metadata_url,
- headers={"Metadata-Flavor": "Google"},
- )
- if resp.status_code == 200:
- # Try to list SA credentials exposed
- try:
- with httpx.Client(follow_redirects=False, timeout=2) as client2:
- sa_resp = client2.get(
- "http://metadata.google.internal/computeMetadata/v1"
- "/instance/service-accounts/",
- headers={"Metadata-Flavor": "Google"},
- )
- sa_list = sa_resp.text.strip().splitlines() if sa_resp.is_success else []
- except Exception:
- sa_list = []
-
- self.finding(
- title="GCE Metadata Server Accessible - SSRF → Credential Theft",
- description=(
- "The GCE metadata server (169.254.169.254) is reachable from this context. "
- "SSRF vulnerabilities in any application running here can steal service "
- "account tokens and escalate to GCP project-level access. "
- f"Service accounts exposed: {', '.join(sa_list) or 'unknown'}."
- ),
- severity=Severity.HIGH,
- mitre_technique="T1552.005",
- mitre_tactic="Credential Access",
- evidence={
- "metadata_url": metadata_url,
- "service_accounts": sa_list,
- "status_code": resp.status_code,
- },
- remediation=(
- "Require IMDSv2-equivalent: enable metadata server with SA scopes only. "
- "Enforce Workload Identity instead of SA bound to VM. "
- "Limit SA permissions with minimal IAM roles. "
- "Enable VPC Service Controls to restrict metadata access. "
- "Use WAF / SSRF protection on all internet-facing applications."
- ),
- )
- return {"accessible": True, "service_accounts": sa_list}
- except httpx.ConnectError:
- # Expected - not running on GCE or metadata blocked
- pass
- except Exception as exc:
- logger.debug("gcp_metadata_check_failed", error=str(exc)[:80])
- return {"accessible": False}
+ # REMOVED (MOD-064): IMDS probing belongs in post-exploitation modules
+ # executed ON TARGET via remote command runner, not from operator machine.
+ # Probing metadata.google.internal from operator host leaks operator IAM credentials
+ # and generates false findings attributed to engagement target.
+ # def _check_metadata_server(self) -> dict[str, Any]:
+ # ...
diff --git a/tests/unit/modules/test_cloud_imds_removal_mod064.py b/tests/unit/modules/test_cloud_imds_removal_mod064.py
new file mode 100644
index 0000000..07aeca8
--- /dev/null
+++ b/tests/unit/modules/test_cloud_imds_removal_mod064.py
@@ -0,0 +1,105 @@
+"""
+Tests for MOD-064: Removal of operator-host IMDS/metadata probing
+from cloud.aws and cloud.gcp discovery modules.
+"""
+
+import pytest
+from unittest.mock import MagicMock, patch
+from ares.core.campaign import Campaign, NoiseProfile, ScopeEntry
+from ares.core.config import AresSettings
+from ares.core.noise import NoiseController
+from ares.modules.cloud.aws import AWSEnumModule
+from ares.modules.cloud.gcp import GCPModule
+
+
+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="Cloud-IMDS-Test",
+ client="Unit-Testing",
+ scope=[ScopeEntry(cidr="10.0.0.0/8")],
+ noise_profile=NoiseProfile.NORMAL,
+ )
+ noise = NoiseController(campaign)
+ return settings, campaign, noise
+
+
+async def test_aws_imds_probe_removed():
+ """Verify cloud.aws run() no longer executes _check_imds or emits IMDS findings."""
+ settings, campaign, noise = _make_context_deps()
+ mod = AWSEnumModule(settings=settings, campaign=campaign, noise=noise)
+
+ mock_session = MagicMock()
+ mock_session.client.return_value.get_caller_identity.return_value = {
+ "Account": "123456789012",
+ "Arn": "arn:aws:iam::123456789012:user/test",
+ }
+ mock_session.client.return_value.get_account_password_policy.return_value = {
+ "PasswordPolicy": {"MinimumPasswordLength": 14}
+ }
+ mock_session.client.return_value.get_account_summary.return_value = {
+ "SummaryMap": {"AccountMFAEnabled": 1}
+ }
+ mock_paginator = MagicMock()
+ mock_paginator.paginate.return_value = []
+ mock_session.client.return_value.get_paginator.return_value = mock_paginator
+ mock_session.client.return_value.list_buckets.return_value = {
+ "Buckets": [{"Name": "test-safe-bucket"}]
+ }
+ mock_session.client.return_value.get_bucket_acl.return_value = {"Grants": []}
+
+ with patch.object(mod, "_make_session", return_value=mock_session):
+ findings, raw = await mod.run(
+ access_key="AKIAEXAMPLETESTKEY01",
+ secret_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ region="us-east-1",
+ )
+
+ # 1. IMDS check is completely gone from raw
+ assert "imds" not in raw
+
+ # 2. Other legitimate discovery operations remain active
+ assert "identity" in raw
+ assert "iam" in raw
+ assert "s3" in raw
+ assert "security_groups" in raw
+
+ # 3. No IMDS / SSRF findings generated
+ finding_titles = [f.title for f in findings]
+ assert not any("IMDS" in t for t in finding_titles)
+ assert not any("169.254.169.254" in str(f.description) for f in findings)
+
+
+async def test_gcp_metadata_probe_removed():
+ """Verify cloud.gcp run() no longer executes _check_metadata_server or emits metadata findings."""
+ settings, campaign, noise = _make_context_deps()
+ mod = GCPModule(settings=settings, campaign=campaign, noise=noise)
+
+ mock_iam_result = {"owner_count": 1, "service_account_users": []}
+ mock_gcs_result = {"buckets_audited": 2, "public_buckets": []}
+ mock_sa_result = {"old_keys": [], "many_keys": [], "total_accounts": 1}
+
+ with patch("ares.modules.cloud.gcp._get_gcp_credentials", return_value=MagicMock()), \
+ patch.object(mod, "_check_iam_bindings", return_value=mock_iam_result), \
+ patch.object(mod, "_check_gcs_buckets", return_value=mock_gcs_result), \
+ patch.object(mod, "_check_sa_keys", return_value=mock_sa_result):
+
+ findings, raw = await mod.run(project_id="test-secure-project")
+
+ # 1. metadata check is completely gone from raw
+ assert "metadata" not in raw
+
+ # 2. Legitimate GCP discovery operations remain active
+ assert raw.get("iam") == mock_iam_result
+ assert raw.get("gcs") == mock_gcs_result
+ assert raw.get("service_accounts") == mock_sa_result
+
+ # 3. No GCE metadata server findings generated
+ finding_titles = [f.title for f in findings]
+ assert not any("Metadata Server" in t for t in finding_titles)
+ assert not any("metadata.google.internal" in str(f.description) for f in findings)