performing-network-traffic-analysis-with-zeek について
セキュリティ運用やインシデント対応向けの Zeek 分析スキルです。リアルタイム監視、PCAP のオフライン分析、構造化ログ、自作検知スクリプトを扱います。
主な機能
- 01ライブ通信の監視と PCAP 分析
- 02多様なプロトコルの構造化ログ生成
- 03独自の検知スクリプト作成
- 04脅威インテリジェンスの読み込みと通知生成
- 05クラスター構築と SIEM へのログ取り込み
活用シーン
- 01不審な接続やプロトコル異常の調査
- 02DNS トンネリングやビーコン動作の分析
- 03保存済み PCAP の事後調査
- 04ネットワークログの SIEM 連携
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill performing-network-traffic-analysis-with-zeekインストール後、Claude Code で/performing-network-traffic-analysis-with-zeekを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
Zeek によるネットワークトラフィック分析
概要
Zeek(旧称 Bro)は、パッシブなネットワークセキュリティモニターとして動作するオープンソースのネットワーク分析フレームワークです。従来のシグネチャベースの IDS ツールとは異なり、Zeek は観測したネットワークトラフィックから高精度な構造化ログを生成し、HTTP、DNS、TLS、SSH、SMTP、FTP など数十種類のプロトコルについて詳細なメタデータを記録します。Zeek の拡張可能なスクリプト言語を使えば、独自の検出ロジック、挙動分析、自動応答を実装できます。このスキルでは、Zeek のデプロイ、ログアーキテクチャの理解、カスタム検出スクリプトの作成、SIEM プラットフォームとの出力連携について説明します。
使用する場面
- Zeek を使ってネットワークトラフィック分析を実施するセキュリティ評価を行う場合
- 関連するセキュリティイベントのインシデント対応手順に従う場合
- 定期的なセキュリティテストや監査活動を実施する場合
- 実地テストを通じてセキュリティ制御を検証する場合
前提条件
- 4 コア以上の CPU と 8GB 以上の RAM を備えた Linux サーバー(Ubuntu 22.04+ または CentOS 8+)
- トラフィックキャプチャ用に設定されたネットワーク TAP または SPAN ポートミラーリング
- Zeek 6.0+ のインストール(パッケージマネージャーまたはソースからのコンパイル)
- パケットキャプチャ用の root 権限またはキャプチャグループ権限
- ログ取り込み用の SIEM プラットフォーム(Splunk、ELK Stack、または QRadar)
主な概念
Zeek アーキテクチャ
Zeek は主に 2 つのモードで動作します。
- ライブキャプチャ - 1 つ以上のネットワークインターフェース上のトラフィックをリアルタイムで監視します
- オフライン分析 - 保存済みの PCAP ファイルを処理して、過去のトラフィックを分析します
処理パイプラインは次の要素で構成されます。
- パケットキャプチャ層 - インターフェースまたは PCAP ファイルから生パケットを読み取ります
- イベントエンジン - TCP ストリームを再構成し、プロトコルイベントを生成します
- スクリプトインタープリター - イベントを処理してログを生成する Zeek スクリプトを実行します
- ログフレームワーク - TSV、JSON、またはカスタム形式で構造化ログを書き込みます
ログアーキテクチャ
Zeek はプロトコルごとのログファイルを生成します。
| ログファイル | 説明 |
|---|---|
conn.log | 継続時間、バイト数、状態を含む TCP/UDP/ICMP 接続の概要 |
dns.log | クエリタイプ、応答、TTL を含む DNS クエリと応答 |
http.log | URI、ユーザーエージェント、MIME タイプを含む HTTP リクエストとレスポンス |
ssl.log | 証明書チェーン、JA3/JA3S を含む TLS ハンドシェイクの詳細 |
files.log | MIME タイプ、ハッシュ(MD5、SHA1、SHA256)を含むファイル転送 |
notice.log | Zeek の検出スクリプトが生成したアラート |
weird.log | プロトコルの異常や想定外の挙動 |
x509.log | TLS 接続の証明書詳細 |
smtp.log | 送信者、受信者、件名などのメールメタデータ |
ssh.log | SSH 接続の詳細と認証結果 |
pe.log | Portable Executable ファイルのメタデータ |
dpd.log | 動的プロトコル検出の失敗 |
ワークフロー
ステップ 1:Zeek のインストールと設定
# Install Zeek on Ubuntu
sudo apt-get install -y zeek
# Or install from Zeek repository
echo 'deb http://download.opensuse.org/repositories/security:/zeek/xUbuntu_22.04/ /' | \
sudo tee /etc/apt/sources.list.d/zeek.list
sudo apt-get update && sudo apt-get install -y zeek-lts
# Verify installation
zeek --version
/opt/zeek/etc/node.cfg でノードレイアウトを設定します。
[manager]
type=manager
host=localhost
[proxy-1]
type=proxy
host=localhost
[worker-1]
type=worker
host=localhost
interface=eth0
lb_method=pf_ring
lb_procs=4
[worker-2]
type=worker
host=localhost
interface=eth1
lb_method=pf_ring
lb_procs=4
/opt/zeek/etc/networks.cfg でネットワーク定義を設定します。
# Internal network ranges
10.0.0.0/8 Private RFC1918
172.16.0.0/12 Private RFC1918
192.168.0.0/16 Private RFC1918
ステップ 2:ログと出力の設定
/opt/zeek/share/zeek/site/local.zeek を編集します。
# Load standard detection scripts
@load base/protocols/conn
@load base/protocols/dns
@load base/protocols/http
@load base/protocols/ssl
@load base/protocols/ssh
@load base/protocols/smtp
@load base/protocols/ftp
# Load file analysis
@load base/files/hash-all-files
@load base/files/extract-all-files
# Load detection frameworks
@load base/frameworks/notice
@load base/frameworks/intel
@load base/frameworks/files
@load base/frameworks/software
# Load additional protocol analyzers
@load policy/protocols/ssl/validate-certs
@load policy/protocols/ssl/log-hostcerts-only
@load policy/protocols/ssh/detect-bruteforcing
@load policy/protocols/dns/detect-external-names
@load policy/protocols/http/detect-sqli
# Enable JA3 fingerprinting
@load policy/protocols/ssl/ja3
# Enable JSON output for SIEM ingestion
@load policy/tuning/json-logs
redef LogAscii::use_json = T;
# Configure file extraction directory
redef FileExtract::prefix = "/opt/zeek/extracted/";
# Set notice email
redef Notice::mail_dest = "[email protected]";
ステップ 3:カスタム検出スクリプトの作成
一般的な脅威を検出するスクリプトを作成します。
DNS トンネリングの検出(/opt/zeek/share/zeek/site/detect-dns-tunnel.zeek):
@load base/protocols/dns
module DNSTunnel;
export {
redef enum Notice::Type += {
DNS_Tunnel_Suspected
};
# Threshold for suspicious DNS query length
const query_len_threshold = 50 &redef;
# Track query counts per host per domain
global dns_query_counts: table[addr, string] of count &default=0 &create_expire=5min;
# High query volume threshold
const query_volume_threshold = 100 &redef;
}
event dns_request(c: connection, msg: dns_msg, query: string, qtype: count, qclass: count)
{
if ( |query| > query_len_threshold )
{
local parts = split_string(query, /\./);
if ( |parts| > 3 )
{
local base_domain = cat(parts[|parts|-2], ".", parts[|parts|-1]);
dns_query_counts[c$id$orig_h, base_domain] += 1;
if ( dns_query_counts[c$id$orig_h, base_domain] > query_volume_threshold )
{
NOTICE([$note=DNS_Tunnel_Suspected,
$msg=fmt("Possible DNS tunneling: %s queries to %s with long query names",
c$id$orig_h, base_domain),
$conn=c,
$identifier=cat(c$id$orig_h, base_domain),
$suppress_for=30min]);
}
}
}
}
ビーコン動作の検出(/opt/zeek/share/zeek/site/detect-beaconing.zeek):
@load base/protocols/conn
module Beaconing;
export {
redef enum Notice::Type += {
C2_Beacon_Detected
};
# Track connection intervals
global conn_intervals: table[addr, addr, port] of vector of time &create_expire=1hr;
const min_connections = 20 &redef;
const jitter_threshold = 0.15 &redef;
}
event connection_state_remove(c: connection)
{
if ( c$id$resp_p == 80/tcp || c$id$resp_p == 443/tcp )
{
local key = [c$id$orig_h, c$id$resp_h, c$id$resp_p];
if ( key !in conn_intervals )
conn_intervals[key] = vector();
conn_intervals[key] += network_time();
if ( |conn_intervals[key]| >= min_connections )
{
local intervals: vector of interval = vector();
local i = 1;
while ( i < |conn_intervals[key]| )
{
intervals += conn_intervals[key][i] - conn_intervals[key][i-1];
i += 1;
}
# Calculate mean and standard deviation
local sum_val = 0.0;
for ( idx in intervals )
sum_val += interval_to_double(intervals[idx]);
local mean_val = sum_val / |intervals|;
local variance = 0.0;
for ( idx in intervals )
{
local diff = interval_to_double(intervals[idx]) - mean_val;
variance += diff * diff;
}
variance = variance / |intervals|;
local stddev = sqrt(variance);
if ( mean_val > 0 && (stddev / mean_val) < jitter_threshold )
{
NOTICE([$note=C2_Beacon_Detected,
$msg=fmt("Possible C2 beaconing: %s -> %s:%s (interval=%.1fs, jitter=%.2f)",
c$id$orig_h, c$id$resp_h, c$id$resp_p,
mean_val, stddev/mean_val),
$conn=c,
$identifier=cat(c$id$orig_h, c$id$resp_h),
$suppress_for=1hr]);
}
}
}
}
ステップ 4:インテリジェンスフレームワークの設定
脅威インテリジェンスフィードを Zeek に読み込みます。
# In local.zeek
@load frameworks/intel/seen
@load frameworks/intel/do_notice
redef Intel::read_files += {
"/opt/zeek/intel/malicious-ips.intel",
"/opt/zeek/intel/malicious-domains.intel",
"/opt/zeek/intel/malicious-hashes.intel",
};
インテリジェンスファイル形式(/opt/zeek/intel/malicious-ips.intel):
#fields indicator indicator_type meta.source meta.desc meta.do_notice
198.51.100.50 Intel::ADDR abuse.ch Known C2 server T
203.0.113.100 Intel::ADDR threatfeed Ransomware infrastructure T
ステップ 5:デプロイと運用
# Deploy Zeek cluster
sudo /opt/zeek/bin/zeekctl deploy
# Check cluster status
sudo /opt/zeek/bin/zeekctl status
# Process offline PCAP
zeek -r capture.pcap local.zeek
# View logs
cat /opt/zeek/logs/current/conn.log | zeek-cut id.orig_h id.resp_h id.resp_p proto service duration orig_bytes resp_bytes
# Search for specific connections
cat /opt/zeek/logs/current/dns.log | zeek-cut query answers | grep -i "suspicious"
# Rotate logs
sudo /opt/zeek/bin/zeekctl cron
ステップ 6:SIEM 連携
ELK Stack 用 Filebeat の設定:
filebeat.inputs:
- type: log
enabled: true
paths:
- /opt/zeek/logs/current/*.log
json.keys_under_root: true
json.add_error_key: true
fields:
source: zeek
fields_under_root: true
output.elasticsearch:
hosts: ["https://elasticsearch:9200"]
index: "zeek-%{+yyyy.MM.dd}"
setup.template.name: "zeek"
setup.template.pattern: "zeek-*"
分析手法
接続分析
# Find top talkers by bytes
cat conn.log | zeek-cut id.orig_h orig_bytes | sort -t$'\t' -k2 -rn | head -20
# Find long-duration connections (potential C2)
cat conn.log | zeek-cut id.orig_h id.resp_h id.resp_p duration | awk '$4 > 3600' | sort -t$'\t' -k4 -rn
# Find connections with unusual ports
cat conn.log | zeek-cut id.resp_p proto | sort | uniq -c | sort -rn | head -30
TLS 分析
# Find self-signed certificates
cat ssl.log | zeek-cut server_name validation_status | grep "self signed"
# Extract JA3 fingerprints for known malware
cat ssl.log | zeek-cut ja3 server_name | sort | uniq -c | sort -rn
# Find expired certificates
cat ssl.log | zeek-cut server_name not_valid_after | awk -F'\t' '$2 < systime()'
ベストプラクティス
- SPANではなくTAPを使用する - 負荷時のパケット損失を避けるため、SPANポートではなくネットワークTAPを使用します
- ワーカーのスケーリング - 監視対象トラフィック1 Gbpsあたり1つのZeekワーカーを割り当てます
- AF_PACKETクラスター - マルチコア処理には、負荷分散機能を備えたAF_PACKETを使用します
- ログローテーション - ログの自動ローテーションとアーカイブを設定します(デフォルト:毎時)
- インテル情報の更新 - 脅威インテリジェンスフィードの更新を少なくとも毎日自動化します
- パケット損失の監視 - パケットのドロップについて
capture_loss.logを監視します - カスタムスクリプト - 脅威の状況に基づいて、組織固有の検知機能を開発します