Kippo SSH ハニーポットを CentOS 5.5 にセットアップする方法
重要: この手順は教育目的です。環境やネットワークの構成により動作やリスクが変わります。実運用ネットワークに接続する前に隔離されたテスト環境で検証してください。
概要
Kippo は攻撃者のブルートフォース試行やシェルでの操作ログを記録するための中間相互作用型 SSH ハニーポットです。Kojoney に触発されていますが、別実装です。詳細は公式ページを参照してください: http://code.google.com/p/kippo/。
このチュートリアルは CentOS 5.5 サーバに対するコンパイルとインストール方法を説明します。成功を保証するものではありません。
要件と前提
- CentOS 5.5 が稼働していること
- root 権限または sudo 権限
- ネットワークでのポートフォワーディング/iptables 操作が可能であること
- このガイドは Python 2.6 を前提としています。CentOS 5.5 のデフォルトは Python 2.4 です
重要な用語 1 行定義:
- ハニーポット: 攻撃者を誘引し、その活動を観察・記録する仕組み
Python 2.6 のインストール
CentOS 5 系ではデフォルトが Python 2.4 なので、Python 2.6 を別途導入します。以下の RPM パッケージを提供するリポジトリからインストールしてください:
http://www.geekymedia.com/tech-articles/rhel5-centos5-rpms-for-python-2-5-and-2-6/
重要な注意:
- インストール時は必要な rpm を選びます。少なくとも base の python パッケージと libs パッケージが必要です
- Python 2.6 を起動するにはコマンド python26 を使います。python は従来の Python 2.4 のまま残ります
- setuptools 等でインストールする際は python26 を明示して実行します 例: python26 setup.py install
Twisted、Zope Interface、PyCrypto のインストール
Twisted はイベント駆動のネットワークエンジンです。多くのプロトコルをサポートします。Zope Interface は Python 用のインタフェースライブラリ、PyCrypto は暗号ライブラリです。これらを Python 2.6 用にビルドしてインストールします。
cd /tmp
wget http://twistedmatrix.com/Releases/Twisted/10.2/Twisted-10.2.0.tar.bz2
tar -xvf Twisted-10.2.0.tar.bz2
cd Twisted-10.2.0
python26 setup.py build
python26 setup.py install
cd /tmp
wget http://www.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz
tar -xvf zope.interface-3.3.0.tar.gz
cd zope.interface-3.3.0
python26 setup.py build
python26 setup.py install
cd /tmp
wget http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz
tar -xvf pycrypto-2.0.1.tar.gz
cd pycrypto-2.0.1
python26 setup.py build
python26 setup.py install
ASN.1 実装 (pyasn1) もインストールします。
cd /tmp
wget http://sourceforge.net/projects/pyasn1/files/pyasn1-devel/0.0.12a/pyasn1-0.0.12a.tar.gz/download
tar -xvf pyasn1-0.0.12a.tar.gz
cd pyasn1-0.0.12a
python26 setup.py build
python26 setup.py install
通常ユーザーの作成
Kippo は root では動作させないでください。専用の通常ユーザーを作成します。
useradd kippouser
ローカルでテストする場合でも、Kippo を専用ユーザーで動かすことで被害の範囲を限定できます。
Kippo ソースパッケージのダウンロード
kippouser に切り替えてソースを取得します。最新版の配布 URL は当時 http://kippo.googlecode.com にありました。
su - kippouser
wget http://kippo.googlecode.com/files/kippo-0.5.tar.gz
tar -xvf kippo-0.5.tar.gz
cd kippo-0.5
Kippo の設定
設定ファイル kippo.cfg を編集します。重要なパラメータを以下に示します。コメントは訳していますが、設定行自体は変更しないでください。
#
# Kippo configuration file (kippo.cfg)
#
[honeypot]
# IP addresses to listen for incoming SSH connections.
#
# (default: 0.0.0.0) = any address
#ssh_addr = 0.0.0.0
# Port to listen for incoming SSH connections.
#
# (default: 2222)
ssh_port = 2222
# Hostname for the honeypot. Displayed by the shell prompt of the virtual
# environment.
#
# (default: sales)
hostname = sales
# Directory where to save log files in.
#
# (default: log)
log_path = log
# Directory where to save downloaded (malware) files in.
#
# (default: dl)
download_path = dl
# Directory where virtual file contents are kept in.
#
# This is only used by commands like 'cat' to display the contents of files.
# Adding files here is not enough for them to appear in the honeypot - the
# actual virtual filesystem is kept in filesystem_file (see below)
#
# (default: honeyfs)
contents_path = honeyfs
# File in the python pickle format containing the virtual filesystem.
#
# This includes the filenames, paths, permissions for the whole filesystem,
# but not the file contents. This is created by the createfs.py utility from
# a real template linux installation.
#
# (default: fs.pickle)
filesystem_file = fs.pickle
# Directory for miscellaneous data files, such as the password database.
#
# (default: data_path)
data_path = data
# Directory for creating simple commands that only output text.
#
# The command must be placed under this directory with the proper path, such
# as:
# txtcmds/usr/bin/vi
# The contents of the file will be the output of the command when run inside
# the honeypot.
#
# In addition to this, the file must exist in the virtual
# filesystem {filesystem_file}
#
# (default: txtcmds)
txtcmds_path = txtcmds
# Public and private SSH key files. If these don't exist, they are created
# automatically.
#
# (defaults: public.key and private.key)
public_key = public.key
private_key = private.key
# Initial root password. Future passwords will be stored in
# {data_path}/pass.db
#
# (default: 123456)
password = 123456
# IP address to bind to when opening outgoing connections. Used exclusively by
# the wget command.
#
# (default: not specified)
#out_addr = 0.0.0.0
# Sensor name use to identify this honeypot instance. Used by the database
# logging modules such as mysql.
#
# If not specified, the logging modules will instead use the IP address of the
# connection as the sensor name.
#
# (default: not specified)
#sensor_name=myhostname
# Fake address displayed as the address of the incoming connection.
# This doesn't affect logging, and is only used by honeypot commands such as
# 'w' and 'last'
#
# If not specified, the actual IP address is displayed instead (default
# behaviour).
#
# (default: not specified)
#fake_addr = 192.168.66.254
# MySQL logging module
#
# Database structure for this module is supplied in doc/sql/mysql.sql
#
# To enable this module, remove the comments below, including the
# [database_mysql] line.
#[database_mysql]
#host = localhost
#database = kippo
#username = kippo
#password = secret
設定ポイントのヒント:
- ssh_port を 2222 のままにすることで非特権ポートで動かせます
- download_path はサンプルファイルやマルウェアを保存するので、容量やアクセス権に注意してください
- データベース連携を使う場合は別途 DB ユーザーとスキーマを準備します
Kippo の起動
kippouser ユーザーで kippo-0.5 ディレクトリに入り、起動します。
./start.sh
標準では出力は log/kippo.log にリダイレクトされます。ログをリアルタイムで見るには:
tail -f log/kippo.log
グローバルに公開する方法
デフォルトで Kippo はポート 2222 を使います。Windows であればポート 22 が空いていれば 22 で動かすことも可能です。Linux 系で 22 を非 root で使うにはポート転送で 22 から 2222 にリダイレクトします。twisted のチャットでよく使われる方法:
iptables -t nat -A PREROUTING -i IN_IFACE -p tcp --dport 22 -j REDIRECT --to-port 2222
IN_IFACE は実インタフェース名 (例 eth0) に置き換えてください。
注意: 公開環境でハニーポットを稼働させる場合は法的・倫理的な観点での配慮、外部ネットワークへの影響評価、監視体制を整えてください。
動作確認
以下のコマンドでローカルから接続してテストします。ユーザーは root、パスワードは 123456 が設定例です。
ssh 127.0.0.1 -p 2222 -l root
ログイン成功後、プロンプトに以下のような表示が出れば期待どおりです。
sales:~#
よくある失敗と回避策
- Python バージョンを間違える: 必ず python26 でビルド/インストールを行う
- 権限不足: kippo を root で稼働させると危険。専用ユーザーで実行する
- ログ保存領域不足: dl や log ディレクトリの容量を監視する
- 公開時の IP フィルタ無し: まずは隔離ネットワークや VPN 内で検証する
セキュリティ強化・運用上の注意
- ネットワーク分離: 本番ネットワークとは VLAN で分離するか DMZ に配置する
- 侵害の連鎖防止: ハニーポットから外向きのトラフィックを制限し、マルウェアの拡散を防ぐ
- ログの転送: ログを外部のセキュアなログサーバに転送して改ざん対策を行う
- アクセス制御: 管理アクセスは限定 IP からのみ許可する
- 定期バックアップ: fs.pickle やデータベースを定期的に保存する
ロール別チェックリスト
- 管理者
- kippo.cfg をレビューして不要なモジュールを無効化する
- ログのローテーションと容量監視を設定する
- ネットワーク担当
- ポート転送とファイアウォールルールを確認する
- ハニーポット用の分離ネットワークを準備する
- セキュリティアナリスト
- ログから攻撃パターンを抽出して IOC を作成する
- マルウェアサンプルはサンドボックスで解析する
導入手順(ミニメソッド)
- テスト用 VM を用意する(スナップショット取得)
- Python 2.6 と依存ライブラリをインストールする
- kippo ユーザーを作成しソースを展開する
- kippo.cfg を最小構成で設定する
- start.sh で起動しログを確認する
- 公開する場合は NAT/iptables を設定する
- ログ収集とバックアップを確立する
受け入れ基準
- Kippo が指定ポートでリッスンしていること
- 接続試験でシェルプロンプトが表示されること
- 攻撃の試行が log/kippo.log に記録されること
- 保存先 dl にダウンロード試行のファイルが保存されること
トラブルシューティング
- start.sh 実行後に即終了する: log/kippo.log を確認し、依存モジュールの import エラーがないか確認する
- ポートにバインドできない: 他プロセスが同ポートを使用していないか確認する
- データが保存されない: ディレクトリの所有権とパーミッションを確認する
代替と発展的アプローチ
- 代替ハニーポット: Cowrie(Kippo の後継にあたる活発なプロジェクト)、Honeyd など
- 可視化: Kibana や Splunk にログを投入してダッシュボード化する
- 自動解析: 攻撃ログから自動で IOC を抽出するスクリプトを作る
終わりに
このガイドは CentOS 5.5 上で Kippo を動かす基本手順と、運用時に注意すべきポイントをまとめました。まずは隔離環境で検証を行い、ログの収集と監視体制を整えてからネットワークに接続してください。
まとめの要点:
- Python 2.6 と依存ライブラリを正しく導入する
- Kippo は非 root ユーザーで実行する
- 公開前にネットワーク分離とログ保護を準備する
参考リンク
- The Honeynet Project: http://www.honeynet.org/
- ハニーポット (Wikipedia): http://en.wikipedia.org/wiki/Honeypot_(computing)
- Kippo Project: http://kippo.googlecode.com/
- Iran Honeynet Project: http://www.honeynet.ir/
- CentOS: http://www.centos.org/