LoginSignup
1
0

More than 1 year has passed since last update.

[自動化] サブドメインの監視・報告システムを作ってみた。

Posted at

Webアプリを監視し、新しいサブドメインが見つかると報告してくれるシステムを作ってみました。

ほぼHaklukeさんのyoutube動画の内容です。こっち見た方がいいかも
5 Minutes to Build a Basic Monitoring and Alerting System for New Subdomains

利用するツール

オープンソースのツール3種類を使います。
- Anew (Tomnomnomさん)
- Haktrails (Haklukeさん)
- Notify (ProjectDiscovery)

環境設定

環境設定をしていきます。

VPSの設定

ここではDigitalOceanを使っていきます。
OSにはUbuntuを設定しました。

各種ツールのインストール

各種ツールを利用するためにGolangをインストールします。

sudo apt update && sudo apt install golang

SSHで回線が切れたときのためにTmuxをインストールします。

apt install tmux

オープンソースの各種ツールをインストールします。

GO111MODULE=on go get -v github.com/projectdiscovery/notify/cmd/notify
go get -u github.com/hakluke/haktrails
go get -u github.com/tomnomnom/anew

GOBINに$PATHをとおす。

毎回~/go/bin/haktrailsと打つのはめんどくさいのでGOBINに$PATHを通します。

まず~/.bashrcexport PATH="$PATH:~/go/bin/"を追加します。
そしてターミナルを再起動後、source ~/.bashrcと打ちます。

Configファイルを設定する。

SecurityTrails API keyを取得します。
haktrails-config.ymlファイルの<yourkey>を取得したkeyに書き換えます。

~/.config/haktools/haktrails-config.yml
securitytrails:
  key: <yourkey>

notify.confにアラートをとばしたいdiscord_webhook_urlを入力します。

~/.config/notify/notify.conf
discord: true
discord_webhook_url: https://a.b.c
discord_username: test

サブドメインの収集

サブドメインを収集するコマンドは以下のようになります。
Tomnomnomさんのanewツールを使用しています。

echo <ターゲットのURL> | haktrails subdomains | tee subdomains.txt

監視ツールの作成

常時ターゲットURLの監視を行うスクリプトを作ります。

monitor.sh
while :
do
    echo securitytrails.com | haktrails subdomains | tee subdomains.txt
    sleep 3600
done

実行権限を付与した後、実行可能となります。

chmod +x ./monitor.sh
Run ./monitor.sh

新しいサブドメインだけ収集するようできるようにする。

新しいサブドメイン情報だけを取得したい。
そういった場合はteeをTomnomnomさんのanewツールに書き換えます。

monitor.sh
while :
do
    echo securitytrails.com | haktrails subdomains | anew subdomains.txt
    sleep 3600
done

アラートを送る

実行結果をDiscordにとばすためにnotifyツールを使います。

./monitor.sh | notify
1
0
1

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
1
0