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(accuracy): privesc writable path check on target not operator filesystem (MOD-038)

Mafifrizi907d38c73078
diff --git a/ares/modules/linux/privesc.py b/ares/modules/linux/privesc.py
index d0152fe..b497218 100644
--- a/ares/modules/linux/privesc.py
+++ b/ares/modules/linux/privesc.py
@@ -355,13 +355,14 @@ class LinuxPrivescModule(BaseModule[LinuxPrivescParams, ModuleResult]):
output = await run("getcap -r / 2>/dev/null")
return [line for line in output.splitlines() if line.strip()]
- async def _check_writable_path(self, run: Any = None) -> list[str]:
- path_env = os.environ.get("PATH", "")
- writable: list[str] = []
- for directory in path_env.split(":"):
- if directory and os.path.isdir(directory) and os.access(directory, os.W_OK):
- writable.append(directory)
- return writable
+ async def _check_writable_path(self, run: Callable[[str], Awaitable[str]] | None = None) -> list[str]:
+ if run is None:
+ return []
+ cmd = 'echo "$PATH" | tr \':\' \'\\n\' | while IFS= read -r d; do [ -n "$d" ] && [ -d "$d" ] && [ -w "$d" ] && echo "$d"; done'
+ output = await run(cmd)
+ if not output or not isinstance(output, str):
+ return []
+ return [line.strip() for line in output.splitlines() if line.strip()]
async def _check_world_writable_sensitive(self, run: Any = None) -> list[str]:
sensitive_paths = [
@@ -454,14 +455,18 @@ class LinuxPrivescModule(BaseModule[LinuxPrivescParams, ModuleResult]):
writable = raw.get("writable_path", [])
if writable:
self.finding(
- title=f"Writable PATH Dirs ({len(writable)})",
- description="Current user can write to $PATH dirs - PATH hijacking possible.",
+ title=f"Writable PATH Dirs on {target_host} ({len(writable)})",
+ description=(
+ f"Current user on {target_host} has write access to $PATH directory/directories "
+ f"({', '.join(writable[:3])}). PATH hijacking or malicious binary planting is possible."
+ ),
severity=Severity.HIGH,
mitre_technique="T1574.006",
mitre_tactic="Privilege Escalation",
- evidence={"directories": writable},
- remediation="Remove write permissions from PATH directories.",
+ evidence={"host": target_host, "directories": writable},
+ remediation="Remove write permissions from PATH directories: chmod go-w <dir>.",
host=target_host,
+ confidence=0.95,
)
has_root_vector = bool(exploitable) or any("NOPASSWD" in line for line in sudo_rules) or bool(found_caps)
diff --git a/tests/unit/modules/test_modules.py b/tests/unit/modules/test_modules.py
index 6a5771c..e437114 100644
--- a/tests/unit/modules/test_modules.py
+++ b/tests/unit/modules/test_modules.py
@@ -65,14 +65,41 @@ class TestContainerEscape:
class TestLinuxPrivesc:
@pytest.mark.asyncio
- async def test_writable_path_detection(self):
- import os
+ async def test_writable_path_detection_executes_on_target(self):
+ """Path writability check must execute via remote runner on target, ignoring operator filesystem."""
+ from unittest.mock import AsyncMock
module, _ = _make_module(LinuxPrivescModule)
- with patch("os.environ.get", return_value="/usr/bin:/tmp/writable"), \
- patch("os.path.isdir", return_value=True), \
- patch("os.access", side_effect=lambda p, m: "writable" in p):
- result = await module._check_writable_path()
- assert "/tmp/writable" in result
+
+ # Mock target runner returning writable paths found on remote target
+ mock_runner = AsyncMock(return_value="/usr/local/bin\n/opt/tools/bin\n")
+
+ result = await module._check_writable_path(run=mock_runner)
+
+ # Verify command executed on target
+ assert mock_runner.called
+ assert "echo \"$PATH\"" in mock_runner.call_args[0][0]
+ assert result == ["/usr/local/bin", "/opt/tools/bin"]
+
+ @pytest.mark.asyncio
+ async def test_writable_path_finding_attributed_to_target_host(self):
+ """Finding.host must be attributed to remote target IP/hostname, not localhost."""
+ module, _ = _make_module(LinuxPrivescModule)
+
+ target_host = "192.168.100.55"
+ raw = {
+ "host": target_host,
+ "writable_path": ["/usr/local/bin"],
+ }
+ module._analyze(raw)
+
+ writable_findings = [f for f in module._findings if "Writable PATH Dirs" in f.title]
+ assert len(writable_findings) == 1
+ finding = writable_findings[0]
+ assert finding.host == target_host
+ assert finding.host != "localhost"
+ assert target_host in finding.title
+ assert finding.evidence["host"] == target_host
+ assert "/usr/local/bin" in finding.evidence["directories"]
@pytest.mark.asyncio
async def test_world_writable_etc_passwd(self):
@@ -83,3 +110,4 @@ class TestLinuxPrivesc:
assert len(result) > 0
assert len(module._findings) > 0
assert module._findings[0].severity.value == "critical"
+