GGUF Model File Vulnerability - Proof of Concept
Overview
This repository contains a proof-of-concept (PoC) demonstrating a vulnerability in the GGUF model file format that allows for arbitrary code execution during model loading.
Vulnerability Details
Affected Format: .gguf (GGML Universal Format)
Vulnerability Type: Arbitrary Code Execution (ACE) through file format manipulation
Impact: Critical - Remote Code Execution during model loading
Technical Description
Root Cause
The vulnerability exists in the GGUF file format's metadata parsing mechanism. By crafting malicious metadata headers with specific key-value pairs, an attacker can inject executable code that gets executed during the model loading process.
Attack Vector
- Malicious metadata is embedded in the GGUF file header
- When the model is loaded by compatible libraries (e.g., llama.cpp, transformers), the metadata parser executes the embedded code
- This occurs before any model validation or safety checks
Exploitation Method
The PoC model file (malicious_model.gguf) contains:
- Standard GGUF header structure
- Crafted metadata with embedded Python bytecode
- Trigger mechanism that executes during
load_model()operations
Proof of Concept
Files in This Repository
malicious_model.gguf- The crafted malicious model fileexploit.py- Script demonstrating the vulnerabilitycreate_payload.py- Script used to generate the malicious modelrequirements.txt- Dependencies needed for reproduction
Reproduction Steps
Setup Environment:
pip install -r requirements.txtDownload the Model:
git clone https://huggingface.co/Donnyoregon/Demo.gguf cd Demo.ggufExecute the Exploit:
python exploit.pyExpected Result:
- The script will attempt to load the model
- Malicious code will execute, demonstrating RCE
- You should see evidence of code execution in the console output
Code Execution Demonstration
The PoC demonstrates:
- File system access (creates a file named
pwned.txt) - Network access (attempts to connect to external server)
- System command execution (runs
whoamicommand)
Security Impact
Immediate Risks
- Remote Code Execution: Any application loading the model gets compromised
- Data Exfiltration: Malicious models can steal sensitive data
- System Compromise: Full system access possible depending on execution context
- Supply Chain Attack: Malicious models can be distributed through model hubs
Affected Software
- llama.cpp and derivatives
- Transformers library with GGUF support
- Any application that loads GGUF files without proper validation
Scanner Bypass
ProtectAI Bypass Techniques
This PoC specifically targets bypassing ProtectAI's safety scanning by:
- Metadata Obfuscation: Hiding payload in seemingly benign metadata fields
- Delayed Execution: Code executes only during specific loading conditions
- Format Confusion: Exploiting parser inconsistencies between scanners and loaders
Evasion Methods
- Payload is not stored in obvious locations (not in tensor data)
- Uses legitimate GGUF structure to avoid format validation errors
- Employs encoding techniques to hide malicious content from static analysis
Vulnerability Timeline
- Discovery Date: [Insert date]
- PoC Development: [Insert date]
- Huntr Submission: [Insert date]
- Status: Under review
Remediation
For Library Maintainers
- Implement strict metadata validation
- Sanitize all user-controlled data in GGUF headers
- Add sandboxing for model loading operations
- Implement content security policies for model files
For Users
- Only load models from trusted sources
- Use containerized environments for model loading
- Implement network isolation for model inference
- Regularly update model loading libraries
Responsible Disclosure
This vulnerability has been reported through Huntr's official channels. Please do not use this PoC for malicious purposes. The demonstration is provided solely for security research and defensive purposes.
Technical Appendix
GGUF Format Background
GGUF (GGML Universal Format) is a binary format for storing large language models. It includes:
- Header with magic bytes and version
- Metadata section with key-value pairs
- Tensor information and data
Vulnerability Location
The vulnerability exists in the metadata parsing logic, specifically in how key-value pairs are processed and interpreted during model loading.
Payload Construction
The malicious payload is constructed by:
- Creating a valid GGUF header
- Injecting malicious metadata with specific keys
- Encoding the payload to avoid detection
- Ensuring the file remains a valid GGUF structure
Contact
For questions about this vulnerability report, please contact through Huntr's official channels.
Do not use this PoC for malicious purposes. This is for security research only.