セキュリティ診断ツール「Nikto」を使ってサイトをチェックしよう | A Day In The Boy's Life

A Day In The Boy's Life

とあるエンジニアのとある1日のつぶやき。

昨今、個人情報漏洩やらサイト改ざんなどセキュリティ関連の話題を耳にしない日がないといっても言いぐらい多くなりましたが、サイト運営側にとってはその問題について特に気を使う領域になっています。


セキュリティと一言で言っても、様々な要因があってのセキュリティですので問題のないサイト作りというのは、なかなか容易なことではありません。

例えば、XSS(クロスサイト・スクリプティング)やSQLインジェクションは主にアプリ側に要因があったりしますし、アプリ側に問題がなくともミドルウェアに問題があり、サイト全体が脅威にさらされる事もあります。


今回紹介するNiktoは、そんなサイト上の様々な危険性を多角的にチェックしてくれるツールです。



Niktoとは?


Nikto (ニクトと読むらしい)は、オープンソースのセキュリティ診断ツールで、XSSなどのアプリ上に潜む問題から、ミドルウェアの設定など、多くのセキュリティ上問題となるであろう項目に対してチェックを行ってくれます。

Perlでかかれており、プラグインを独自に拡張する事も可能になっています。



Niktoの使い方


まずは、本家サイト からNiktoのソースをダウンロードし、サーバー上に展開します。

展開したディレクトリ内に、nikto.plファイルがありますので、それを実行するだけです。


実行するにあたっては、様々なオプションを指定することが出来ます。


# perl nikto.pl -h
Option host requires an argument
---------------------------------------------------------------------------
- Nikto 2.02/2.03 - cirt.net
+ ERROR: No host specified
-Cgidirs+ scan these CGI dirs: 'none', 'all', or values like "/cgi/ /cgi-a/"
-dbcheck check database and other key files for syntax errors (cannot be abbreviated)
-evasion+ ids evasion technique
-Format+ save file (-o) format
-host+ target host
-Help Extended help information
-id+ host authentication to use, format is userid:password
-mutate+ Guess additional file names
-output+ write output to this file
-port+ port to use (default 80)
-Display+ turn on/off display outputs
-ssl force ssl mode on port
-Single Single request mode
-timeout+ timeout (default 2 seconds)
-Tuning+ scan tuning
-update update databases and plugins from cirt.net (cannot be abbreviated)
-Version print plugin and database versions
-vhost+ virtual host (for Host header)
+ requires a value 

基本的な使い方としては、このような感じ。


