Skip to content
CVE-2026-113718 Microsoft Sentinel · KQL

Detect CVE-2026-113718: virtualenv xonsh Activation Script Code Injection via repr() Quoting in Microsoft Sentinel

Detects potential exploitation of CVE-2026-113718, a code injection vulnerability (CWE-94) in the Python virtualenv tool prior to 21.14.9. The POSIX xonsh activation script generator uses a quote() helper that relies on repr(), which leaves printable non-ASCII characters in the generated UTF-8 activate.xsh file. xonsh reads that file using the codec named by $XONSH_ENCODING. Under a legacy multibyte codec such as GBK or Big5, a UTF-8 trail byte can consume the backslash before an adjacent quote, so a Python string literal can close early and attacker-influenced statements can run when the user sources the script. The attacker must influence the prompt or destination value passed to virtualenv, and the user must later source the generated script. Affected: virtualenv >= 21.3.0, < 21.14.9. CVSS 7.1. A reproducer is included in the published advisory; the xonsh code-execution path was confirmed by maintainer review rather than rerun.

MITRE ATT&CK

Tactic
Execution Initial Access

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
// df00tech DF00-319ab8aa8d · https://df00tech.com/detections/CVE-2026-113718 · licence: https://df00tech.com/detections/licence
// Detect creation of xonsh activation scripts and suspicious virtualenv invocations (CVE-2026-113718)
let suspiciousPaths = dynamic(["\"", "'", "$(", "`", ";", "\n", "\\x"]);
union
(
DeviceProcessEvents
| where ProcessCommandLine has_any ("virtualenv", "-m venv", "python -m virtualenv")
| where ProcessCommandLine has_any (suspiciousPaths)
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, Signal="virtualenv-suspicious-path"
),
(
DeviceFileEvents
| where FileName =~ "activate.xsh"
| where ActionType == "FileCreated"
| project Timestamp, DeviceName, AccountName, FileName, FolderPath, InitiatingProcessCommandLine, Signal="activate-xsh-created"
),
(
DeviceProcessEvents
| where FileName in~ ("xonsh")
| where ProcessCommandLine has "activate.xsh"
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, Signal="activate-xsh-sourced"
)
| sort by Timestamp desc
high severity medium confidence

Surfaces virtualenv creations into paths containing shell metacharacters, creation of activate.xsh files, and xonsh sourcing activate.xsh, the exploitation chain for CVE-2026-113718.

Data Sources

Microsoft Defender for EndpointDeviceProcessEventsDeviceFileEvents

Required Tables

DeviceProcessEventsDeviceFileEvents

False Positives & Tuning

  • Legitimate developers creating virtualenvs in paths that happen to contain quote characters.
  • CI/CD systems that routinely create and source xonsh activation scripts.
  • Security researchers testing the PoC in a sandbox.

Other platforms for CVE-2026-113718


Testing Methodology

Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are further down this page.

  1. Test 1 Create virtualenv in path with embedded quote metacharacters

    Expected signal: Process creation event for python3 -m virtualenv with quote metacharacters in command line; file creation event for activate.xsh.

  2. Test 2 Source a crafted activate.xsh in xonsh

    Expected signal: xonsh process launch with activate.xsh on the command line; child process execution of injected marker.

  3. Test 3 Create xonsh activation script with non-ASCII path

    Expected signal: File creation of activate.xsh containing repr()-written non-ASCII path values.


Response Playbook

Triage

  1. Confirm the installed virtualenv version on the affected host (`pip show virtualenv` / `virtualenv --version`); versions >= 21.3.0 and < 21.14.9 are vulnerable.
  2. Inspect the full path and prompt value used in the flagged virtualenv creation command for shell metacharacters, non-ASCII, or embedded quote/subshell sequences.
  3. Open the generated activate.xsh file and review the quoted variable assignments (VIRTUAL_ENV, PATH, prompt) for injected xonsh/Python code produced via repr().
  4. Determine whether the activate.xsh was actually sourced by a xonsh shell and by which user/service account.

Containment

  1. Quarantine or delete any activate.xsh created in an untrusted or metacharacter-containing path and prevent it from being sourced.
  2. Upgrade virtualenv to >= 21.14.9 on all affected hosts and rebuild any virtual environments created by the vulnerable version in suspicious paths.

