Detect CVE-2026-113718: virtualenv xonsh Activation Script Code Injection via repr() Quoting in Elastic Security
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
Elastic Detection Query
// df00tech DF00-319ab8aa8d · https://df00tech.com/detections/CVE-2026-113718 · licence: https://df00tech.com/detections/licence
sequence by host.id with maxspan=10m
[ process where process.name in ("python", "python3", "virtualenv") and
process.command_line like~ ("*virtualenv*", "*-m venv*") and
process.command_line regex~ """.*[\"'`;$].*""" ]
[ file where file.name == "activate.xsh" and event.action in ("creation", "file_create_event") ] Detects a virtualenv invocation into a path with shell metacharacters followed by creation of an activate.xsh script (CVE-2026-113718).
Data Sources
Required Tables
False Positives & Tuning
- Legitimate xonsh virtualenv setup.
- CI runners generating activation scripts.
- Benign paths containing special characters.
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.
- 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.
- 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.
- 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
- Confirm the installed virtualenv version on the affected host (`pip show virtualenv` / `virtualenv --version`); versions >= 21.3.0 and < 21.14.9 are vulnerable.
- Inspect the full path and prompt value used in the flagged virtualenv creation command for shell metacharacters, non-ASCII, or embedded quote/subshell sequences.
- Open the generated activate.xsh file and review the quoted variable assignments (VIRTUAL_ENV, PATH, prompt) for injected xonsh/Python code produced via repr().
- Determine whether the activate.xsh was actually sourced by a xonsh shell and by which user/service account.
Containment
- Quarantine or delete any activate.xsh created in an untrusted or metacharacter-containing path and prevent it from being sourced.
- 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
- Preserve the activate.xsh file, the creating process command line, and the parent process tree.
- 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.
// 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 ``` 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
Simulates creating a virtual environment in a directory whose name contains quote characters that exercise the vulnerable repr()-based quoting in activate.xsh.
Command
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
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.
Sources an activation script in a xonsh shell to observe xonsh executing activate.xsh (where injected code would run).
Command
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
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.
Creates a virtualenv in a path containing non-ASCII characters, which repr() leaves in the generated activate.xsh via the vulnerable quote() helper.
Command
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
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.