# perl nikto.pl -host http://192.168.0.100 -o output.txt
---------------------------------------------------------------------------
- Nikto 2.02/2.03 - cirt.net
+ Target IP: 192.168.0.100
+ Target Hostname: 192.168.0.100
+ Target Port: 80
+ Start Time: 2008-07-12 17:12:54
---------------------------------------------------------------------------
+ Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7a mod_python/3.3.1 Python/2.4.4
- Allowed HTTP Methods: GET, HEAD, POST, OPTIONS, TRACE
+ OSVDB-877: HTTP method ('Allow' Header): 'TRACE' is typically only used for debugging and should be disabled. This message does not mean it is vulnerable to XST.
+ Apache/2.0.63 appears to be outdated (current is at least Apache/2.2.6). Apache 1.3.39 and 2.0.61 are also current.
+ mod_ssl/2.0.63 appears to be outdated (current is at least 2.8.30) (may depend on server version)
+ OpenSSL/0.9.7a appears to be outdated (current is at least 0.9.8g) (may depend on server version)
+ Python/2.4.4 appears to be outdated (current is at least 2.5.1)
+ mod_ssl/2.0.63 OpenSSL/0.9.7a mod_python/3.3.1 Python/2.4.4 - mod_ssl 2.8.7 and lower are vulnerable to a remote buffer overflow which may allow a remote shell (difficult to exploit). CAN-2002-0082.
+ OSVDB-3268: GET //icons/ : Directory indexing is enabled: /icons
+ OSVDB-3233: GET //icons/README : Apache default file found.
+ 4347 items checked: 9 item(s) reported on remote host
+ End Time: 2008-07-12 17:13:06 (12 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

「-h」オプションの後ろに、チェックをかけたいサイト(必ず自分が管理するサーバーのみを対象とすること)、「-o」オプションの後ろに、レポートを保存したいファイル名を指定します。

その他のオプションもありますので、ヘルプを参照してみてください。



Niktoのレポートを読み解く


例えば、先ほど出力されたレポートを見てみると・・・


- Allowed HTTP Methods: GET, HEAD, POST, OPTIONS, TRACE
+ OSVDB-877: HTTP method ('Allow' Header): 'TRACE' is typically only used for debugging and should be disabled. This message does not mean it is vulnerable to XST.

「TRACE」のHTTPリクエストが許可されていますよ。これはデバッグの時だけ使うべきだから無効にしたほうがよいですよ。でも、これはXST(Cross Site Tracing)の攻撃が可能といっているわけじゃないからね。

という感じです。

Cross Site Tracingの危険性については、こちら(@鳩丸ぐろっさり (用語集)) に詳しく書かれています。


このTRACEメソッドのリクエストを受け付けなくする設定方法は、「ApacheでTRACEメソッドを受付けなくする 」を参考にしてみてください。


その他にも、


+ Apache/2.0.63 appears to be outdated (current is at least Apache/2.2.6). Apache 1.3.39 and 2.0.61 are also current.

※ Apacheの最新ソースのバージョンでチェックがかかるので、パッケージで管理している場合は、どうしても差が出てしまいますが。


+ OSVDB-3268: GET //icons/ : Directory indexing is enabled: /icons

通常であれば、必要ないはずなので設定ファイル(httpd.conf)を編集してディレクトリにアクセスできないように

しておきましょう。


+ OSVDB-3092: GET //manual/ : Web server manual found.

iconsディレクトリの対処と同様。


+ OSVDB-3092: GET /hoge/README.TXT : This might be interesting...
+ OSVDB-3092: GET /hoge/LICENSE.txt : License file found may identify site software.

恐らくファイル名を決め打ちしてチェックしているのだと思いますが、ライセンス関係のファイルに重要な情報が書かれている場合もありますので、そういうファイルは削除・移動するようにしておきましょう。


+ OSVDB-3233: GET //index.html.en : Apache default foreign language file found. All default files should be removed from the web server as they may give an attacker additional system information.

こちらも通常であれば不要なので、削除しておきましょう。


+ OSVDB-637: GET /~root - Enumeration of users is possible by requesting ~username (responds with 'Forbidden' for users, 'not found' for non-existent users).


ユーザーディレクトリは、Apacheの設定ファイルにて編集可能です。


<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
UserDir disable

有効にする理由がない限りは、アクセスできないようにしておきましょう。


+ OSVDB-397: HTTP method ('Allow' Header): 'PUT' method could allow clients to save files on the web server.
+ OSVDB-5646: HTTP method ('Allow' Header): 'DELETE' may allow clients to remove files on the web server.
+ OSVDB-0: HTTP method ('Allow' Header): 'CONNECT' may allow server to proxy client requests.
+ OSVDB-13431: HTTP method ('Allow' Header): 'PROPFIND' may indicate DAV/WebDAV is installed. This may be used to get directory listings if indexing is allowed but a default page exists.
+ OSVDB-425: HTTP method ('Allow' Header): 'PROPPATCH' indicates DAV/WebDAV is installed.
+ OSVDB-5647: HTTP method ('Allow' Header): 'MOVE' may allow clients to change file locations on the web server.

WebDAVを利用している場合、これらのHTTPリクエストを許可する場合がありますが、それ以外であれば特に必要ないはずなので、これらのHTTPリクエストは停止しておいた方がよいでしょう。


様々なセキュリティチェックを行ってくれますので、どのようなレポートが出るのか全て把握はしていませんが・・・。



サイトを構築してみたら、一度このようなツールでセキュリティ診断をしてみてもいいかもしれません。

くれぐれも自分が管理していないサイトに対しては使用しないこと。