Model file scanning library for detecting malicious code in ML model files
Project description
ModelAudit
A security scanner for machine learning models. Quickly check your AIML models for potential security risks before deployment.
🔍 What It Does
ModelAudit scans ML model files for:
- Malicious code (e.g.,
os.systemcalls in pickled models) - Suspicious TensorFlow operations
- Potentially unsafe Keras Lambda layers
- Models with blacklisted names
- Dangerous pickle opcodes and serialization patterns
- Suspicious string patterns that might indicate encoded payloads
- Risky configurations in model architectures
- Suspicious patterns in model manifests and configuration files
🚀 Quick Start
Installation
# Using pip
pip install modelaudit
# Or with optional dependencies for specific model formats
pip install modelaudit[tensorflow,h5,pytorch]
# For YAML manifest scanning support
pip install modelaudit[yaml]
# For all dependencies
pip install modelaudit[all]
Basic Usage
# Scan one or more models or directories
modelaudit scan model.pkl model2.h5 models_directory
# Export results to JSON
modelaudit scan model.pkl --format json --output results.json
# Set maximum file size to scan
modelaudit scan model.pkl --max-file-size 1073741824 # 1GB limit
# Add custom blacklist patterns
modelaudit scan model.pkl --blacklist "unsafe_model" --blacklist "malicious_net"
✨ Features
- Multiple Format Support: Scans PyTorch, TensorFlow, Keras, and pickle models
- Automatic Format Detection: Identifies model formats automatically
- Comprehensive Scanning: Checks for various security issues with severity levels
- Batch Processing: Scan multiple files and directories at once
- Configurable Timeouts: Set scan timeouts for large models
- Detailed Reporting: Get information about scan duration, files scanned, and bytes processed
- Structured Output: Export results as JSON for integration with other tools
- Name Blacklisting: Block models with names matching suspicious patterns
- Manifest Scanning: Detect suspicious patterns in model configuration files
🛡️ Scanners
ModelAudit includes specialized scanners for different model formats:
- Pickle Scanner: Detects malicious code and encoded payloads in pickle files
- TensorFlow Scanner: Identifies suspicious operations in SavedModel format
- Keras Scanner: Checks for unsafe Lambda layers and risky configurations
- PyTorch Scanner: Examines PyTorch models for security issues
- Manifest Scanner: Analyzes model manifests and configuration files for suspicious patterns and blacklisted names
🛠️ Development
Using Poetry
# Clone the repository
git clone https://github.com/promptfoo/modelaudit.git
cd modelaudit
# Install dependencies
poetry install
# Install with extras
poetry install --extras "all"
📝 License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modelaudit-0.1.0.tar.gz.
File metadata
- Download URL: modelaudit-0.1.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3f915bc7d51647859df2eceb1c646e4e20e92c6443351014c4369b11f072ea7
|
|
| MD5 |
0f21d00e09dfc9e7eb261ae1f8cd07ba
|
|
| BLAKE2b-256 |
f44f694df8158454d1604631760d719def842bd4693b144e48efcac699716f5f
|
File details
Details for the file modelaudit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: modelaudit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9b22b741284b889b92b24025f17989cd995d8579adb6a807ee31746407135c1
|
|
| MD5 |
862f2a9fe455d3b3ea1dfacc15895bdb
|
|
| BLAKE2b-256 |
e72c961f9fb1d43714c02086071a91c11613b10daf20b89b380bd581f5aa3b3f
|