Crates.io | virustotal-rs |
lib.rs | virustotal-rs |
version | 0.3.7 |
created_at | 2025-08-28 20:59:51.010901+00 |
updated_at | 2025-08-29 23:10:29.57768+00 |
description | Rust SDK for VirusTotal API v3 |
homepage | https://github.com/threatflux/virustotal-rs |
repository | https://github.com/threatflux/virustotal-rs |
max_upload_size | |
id | 1814621 |
size | 1,829,596 |
A comprehensive, async Rust SDK for the VirusTotal API v3 with advanced features including Model Context Protocol (MCP) server for AI/LLM integrations.
mcp-jwt
feature)mcp-oauth
feature)Add to your Cargo.toml
:
[dependencies]
virustotal-rs = "0.1.0"
# For MCP server functionality
virustotal-rs = { version = "0.1.0", features = ["mcp"] }
# For MCP with JWT authentication
virustotal-rs = { version = "0.1.0", features = ["mcp-jwt"] }
# For MCP with OAuth 2.1 authentication
virustotal-rs = { version = "0.1.0", features = ["mcp-oauth"] }
# Pull the latest MCP server image (Docker Hub)
docker pull threatflux/virustotal-rs-mcp:latest
# Or from GitHub Container Registry
docker pull ghcr.io/threatflux/virustotal-rs-mcp:latest
# Run with your VirusTotal API key
docker run -e VIRUSTOTAL_API_KEY=your_api_key -p 8080:8080 \
threatflux/virustotal-rs-mcp:latest
Download from GitHub Releases for:
use virustotal_rs::{ClientBuilder, ApiTier};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client for Public API
let client = ClientBuilder::new()
.api_key("your-api-key")
.tier(ApiTier::Public)
.build()?;
// Get file information
let file_hash = "44d88612fea8a8f36de82e1278abb02f";
let file_info = client.files().get_file_info(file_hash).await?;
println!("File reputation: {:?}", file_info.data.attributes.reputation);
// Get URL analysis
let url_id = client.urls().scan_url("https://example.com").await?;
let analysis = client.analyses().get_analysis(&url_id.data.id).await?;
println!("URL analysis status: {:?}", analysis.data.attributes.status);
Ok(())
}
# Start MCP HTTP server
VIRUSTOTAL_API_KEY=your_key cargo run --bin mcp_server --features mcp
# Or using Docker
docker run -e VIRUSTOTAL_API_KEY=your_key -p 8080:8080 \
threatflux/virustotal-rs-mcp:latest
# Connect with MCP Inspector
npx @modelcontextprotocol/inspector http://localhost:8080
SERVER_MODE=stdio VIRUSTOTAL_API_KEY=your_key cargo run --bin mcp_server --features mcp
Variable | Description | Default |
---|---|---|
VIRUSTOTAL_API_KEY |
Required VirusTotal API key | - |
SERVER_MODE |
Server mode: http or stdio |
http |
HTTP_ADDR |
HTTP server address | 127.0.0.1:8080 |
VIRUSTOTAL_API_TIER |
API tier: Public or Premium |
Public |
LOG_LEVEL |
Log level: error , warn , info , debug , trace |
info |
Category | Endpoints | Status |
---|---|---|
Files | Upload, scan, get info, comments, votes, relationships | ✅ Complete |
URLs | Scan, get info, comments, votes | ✅ Complete |
Domains | Get info, comments, votes, relationships | ✅ Complete |
IP Addresses | Get info, comments, votes, relationships | ✅ Complete |
Analyses | Get analysis results, comments | ✅ Complete |
Comments | CRUD operations, votes | ✅ Complete |
Collections | IOC collections management | ✅ Complete |
Livehunt | Real-time hunting rules (Premium) | ✅ Complete |
Retrohunt | Historical hunting jobs (Premium) | ✅ Complete |
Intelligence | VT Intelligence searches (Premium) | ✅ Complete |
Graphs | Relationship graphs (Premium) | ✅ Complete |
Private Scanning | Private file/URL analysis (Premium) | ✅ Complete |
All VirusTotal API errors are mapped to strongly-typed Rust errors:
use virustotal_rs::Error;
match client.files().get_file_info("invalid-hash").await {
Ok(file) => println!("File info: {:?}", file),
Err(Error::NotFound) => println!("File not found in VirusTotal"),
Err(Error::QuotaExceeded(msg)) => println!("API quota exceeded: {}", msg),
Err(Error::RateLimit(msg)) => println!("Rate limited: {}", msg),
Err(e) if e.is_retryable() => {
println!("Retryable error (will auto-retry): {}", e);
},
Err(e) => println!("Permanent error: {}", e),
}
# Clone the repository
git clone https://github.com/threatflux/virustotal-rs.git
cd virustotal-rs
# Build with all features
cargo build --all-features
# Run tests (requires VT_API_KEY environment variable)
export VT_API_KEY=your_api_key
cargo test --all-features
# Build the MCP server
cargo build --bin mcp_server --features mcp
The project includes a comprehensive Makefile for development:
# Quick development workflow
make dev # format + build + test
# Full validation (used in CI)
make all # format + lint + build + test + doc + security
# Individual commands
make fmt # Format code
make clippy # Run linting
make test # Run all tests
make doc # Generate documentation
make security # Security audits
make examples # Run examples (requires VT_API_KEY)
# Set your API key
export VIRUSTOTAL_API_KEY=your_api_key
# Run basic examples
cargo run --example test_file --all-features
cargo run --example test_url --all-features
# Run MCP server examples
cargo run --example mcp_http_server --features mcp
cargo run --example mcp_stdio_server --features mcp
# Run with JWT authentication
cargo run --example mcp_http_server_jwt --features mcp-jwt
The Model Context Protocol (MCP) enables AI models to securely access external data sources. This SDK includes a full MCP server implementation that provides threat intelligence tools to Language Models.
Tool | Description | Parameters |
---|---|---|
vt_file_scan |
Analyze files by hash/upload | hash or file_path |
vt_url_scan |
Analyze URLs | url |
vt_domain_info |
Get domain information | domain |
vt_ip_info |
Get IP address information | ip_address |
vt_search |
VirusTotal Intelligence search (Premium) | query |
vt_livehunt |
Manage hunting rules (Premium) | rule_content |
# Generate JWT configuration
cargo run --example jwt_token_generator --features mcp-jwt
# Start server with JWT
JWT_SECRET=your_secret cargo run --bin mcp_server --features mcp-jwt
# Configure OAuth settings
export OAUTH_CLIENT_ID=your_client_id
export OAUTH_CLIENT_SECRET=your_secret
# Start server with OAuth
cargo run --bin mcp_server --features mcp-oauth
# Build custom image
docker build -t my-vt-mcp-server .
# Run with custom configuration
docker run -d \
--name vt-mcp-server \
-e VIRUSTOTAL_API_KEY=your_key \
-e VIRUSTOTAL_API_TIER=Premium \
-e LOG_LEVEL=info \
-p 8080:8080 \
--restart unless-stopped \
threatflux/virustotal-rs-mcp:latest
# Health check
curl http://localhost:8080/health
This project uses an advanced automated release system:
main
after CI passesBREAKING CHANGE
or !:
feat:
or feature:
# Trigger manual release via GitHub Actions
gh workflow run auto-release.yml -f version_type=minor
# Patch release (0.1.0 → 0.1.1)
git commit -m "fix: resolve rate limiting edge case"
# Minor release (0.1.0 → 0.2.0)
git commit -m "feat: add new MCP authentication method"
# Major release (0.1.0 → 1.0.0)
git commit -m "feat!: redesign API structure
BREAKING CHANGE: Client initialization now requires explicit tier"
Regular security audits are performed automatically:
# Run security audit locally
make security
# Or individually
cargo audit # Known vulnerabilities
cargo deny check # License and source verification
Please report security vulnerabilities via GitHub Security Advisories.
Operation | Public API | Premium API | Notes |
---|---|---|---|
File Hash Lookup | ~200ms | ~150ms | Cached results faster |
URL Scan | ~500ms | ~400ms | Depends on URL complexity |
Domain Info | ~300ms | ~250ms | WHOIS data included |
Batch Operations | 4/min | No limit* | *Based on your plan |
// Use connection pooling for multiple requests
let client = ClientBuilder::new()
.api_key("key")
.tier(ApiTier::Premium)
.timeout(Duration::from_secs(30))
.build()?;
// Batch requests when possible
let hashes = vec!["hash1", "hash2", "hash3"];
let futures: Vec<_> = hashes.iter()
.map(|hash| client.files().get_file_info(hash))
.collect();
let results = futures::future::join_all(futures).await;
We welcome contributions! Please see our Contributing Guidelines for details.
git clone https://github.com/your-username/virustotal-rs.git
cd virustotal-rs
# Install Rust toolchain
rustup install stable
rustup default stable
# Install development tools
make install-tools
# Set API key for testing
export VIRUSTOTAL_API_KEY=your_test_key
make test
make examples # Integration tests
See CHANGELOG.md for detailed release notes.
This project is dual-licensed under either:
at your option.
Built with ❤️ by the ThreatFlux team# CI Status Check