Evidence Collection

  1. Preserve the activate.xsh file, the creating process command line, and the parent process tree.
  2. Collect xonsh shell history and any child processes spawned after activate.xsh was sourced.

Escalation Criteria

  • !Escalate to IR if sourcing activate.xsh resulted in execution of unexpected commands or outbound network connections.
  • !Escalate if the virtualenv prompt or path was influenced by externally controlled input (e.g., CI job parameters, web-facing automation).

Investigation Guide

Forensic Artifacts

  • >activate.xsh contents and modification timestamp
  • >virtualenv/pip process command lines
  • >xonsh shell history (~/.local/share/xonsh/history_*)
  • >Parent/child process lineage around activation

Tuning Guidance

Baseline the legitimate paths where your developers and CI systems create virtualenvs; exclude known-good base directories. Tighten the metacharacter regex to the specific repr()-emitted escape patterns (\x, \u, embedded quotes) if command-line noise is high. Prioritize alerts where the virtualenv prompt or base path derives from untrusted input.


Hunting Queries

Enumerate all activate.xsh scripts and their creation context across the fleet to identify ones written to suspicious paths.

Hunting — KQL
kql
// df00tech DF00-319ab8aa8d · https://df00tech.com/detections/CVE-2026-113718 · licence: https://df00tech.com/detections/licence
DeviceFileEvents | where FileName =~ "activate.xsh" | join kind=inner (DeviceFileEvents | where FileName =~ "activate.xsh") on DeviceId | project Timestamp, DeviceName, FolderPath, InitiatingProcessCommandLine
Hunting — SPL
spl
``` df00tech DF00-319ab8aa8d · https://df00tech.com/detections/CVE-2026-113718 · licence: https://df00tech.com/detections/licence ```
index=* name="*activate.xsh" | stats count values(path) by host, user

Atomic Red Team Tests

Test 1 Create virtualenv in path with embedded quote metacharacters
linux

Simulates creating a virtual environment in a directory whose name contains quote characters that exercise the vulnerable repr()-based quoting in activate.xsh.

Command

bash
mkdir -p "/tmp/poc_$(printf 'ev\x27il')" && python3 -m virtualenv "/tmp/poc_$(printf 'ev\x27il')/venv" 2>/dev/null; cat "/tmp/poc_$(printf 'ev\x27il')/venv/bin/activate.xsh"

Cleanup

bash
rm -rf "/tmp/poc_$(printf 'ev\x27il')"

Expected Telemetry

Process creation event for python3 -m virtualenv with quote metacharacters in command line; file creation event for activate.xsh.

Expected Detection

kql virtualenv-suspicious-path and activate-xsh-created signals fire.

Test 2 Source a crafted activate.xsh in xonsh
linux

Sources an activation script in a xonsh shell to observe xonsh executing activate.xsh (where injected code would run).

Command

bash
python3 -m pip install xonsh 2>/dev/null; echo 'echo INJECTED_MARKER' >> /tmp/venv/bin/activate.xsh 2>/dev/null; xonsh -c 'source /tmp/venv/bin/activate.xsh' 2>/dev/null

Cleanup

bash
rm -rf /tmp/venv

Expected Telemetry

xonsh process launch with activate.xsh on the command line; child process execution of injected marker.

Expected Detection

activate-xsh-sourced signal fires in kql/spl/cql queries.

Test 3 Create xonsh activation script with non-ASCII path
linux

Creates a virtualenv in a path containing non-ASCII characters, which repr() leaves in the generated activate.xsh via the vulnerable quote() helper.

Command

bash
mkdir -p '/tmp/poc_café' && python3 -m virtualenv '/tmp/poc_café/venv' 2>/dev/null; grep -n 'VIRTUAL_ENV' '/tmp/poc_café/venv/bin/activate.xsh'

Cleanup

bash
rm -rf '/tmp/poc_café'

Expected Telemetry

File creation of activate.xsh containing repr()-written non-ASCII path values.

Expected Detection

activate-xsh-created / activate-xsh-file signals fire.

Related Detections