Shodan Reconnaissance and Pentesting について
Shodan Reconnaissance and Pentestingは、許可を得た偵察を行うセキュリティ担当者向けのShodan活用ガイドです。WebやCLIでの検索、API利用、オンデマンドスキャン、監視、分析用データの出力を扱います。
主な機能
- 01Shodan CLIとAPIの手順
- 02ホストと条件指定によるサービス検索
- 03オンデマンドスキャンと状態確認
- 04ネットワーク監視の設定
- 05JSONまたはCSVの出力と解析
活用シーン
- 01ホストと公開サービスの一覧化
- 02既知のCVEに関連するサービスの検出
- 03許可済みネットワーク範囲の評価
- 04監視対象資産の変化の追跡
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ davila7/ claude-code-templates --skill shodan-reconnaissance-and-pentestingインストール後、Claude Code で/shodan-reconnaissance-and-pentestingを入力して読み込まれたか確認します。
詳細
Shodan によるリコネッサンスとペネトレーションテスト
目的
ペネトレーションテストの実施中に、Shodan をリコネッサンスツールとして活用するための体系的な手法を提供します。このスキルでは、Shodan の Web インターフェース、コマンドラインインターフェース(CLI)、REST API、検索フィルター、オンデマンドスキャン、ネットワーク監視機能を扱い、公開されているサービス、脆弱なシステム、IoT デバイスを発見する方法を説明します。
入力 / 前提条件
- Shodan アカウント: shodan.io の無料または有料アカウント
- API キー: Shodan アカウントのダッシュボードから取得
- 対象情報: 調査対象の IP アドレス、ドメイン、またはネットワーク範囲
- Shodan CLI: Python ベースのコマンドラインツールがインストールされていること
- 認可: 対象ネットワークに対するリコネッサンスの書面による許可
出力 / 成果物
- アセットインベントリ: 発見したホスト、ポート、サービスの一覧
- 脆弱性レポート: 特定された CVE と、公開されている脆弱なサービス
- バナーデータ: ソフトウェアのバージョンを明らかにするサービスバナー
- ネットワークマッピング: アセットの地理的および組織的な分布
- スクリーンショットギャラリー: 公開されているインターフェースの視覚的なリコネッサンス
- エクスポートデータ: さらなる分析のための JSON/CSV ファイル
基本ワークフロー
1. セットアップと設定
Shodan CLI のインストール
# Using pip
pip install shodan
# Or easy_install
easy_install shodan
# On BlackArch/Arch Linux
sudo pacman -S python-shodan
API キーの初期化
# Set your API key
shodan init YOUR_API_KEY
# Verify setup
shodan info
# Output: Query credits available: 100
# Scan credits available: 100
アカウント状態の確認
# View credits and plan info
shodan info
# Check your external IP
shodan myip
# Check CLI version
shodan version
2. 基本的なホストのリコネッサンス
単一ホストのクエリ
# Get all information about an IP
shodan host 1.1.1.1
# Example output:
# 1.1.1.1
# Hostnames: one.one.one.one
# Country: Australia
# Organization: Mountain View Communications
# Number of open ports: 3
# Ports:
# 53/udp
# 80/tcp
# 443/tcp
ホストがハニーポットかどうかの確認
# Get honeypot probability score
shodan honeyscore 192.168.1.100
# Output: Not a honeypot
# Score: 0.3
3. 検索クエリ
基本検索(無料)
# Simple keyword search (no credits consumed)
shodan search apache
# Specify output fields
shodan search --fields ip_str,port,os smb
フィルター付き検索(1 クレジット)
# Product-specific search
shodan search product:mongodb
# Search with multiple filters
shodan search product:nginx country:US city:"New York"
結果件数のカウント
# Get result count without consuming credits
shodan count openssh
# Output: 23128
shodan count openssh 7
# Output: 219
結果のダウンロード
# Download 1000 results (default)
shodan download results.json.gz "apache country:US"
# Download specific number of results
shodan download --limit 5000 results.json.gz "nginx"
# Download all available results
shodan download --limit -1 all_results.json.gz "query"
ダウンロードしたデータの解析
# Extract specific fields from downloaded data
shodan parse --fields ip_str,port,hostnames results.json.gz
# Filter by specific criteria
shodan parse --fields location.country_code3,ip_str -f port:22 results.json.gz
# Export to CSV format
shodan parse --fields ip_str,port,org --separator , results.json.gz > results.csv
4. 検索フィルターのリファレンス
ネットワークフィルター
ip:1.2.3.4 # Specific IP address
net:192.168.0.0/24 # Network range (CIDR)
hostname:example.com # Hostname contains
port:22 # Specific port
asn:AS15169 # Autonomous System Number
地理的フィルター
country:US # Two-letter country code
country:"United States" # Full country name
city:"San Francisco" # City name
state:CA # State/region
postal:94102 # Postal/ZIP code
geo:37.7,-122.4 # Lat/long coordinates
組織フィルター
org:"Google" # Organization name
isp:"Comcast" # ISP name
サービス / 製品フィルター
product:nginx # Software product
version:1.14.0 # Software version
os:"Windows Server 2019" # Operating system
http.title:"Dashboard" # HTTP page title
http.html:"login" # HTML content
http.status:200 # HTTP status code
ssl.cert.subject.cn:*.example.com # SSL certificate
ssl:true # Has SSL enabled
脆弱性フィルター
vuln:CVE-2019-0708 # Specific CVE
has_vuln:true # Has any vulnerability
スクリーンショットフィルター
has_screenshot:true # Has screenshot available
screenshot.label:webcam # Screenshot type
5. オンデマンドスキャン
スキャンの送信
# Scan single IP (1 credit per IP)
shodan scan submit 192.168.1.100
# Scan with verbose output (shows scan ID)
shodan scan submit --verbose 192.168.1.100
# Scan and save results
shodan scan submit --filename scan_results.json.gz 192.168.1.100
スキャン状態の監視
# List recent scans
shodan scan list
# Check specific scan status
shodan scan status SCAN_ID
# Download scan results later
shodan download --limit -1 results.json.gz scan:SCAN_ID
利用可能なスキャンプロトコル
# List available protocols/modules
shodan scan protocols
6. 統計と分析
検索統計の取得
# Default statistics (top 10 countries, orgs)
shodan stats nginx
# Custom facets
shodan stats --facets domain,port,asn --limit 5 nginx
# Save to CSV
shodan stats --facets country,org -O stats.csv apache
7. ネットワーク監視
アラートの設定(Web インターフェース)
1. Navigate to Monitor Dashboard
2. Add IP, range, or domain to monitor
3. Configure notification service (email, Slack, webhook)
4. Select trigger events (new service, vulnerability, etc.)
5. View dashboard for exposed services
8. REST API の利用
API の直接呼び出し
# Get API info
curl -s "https://api.shodan.io/api-info?key=YOUR_KEY" | jq
# Host lookup
curl -s "https://api.shodan.io/shodan/host/1.1.1.1?key=YOUR_KEY" | jq
# Search query
curl -s "https://api.shodan.io/shodan/host/search?key=YOUR_KEY&query=apache" | jq
Python ライブラリ
import shodan
api = shodan.Shodan('YOUR_API_KEY')
# Search
results = api.search('apache')
print(f'Results found: {results["total"]}')
for result in results['matches']:
print(f'IP: {result["ip_str"]}')
# Host lookup
host = api.host('1.1.1.1')
print(f'IP: {host["ip_str"]}')
print(f'Organization: {host.get("org", "n/a")}')
for item in host['data']:
print(f'Port: {item["port"]}')
クイックリファレンス
主要な CLI コマンド
| コマンド | 説明 | クレジット |
|---|---|---|
shodan init KEY | API キーの初期化 | 0 |
shodan info | アカウント情報の表示 | 0 |
shodan myip | 自身の IP の表示 | 0 |
shodan host IP | ホストの詳細 | 0 |
shodan count QUERY | 結果件数 | 0 |
shodan search QUERY | 基本検索 | 0* |
shodan download FILE QUERY | 結果の保存 | 100 件につき 1 |
shodan parse FILE | データの抽出 | 0 |
shodan stats QUERY | 統計 | 1 |
shodan scan submit IP | オンデマンドスキャン | IP につき 1 |
shodan honeyscore IP | ハニーポットのチェック | 0 |
*フィルターを使用すると、クエリごとに 1 クレジットを消費します
よく使う検索クエリ
| 目的 | クエリ |
|---|---|
| Web カメラの検索 | webcam has_screenshot:true |
| MongoDB データベース | product:mongodb |
| Redis サーバー | product:redis |
| Elasticsearch | product:elastic port:9200 |
| デフォルトパスワード | "default password" |
| 脆弱な RDP | port:3389 vuln:CVE-2019-0708 |
| 産業用システム | port:502 modbus |
| Cisco デバイス | product:cisco |
| 公開された VNC | port:5900 authentication disabled |
| 公開された FTP | port:21 anonymous |
| WordPress サイト | http.component:wordpress |
| プリンター | "HP-ChaiSOE" port:80 |
| カメラ(RTSP) | port:554 has_screenshot:true |
| Jenkins サーバー | X-Jenkins port:8080 |
| Docker API | port:2375 product:docker |
便利なフィルターの組み合わせ
| シナリオ | クエリ |
|---|---|
| 対象組織の偵察 | org:"Company Name" |
| ドメインの列挙 | hostname:example.com |
| ネットワーク範囲のスキャン | net:192.168.0.0/24 |
| SSL 証明書の検索 | ssl.cert.subject.cn:*.target.com |
| 脆弱なサーバー | vuln:CVE-2021-44228 country:US |
| 公開されている管理パネル | http.title:"admin" port:443 |
| データベースの公開 | port:3306,5432,27017,6379 |
クレジットシステム
| アクション | クレジットの種類 | コスト |
|---|---|---|
| 基本検索 | クエリ | 0(フィルターなし) |
| フィルター付き検索 | クエリ | 1 |
| 100 件の結果のダウンロード | クエリ | 1 |
| レポートの生成 | クエリ | 1 |
| IP 1 件のスキャン | スキャン | 1 |
| ネットワークモニタリング | 監視対象 IP | プランによる |
制約と制限事項
運用上の境界
- 1 秒あたり 1 リクエストにレート制限されています
- スキャン結果は即時ではありません(非同期)
- 同じ IP は 24 時間以内に再スキャンできません(Enterprise を除く)
- 無料アカウントのクレジットは制限されています
- 一部のデータは有料サブスクリプションが必要です
データの鮮度
- Shodan は継続的にクロールしていますが、データは数日から数週間前のものである場合があります
- オンデマンドスキャンは最新のデータを提供しますが、クレジットを消費します
- 履歴データは有料プランで利用できます
法的要件
- 許可を得た対象に対してのみ偵察を実施してください
- パッシブな偵察は一般的に合法ですが、管轄の法律を確認してください
- アクティブスキャン(scan submit)には許可が必要です
- すべての偵察活動を文書化してください
例
例 1:組織の偵察
# Find all hosts belonging to target organization
shodan search 'org:"Target Company"'
# Get statistics on their infrastructure
shodan stats --facets port,product,country 'org:"Target Company"'
# Download detailed data
shodan download target_data.json.gz 'org:"Target Company"'
# Parse for specific info
shodan parse --fields ip_str,port,product target_data.json.gz
例 2:脆弱なサービスの発見
# Find hosts vulnerable to BlueKeep (RDP CVE)
shodan search 'vuln:CVE-2019-0708 country:US'
# Find exposed Elasticsearch with no auth
shodan search 'product:elastic port:9200 -authentication'
# Find Log4j vulnerable systems
shodan search 'vuln:CVE-2021-44228'
例 3:IoT デバイスの発見
# Find exposed webcams
shodan search 'webcam has_screenshot:true country:US'
# Find industrial control systems
shodan search 'port:502 product:modbus'
# Find exposed printers
shodan search '"HP-ChaiSOE" port:80'
# Find smart home devices
shodan search 'product:nest'
例 4:SSL/TLS 証明書の分析
# Find hosts with specific SSL cert
shodan search 'ssl.cert.subject.cn:*.example.com'
# Find expired certificates
shodan search 'ssl.cert.expired:true org:"Company"'
# Find self-signed certificates
shodan search 'ssl.cert.issuer.cn:self-signed'
例 5:Python 自動化スクリプト
#!/usr/bin/env python3
import shodan
import json
API_KEY = 'YOUR_API_KEY'
api = shodan.Shodan(API_KEY)
def recon_organization(org_name):
"""Perform reconnaissance on an organization"""
try:
# Search for organization
query = f'org:"{org_name}"'
results = api.search(query)
print(f"[*] Found {results['total']} hosts for {org_name}")
# Collect unique IPs and ports
hosts = {}
for result in results['matches']:
ip = result['ip_str']
port = result['port']
product = result.get('product', 'unknown')
if ip not in hosts:
hosts[ip] = []
hosts[ip].append({'port': port, 'product': product})
# Output findings
for ip, services in hosts.items():
print(f"\n[+] {ip}")
for svc in services:
print(f" - {svc['port']}/tcp ({svc['product']})")
return hosts
except shodan.APIError as e:
print(f"Error: {e}")
return None
if __name__ == '__main__':
recon_organization("Target Company")
例 6:ネットワーク範囲の評価
# Scan a /24 network range
shodan search 'net:192.168.1.0/24'
# Get port distribution
shodan stats --facets port 'net:192.168.1.0/24'
# Find specific vulnerabilities in range
shodan search 'net:192.168.1.0/24 vuln:CVE-2021-44228'
# Export all data for range
shodan download network_scan.json.gz 'net:192.168.1.0/24'
トラブルシューティング
| 問題 | 原因 | 解決策 |
|---|---|---|
| API キーが設定されていない | キーが初期化されていない | shodan init YOUR_API_KEY を実行し、shodan info で確認します |
| クエリクレジットの枯渇 | 月間クレジットを消費済み | フィルターなしのクエリを使用するか、リセットを待つか、アップグレードします |
| ホストが最近クロールされた | 24 時間以内は IP を再スキャンできない | 既存のデータには shodan host IP を使用するか、24 時間待ちます |
| レート制限の超過 | 1 秒あたり 1 リクエストを超過 | API リクエストの間に time.sleep(1) を追加します |
| 検索結果が空 | 条件が具体的すぎるか、構文エラー | フレーズには引用符を使用します:'org:"Company Name"'。条件を広げます |
| ダウンロードしたファイルを解析できない | 破損しているか、形式が誤っている | gunzip -t file.gz で検証し、--limit を付けて再ダウンロードします |
コメント
Markdown 対応