LoginSignup
3
4

More than 3 years have passed since last update.

Amazon Lightsail でハニーポット (T-Pot 20.06) を構築

Posted at

はじめに

Amazon Lightsail にハニーポットである T-Pot 20.06 をインストールしました。
本記事では、T-Pot の構築方法について説明します。

インスタンスの選定

インスタンスタイプについて

結論として、システム要件を満たしつつ安価に利用できる Lightsail を使用することにしました。

システム要件は System Requirements に記載されています。

Depending on the installation type, whether installing on real hardware or in a virtual machine, make sure the designated system meets the following requirements:

  • 8 GB RAM (less RAM is possible but might introduce swapping / instabilities)
  • 128 GB SSD (smaller is possible but limits the capacity of storing events)
  • Network via DHCP
  • A working, non-proxied, internet connection

これを満たすインスタンスの料金を EC2 と Lightsail で比較しました。

インスタンスタイプ 料金
EC2 (t3a.large, On-demand) $72.83/month
EC2 (t3a.large, RI 1年, 前払いなし) $45.04/month
EC2 (t3a.large, RI 3年, 前払いなし) $23.73/month
Lightsail (8GB メモリ) $40/month

3年のリザーブドインスタンスが最も安いですが、個人の趣味の範囲で3年後もハニーポットを運用している自信が無かったため、Lightsail を選択しました。
また、EC2 のオンデマンドインスタンスよりも Lightsail の方が安価であることは予想できましたが、1年のリザーブドインスタンスよりも安いというのは意外でした。

OS について

Debian 10.8 (buster)でインスタンスを起動しました。
これは、インストールドキュメントの Post-Install User には以下のように記載されており、T-Pot が Debian 10 上で動作することを前提としているためです。

In some cases it is necessary to install Debian 10 (Buster) on your own:

また、Amazon Linux 2 と Ubuntu でもインストールを試みましたが、それぞれ以下の理由によりインストールができませんでした。

Amazon Linux 2 の場合

T-Pot のインストーラーが apt を前提としています。そのため、パッケージマネージャとして yum を採用している Amazon Linux 2 は対応していませんでした。

Ubuntu 20.04 の場合

パッケージマネージャとして apt を採用している Ubuntu でもインストールは不可能でした。
T-Pot のインストーラーを実行したところ、インストーラー内で OS のチェックをしており、Debian focal (Ubuntu 20.04)はサポートしていないというエラーメッセージが表示されました。

sudo ./install.sh --type=auto --conf=tpot.conf
[sudo] password for user:

### Checking for root: [ OK ]
### Installing apt-fast
--2021-04-30 23:44:30--  https://raw.githubusercontent.com/ilikenwf/apt-fast/master/apt-fast
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22286 (22K) [text/plain]
Saving to: ‘/usr/local/sbin/apt-fast’

/usr/local/sbin/apt-fast                             100%[===================================================================================================================>]  21.76K  --.-KB/s    in 0s

2021-04-30 23:44:30 (51.9 MB/s) - ‘/usr/local/sbin/apt-fast’ saved [22286/22286]

### Checking for installer dependencies: [ OK ]
Aborting. Debian focal is not supported.

T-Pot のインストール

T-Pot をインストールします。

USERNAME=new-user-name # ユーザ名を設定します

sudo apt update && sudo apt upgrade -y
sudo apt install git
sudo adduser ${USERNAME}
sudo gpasswd -a ${USERNAME} sudo
sudo su ${USERNAME}

# SSH の設定
## 接続元のローカル PC 側で事前にキーペアを作成してください
## $ ssh-keygen -t ed25519 
cd ${HOME}
mkdir .ssh
vim .ssh/authorized_keys # 公開鍵を設定
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

# T-Pot のインストール
git clone https://github.com/dtag-dev-sec/tpotce
cd tpotce/iso/installer/
cp tpot.conf.dist tpot.conf
vim tpot.conf # myCONF_WEB_USER と myCONF_WEB_PW に管理画面のユーザ名とパスワードを指定します。
sudo ./install.sh --type=auto --conf=tpot.conf

sudo reboot

管理用ポートの開放

T-Pot をインストール後に再起動した時点で SSH のポートが変更されます。そのため、 22 番ポートで SSH 接続ができなくなります。
そこで、以下のポートで管理用途のアクセスができるように設定します。
- 64295 (SSH 用)
- 64297 (Web 管理画面用)

また、念の為に接続元 IP アドレスを自宅のみに制限しています。
スクリーンショット 2021-05-01 091140.png

管理画面へのアクセス

Web ブラウザで https://<IPアドレス>:64297/ を開きます。
「この接続ではプライバシーが保護されません」と表示されますが、「詳細設定」から「<IPアドレス> にアクセスする(安全ではありません)」を選択してください。

インストールに成功していた場合、以下のような画面が表示されます。
スクリーンショット 2021-05-01 092537.png

攻撃を受けるためのポート開放

1~64000 番ポートを全世界に開放します。
スクリーンショット 2021-05-01 092932.png

動作確認

ポートを開放してから数分で攻撃を観測することができました。
スクリーンショット 2021-05-01 093740.png

追加の設定

追加で2点、設定を変更します。

ホスト名の設定

T-Pot インストール後に SSH 接続すると、ホスト名が roughblackboard に変更されています。
この状態では sudo コマンド実行すると sudo: unable to resolve host roughblackboard: Name or service not known というエラーが発生します。
そこで、/etc/hosts を編集し、名前解決ができるようにしました。

$ sudo vim /etc/hosts
#127.0.1.1 ip-172-26-12-88.ap-northeast-1.compute.internal ip-172-26-12-88
127.0.1.1 ip-172-26-12-88.ap-northeast-1.compute.internal ip-172-26-12-88 roughblackboard

スワップの作成

T-Pot を起動した時点で既にメモリの使用率が高く、システムが安定しませんでした。
free コマンドでメモリの使用量を確認してみると、約80%程度使用している事が分かります。

$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7979        6402         147          21        1429        1355
Swap:             0           0           0

そこで、スワップメモリを作成し、有効化します。
Debian 10 でスワップを作成する方法 - Tutorial Crawler を参考に設定しました。

sudo fallocate -l 8G /swapfile # 8GB のスワップファイルを作成します
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness = 10' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

スワップメモリが正常に追加されました。

$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7979        6416         148          21        1414        1343
Swap:          8191           0        8191

まとめ

T-Pot の構築方法について説明しました。
また、ハニーポットを運用していく上で何か知見があれば投稿しようと思っています。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4