subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
def exec_cmd(cmd: str, timeout: int = 30, raise_on_error: bool = False) -> Tuple[int, str, str]: """执行 shell 命令""" try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout) if raise_on_error and result.returncode != 0: raise ExternalCommandError(cmd, result.returncode, result.stderr) return result.returncode, result.stdout, result.stderr- Confidence
- 98% confidence
- Finding
- The helper executes arbitrary shell strings with shell=True, creating a generic command-execution sink. In this file, some callers interpolate variable data such as session keys, service names, hosts, and filesystem paths into command strings, so if any of those values are attacker-controlled or malformed, they can trigger shell injection or unintended command chaining.
