terraform-provider-shodan

command module
v0.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2025 License: MIT Imports: 11 Imported by: 0

README ΒΆ

Terraform Provider for Shodan

Go Version Terraform Version Tests Release

A Terraform provider for managing Shodan network alerts and domain monitoring configurations. This provider allows you to programmatically create, manage, and monitor network security alerts and domains using Shodan's powerful threat detection capabilities.

πŸš€ New Features:

  • Domain Monitoring: Monitor domains for security threats with automatic IP resolution
  • Configurable Request Intervals: Built-in rate limiting to ensure compliance with Shodan's API limits
  • Multiple IP Support: Monitor multiple networks with single alerts

All API requests are automatically spaced apart to prevent hitting rate limits and ensure reliable operation. The request interval is configurable and defaults to 2 seconds between requests.

πŸ“‹ Prerequisites

πŸ“– Usage

Multiple IP Support

The provider now supports monitoring multiple IP addresses or network ranges in a single alert. You can specify:

  • Single network: network = ["192.168.1.0/24"]
  • Multiple networks: network = ["192.168.1.0/24", "10.0.0.0/8", "172.16.0.0/12"]
  • Mixed IP types: network = ["203.0.113.1/32", "198.51.100.0/24", "192.0.2.1/32"]

This allows you to consolidate monitoring for multiple networks into fewer alerts while maintaining the same level of security monitoring.

Benefits of Multiple IP Support:

  • Consolidated monitoring: Monitor multiple networks with a single alert
  • Easier management: Fewer alert resources to manage in Terraform
  • Cost effective: Reduce the number of Shodan alerts needed
  • Flexible: Mix different types of IP ranges (single IPs, subnets, large networks)
Domain Monitoring

The provider now supports monitoring domains for security threats with automatic IP resolution:

# Monitor a domain for security threats
resource "shodan_domain" "example_monitoring" {
  domain      = "example.com"
  name        = "Example Domain Security Monitoring"
  description = "Monitor example.com for security threats"
  enabled     = true
  
  triggers = [
    "ai",
    "malware",
    "vulnerable",
    "new_service",
    "ssl_expired"
  ]
  
  notifiers = ["default"]
  
  # Enable Slack notifications
  slack_notifications = ["slack_12345"]
}

# Get domain information
data "shodan_domain" "example_info" {
  domain = "example.com"
}

How Domain Monitoring Works:

  1. Automatic IP Resolution: The provider automatically resolves domains to IP addresses using Shodan's DNS API
  2. Alert Creation: Creates a Shodan alert with the resolved IP addresses
  3. Naming Convention: Uses __domain: {domain} format for automatic domain alerts
  4. IP Monitoring: Monitors all IP addresses associated with the domain for security threats

Benefits of Domain Monitoring:

  • Automatic IP Discovery: No need to manually track IP addresses for domains
  • Dynamic Monitoring: Automatically adapts to IP address changes
  • Comprehensive Coverage: Monitors all IP addresses associated with a domain
  • Easy Management: Monitor domains instead of individual IP ranges
  • Slack Integration: Direct Slack notification support for real-time alerts

Guides

The provider includes comprehensive guides to help you get started:

Provider Configuration

terraform {
  required_providers {
    shodan = {
      source = "AdconnectDevOps/shodan"
      version = "~> 0.1"
    }
  }
}

provider "shodan" {
  api_key = var.shodan_api_key
}
Request Interval Configuration

The provider automatically implements request spacing to ensure compliance with Shodan's API requirements:

  • Configurable intervals: Request interval is configurable via the request_interval provider attribute
  • Default behavior: Defaults to 2 seconds between requests if not specified
  • Thread-safe: Concurrent requests are properly queued and spaced
  • Flexible configuration: Can be adjusted based on your Shodan API plan limits
  • Resource cleanup: Rate limiter resources are automatically cleaned up when the provider is closed
Configuration Examples

Default interval (2 seconds between requests):

provider "shodan" {
  api_key = var.shodan_api_key
  # request_interval defaults to 2 if not specified
}

Slower requests (5 seconds between requests):

provider "shodan" {
  api_key           = var.shodan_api_key
  request_interval  = 5  # 5 seconds between requests
}

Faster requests (1 second between requests):

provider "shodan" {
  api_key           = var.shodan_api_key
  request_interval  = 1  # 1 second between requests
}

This feature helps prevent API rate limit errors and ensures your Terraform operations complete successfully.

Finding Your Slack Notifier IDs

To configure Slack notifications, you need to get your Slack notifier IDs from your Shodan account:

  1. Log into your Shodan account at shodan.io
  2. Go to Account Settings β†’ Notifications or Integrations
  3. Find your Slack integration and note the notifier ID
  4. Use this ID in your Terraform configuration:
variable "slack_notifier_ids" {
  description = "List of Slack notifier IDs from your Shodan account"
  type        = list(string)
  default     = ["xxxxxxxxxxx"]  # Your actual Slack notifier ID
  sensitive   = true
}

