こんにちは。田中(邦)です。
今回は、”The most advanced penetration testing distribution,ever.” なLinuxディストリビューションであるKali Linuxを使ってウェブサービスの脆弱性をテストしてみます。
VagrantとVirtual Boxのインストール
VagrantとVirtualBoxはインストールしてあることが前提です。
インストールしていない方はまずインストールしておいてください。
ついでにプラグインのvagrant-vbguestも入れておくと便利だと思います。
Kali Linuxのインストール
まずはKali Linuxをインストールしないと始まりません。
こちら↓を参考に日本語版のKali Linuxをインストールします。
wasabeef/vagrant-kali-linux
https://github.com/wasabeef/vagrant-kali-linux
vagrant box add kali-jp http://dalvik.jp/vagrant/KaliLinux-1.0-jp-i686.box vagrant init kali
これでVagrantファイルができるのですが、今回はGUIを有効にしてみましょう。
config.vm.provider :virtualbox do |vb| ... vb.gui = true ... end
ここまでできたら
vagrant up
します。
Kali Linuxが起動したら
ID: vagrant
Password: vagrant
でログインします。
まずは各種パッケージのアップデート
$sudo su #apt-get update
GUIで使いたいのでxorgも入れちゃいます。
#apt-get xorg
ここまでできたらGUIに切り替えましょう。
#startx
とりあえず起動できました。
色々なツールを使ってみる
画面右上のKali Linuxというメニューを開いてみると、色々なツールがインストールされていることが分かります。
それでは実際に使っていきましょう。
(ご自分が管理しているサービスや、ローカルでお試しください。)
skipfish
まず、skipfishからいきましょう。
skipfishはGoogle製のセキュリティスキャナで、指定したウェブサイトをクロールしながら辞書を使って色々なリクエストを投げて脆弱性をチェックしてくれます。
詳しくは下記サイトなどをご覧ください。
Webアプリケーション向けのセキュリティスキャナ「skipfish」を使う | SourceForge.JP Magazine
http://sourceforge.jp/magazine/13/09/27/200000
Kali Linux -> Web Applications -> Web Vulnerability Scanners -> skipfish と選択します。
するとターミナルが開かれ下記のようにオプション一覧が表示されます。
skipfish version 2.05b by <lcamtuf@google.com> Usage: skipfish [ options ... ] -W wordlist -o output_dir start_url [ start_url2 ... ] Authentication and access options: -A user:pass - use specified HTTP authentication credentials -F host=IP - pretend that 'host' resolves to 'IP' -C name=val - append a custom cookie to all requests -H name=val - append a custom HTTP header to all requests -b (i|f|p) - use headers consistent with MSIE / Firefox / iPhone -N - do not accept any new cookies Crawl scope options: -d max_depth - maximum crawl tree depth (16) -c max_child - maximum children to index per node (512) -x max_desc - maximum descendants to index per branch (8192) -r r_limit - max total number of requests to send (100000000) -p crawl% - node and link crawl probability (100%) -q hex - repeat probabilistic scan with given seed -I string - only follow URLs matching 'string' -X string - exclude URLs matching 'string' -K string - do not fuzz parameters named 'string' -D domain - crawl cross-site links to another domain -B domain - trust, but do not crawl, another domain -Z - do not descend into 5xx locations -O - do not submit any forms -P - do not parse HTML, etc, to find new links Reporting options: -o dir - write output to specified directory (required) -M - log warnings about mixed content / non-SSL passwords -E - log all HTTP/1.0 / HTTP/1.1 caching intent mismatches -U - log all external URLs and e-mails seen -Q - completely suppress duplicate nodes in reports -u - be quiet, disable realtime progress stats Dictionary management options: -W wordlist - use a specified read-write wordlist (required) -S wordlist - load a supplemental read-only wordlist -L - do not auto-learn new keywords for the site -Y - do not fuzz extensions in directory brute-force -R age - purge words hit more than 'age' scans ago -T name=val - add new form auto-fill rule -G max_guess - maximum number of keyword guesses to keep (256) Performance settings: -l max_req - max requests per second (0.000000) -g max_conn - max simultaneous TCP connections, global (40) -m host_conn - max simultaneous connections, per target IP (10) -f max_fail - max number of consecutive HTTP errors (100) -t req_tmout - total request response timeout (20 s) -w rw_tmout - individual network I/O timeout (10 s) -i idle_tmout - timeout on idle HTTP connections (10 s) -s s_limit - response size limit (200000 B) -e - do not keep binary responses for reporting Safety settings: -k duration - stop scanning after the given duration h:m:s Send comments and complaints to <lcamtuf@google.com>.
任意のヘッダをリクエストに付与したり、同時接続数を制限したり、任意のクッキーをつけたりフォームの自動入力の設定を行ったりと色々できます。
早速使ってみましょう。
まず辞書が必要になるので↓こちらからskipfishごと落として中のdictionariesの中のcomplete.wlを使います。
https://code.google.com/p/skipfish/
touch test.wl skipfish -o /vagrant/result -W test.wl -S complete.wl -X /sessions/destroy "rack.session=value" http://your.domain.net
これだけでテストが始まります。
リンクが大量にあったりするようなサイトは数時間かかることもあると思いますので、終わるまで気長に待ってください。
Backbone.jsとかAngular.jsとかknockout.jsなんかで動的に生成しているようなサイトは、上手くクロールされないようです。
私はテストに必要なURLを一時的にトップページに表示してクロールさせるようにしました。
テストが終了すると、-oオプションで指定したディレクトリの中に大量にファイルができているのでindex.htmlを開きます。
(Chromeで開くと上手く表示されなかったのでSafariで開きました)
各項目をクリックすると、該当URLとリクエスト、レスポンスを表示することができます。
クリティカルな脆弱性はこの結果を見て修正していくと良いと思います。
くれぐれも自分が管理しているサービスやlocalhost以外で試さないようお願いします。
Vega
こちらも同じようなツールなのですが、GUIで動作します。
Kali Linux -> Web Applications -> Web Vulnerability Scanners -> Vega
から起動します。
起動すると画面左上に新しいスキャンを開始するためのアイコンがあるのでそれをクリックします。
対象URL、クッキーの設定など諸々行ってFinishをクリックすると自動的にテストが始まります。
テストが終わると下記のように結果が表示されます。
多少誤検出っぽいものもありました。
Proxyタブでリクエスト、レスポンスの内容を確認できます。
個人的にはskipfish使うならいらないんじゃないかなーという印象です。
Owasp-Zap
これも同じような脆弱性診断ツールです。
Kali Linux -> Web Applications -> Web Vulnerability Scanners -> zaproxy
で起動します。
画面上部の ポリシー -> スキャンポリシー で他のツールと同様クッキーなど色々と設定し、画面右側のテキストフィールドにURLを入力した後「攻撃」ボタンを押します。
結果は レポート -> HTMLレポート生成 を行うとブラウザに表示されます。
終わりに
以上、Kali Linuxをインストールして脆弱性のテストツールを何個か使ってみました。
3つほど使ってみましたが、個人的にはskipfishだけで良いんじゃないかなーという感じです。
Kali Linuxは脆弱性チェック用のツールが最初からたくさんインストールされていて、すぐに診断を開始することができるので、サービス公開前にクリティカルなものはこれで発見してセキュアなサービスを素早くリリースしたいですね。