T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- universal_permission_manager_skill.py:116
- Finding
- Arbitrary Command Execution with Automatic Privilege Escalation<![CDATA[ ## Vulnerability Details **File Location**: `universal_permission_manager_skill.py`, lines 116-146, 158-160, 222-248, and 391-411 **Vulnerability Type**: Arbitrary OS command execution with automatic `sudo` fallback **Risk Level**: High ### Vulnerable Code ```python def run_command_with_fallback(self, command_str: str) -> Dict[str, Any]: try: parsed_command = shlex.split(command_str) result = self._try_run_command(parsed_command) if result["status"] == "success": return result strategies = [ lambda cmd: self._try_run_with_user_flag(cmd), lambda cmd: self._try_run_with_sudo(cmd), lambda cmd: self._try_run_with_verb_runas(cmd) ] for strategy in strategies: result = strategy(parsed_command) if result["status"] == "success": return result return result ``` ```python def _try_run_command(self, command: List[str]) -> Dict[str, Any]: try: result = subprocess.run( command, capture_output=True, text=True, timeout=60 ) ``` ```python def _try_run_with_sudo(self, command: List[str]) -> Dict[str, Any]: if self.system == "Windows": return { "status": "error", "error": "sudo不适用于Windows系统", "command": " ".join(command), "strategy_used": "sudo_not_applicable" } try: new_command = ["sudo"] + command result = subprocess.run( new_command, capture_output=True, text=True, timeout=60 ) ``` ```python elif "运行命令" in query_lower or "执行命令" in query_lower: import re cmd_match = re.search( r'(?:运行命令|执行命令|run|execute)\s+(.+)', query, re.IGNORECASE ) if cmd_match: command = cmd_match.group(1) return manager.run_any_command_safely(command) else: if query.strip( ...[truncated 2089 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the default behavior that executes every non-empty query. 2. Replace generic command execution with narrowly scoped, per-operation APIs. 3. Maintain an explicit allowlist of permitted executable paths, subcommands, and arguments. 4. Reject shell interpreters, privilege tools, package managers, destructive utilities, redirections, arbitrary script paths, and unapproved network clients. 5. Never retry attacker-controlled commands using `sudo`. 6. Require explicit, operation-specific user confirmation before any state-changing command. 7. Run approved commands as a dedicated unprivileged account inside a sandbox or container. 8. Apply filesystem, network, process, syscall, and resource restrictions. 9. Use absolute paths to trusted executables and a controlled environment with a restricted `PATH`. 10. Record security audit logs without exposing secrets or complete sensitive command output. ]]>