# Example: Using your actual Slack notifier ID
slack_notifier_ids = ["xxxxxxxxxxx"]  # Replace with your actual ID

πŸ’‘ Pro Tip: You can have multiple Slack notifiers for different channels or teams. Just add more IDs to the list:

slack_notifier_ids = [
  "first-id-here",      # Main alerts channel
  "another-id-here",    # Secondary channel
  "third-id-here"       # Team-specific channel
]
Comprehensive Security Monitoring
# Single network range
resource "shodan_alert" "security_monitoring" {
  name        = "comprehensive-security-monitoring"
  network     = ["172.16.0.0/12"]
  description = "Comprehensive security monitoring for internal network"
  
  triggers = [
    "ai",
    "malware",
    "vulnerable",
    "new_service",
    "open_database",
    "ssl_expired",
    "iot"
  ]
  
  notifiers = ["default"]  # Email notifications
}

# Multiple specific IPs for targeted monitoring
resource "shodan_alert" "targeted_monitoring" {
  name        = "targeted-ip-monitoring"
  network     = ["203.0.113.1/32", "198.51.100.1/32", "192.0.2.1/32"]
  description = "Targeted monitoring for specific critical IPs"
  
  triggers = [
    "ai",
    "malware",
    "vulnerable",
    "new_service"
  ]
  
  notifiers = ["default"]
}
Slack Integration and Email Notifications
resource "shodan_alert" "multi_network_slack" {
  name        = "multi-network-slack-monitoring"
  network     = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
  description = "Multi-network monitoring with Slack alerts"
  
  triggers = [
    "ai",
    "malware",
    "vulnerable",
    "new_service"
  ]
  
  notifiers = ["default"]
  
  slack_notifications = var.slack_notifier_ids
}

πŸ“š Resources

shodan_alert
Arguments
Name Type Required Description
name string Yes The name of the Shodan alert
network list(string) Yes The IP network range(s) to monitor ['192.168.1.0/24', '10.0.0.0/8']
description string No A description of the alert
tags list(string) No Tags to associate with the alert
enabled bool No Whether the alert is enabled (default: true)
triggers list(string) No List of trigger rules to enable
notifiers list(string) No List of notifier IDs to associate
slack_notifications list(string) No List of Slack channels IDs to send notifications to
Attributes
Name Type Description
id string The unique identifier for the Shodan alert
created_at string The timestamp when the alert was created
shodan_domain
Arguments
Name Type Required Description
domain string Yes The domain name to monitor (e.g., 'example.com')
name string No Optional custom name for the alert. If not provided, will use '__domain: {domain}' format
description string No Optional description of the domain monitoring alert
enabled bool No Whether the domain monitoring alert is enabled (default: true)
triggers list(string) No List of trigger rules to enable for domain monitoring
notifiers list(string) No List of notifier IDs to associate with the domain alert
Attributes
Name Type Description
id string The unique identifier for the Shodan domain alert
created_at string The timestamp when the domain alert was created

πŸ“Š Data Sources

shodan_domain
Arguments
Name Type Required Description
domain string Yes The domain name to lookup (e.g., 'example.com')
Attributes
Name Type Description
domain string The domain name that was looked up
tags list(string) Tags associated with the domain
subdomains list(string) List of subdomains found for the domain
data list(object) DNS records and other data for the domain
more bool Whether there are more results available

Available Trigger Rules

The following trigger rules are available for Shodan alerts:

  • end_of_life - End of life software detected
  • industrial_control_system - Industrial control system detected
  • internet_scanner - Internet scanner detected
  • iot - Internet of Things device detected
  • malware - Malware detected
  • new_service - New service detected
  • open_database - Open database detected
  • ssl_expired - SSL certificate expired
  • uncommon - Uncommon service detected
  • uncommon_plus - Extended uncommon service detection
  • vulnerable - Vulnerable service detected
  • vulnerable_unverified - Unverified vulnerable service

πŸ“§ Available Notifiers

  • default - Default email notifier (configured in Shodan account)
  • slack - Slack integration (configured in Shodan account)
Getting Slack Notifier IDs

To use Slack notifications, you need to get your Slack notifier ID from your Shodan account:

  1. Go to your Shodan account settings
  2. Navigate to "Notifications" or "Integrations"
  3. Find your Slack integration and note the notifier ID
  4. Use this ID in your Terraform configuration:
variable "slack_notifier_ids" {
  description = "List of Slack notifier IDs from your Shodan account"
  type        = list(string)
  default     = ["xxxxxxxxxxx"]  # Your actual Slack notifier ID
  sensitive   = true
}

resource "shodan_alert" "example" {
  # ... other configuration ...
  
  slack_notifications = var.slack_notifier_ids
}

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Shodan for providing the security monitoring API
  • HashiCorp for the Terraform plugin framework
  • The open-source community for inspiration and support

πŸ“ž Support


Note: This provider is not officially affiliated with Shodan. It's a community-driven project to bring Shodan's powerful security monitoring capabilities to Terraform workflows.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL