ばぁど・うぉっちんぐ

セキュリティに強いWeb屋。自由と春を求めて羽ばたく渡り鳥。

このブログはGoogle Analyticsを利用しています

【備忘録】フリーの脆弱性スキャナーNiktoの備忘録

最近、仕事でNiktoを使うようになっているので、Niktoに対しての備忘録。

Niktoとは?

github.com

概要①(英語)

Nikto is an Open Source (GPL) web server scanner which performs comprehensive tests against web servers for multiple items, including over 6700 potentially dangerous files/programs, checks for outdated versions of over 1250 servers, and version specific problems on over 270 servers. It also checks for server configuration items such as the presence of multiple index files, HTTP server options, and will attempt to identify installed web servers and software. Scan items and plugins are frequently updated and can be automatically updated. Nikto is not designed as a stealthy tool. It will test a web server in the quickest time possible, and is obvious in log files or to an IPS/IDS. However, there is support for LibWhisker's anti-IDS methods in case you want to give it a try (or test your IDS system).

概要①(日本語訳(基本はGoogle翻訳))

NiktoはオープンソースGPL)ライセンスで作成されている、Webサーバースキャナーであり、6700を超える潜在的に危険なファイル/プログラムを含む複数のアイテムについて、Webサーバーに対して包括的なテストを実行し、1250を超えるサーバーの古いバージョンをチェックし、270を超えるサーバーでバージョン固有の問題をチェックします。また、複数のインデックスファイルの存在、HTTPサーバーオプションなどのサーバー構成項目をチェックし、インストールされているWebサーバーとソフトウェアの識別を試みます。スキャンアイテムとプラグインは頻繁に更新され、自動的に更新できます。

概要①の要約

要約すると、Niktoは一言で言うとWebサーバースキャナー。 オープンソース(GPL)ライセンスで作成されているOSS。 6700を超える危険なファイル、プログラムなどのアイテムを知っており、それらの知見をもとにWebサーバーに対して、それらの危険なファイル、プログラムが存在しないかの包括的なテストを実行することができます。

6700というのは、危険なファイルの定義は定かではないが、他のものとして多種多様なWebサーバー(Apache, Nginx)、プログラム言語(PHPJava・・・)、Webフレームワーク(lalavel, Struts)、CMS(WordPressDrupal)などのデフォルトの公開設定しているファイルが公開状態になっていないかの検査パターンが用意されているという認識でいいだろう。

概要②(英語)

Not every check is a security problem. There are some items that are "info only" type checks that look for things that may not have a security flaw, but Pentester may not know are present on the server. These items are usually marked appropriately in the information printed. There are also some checks for unknown items which have been seen scanned for in log files. Not every check is a security problem. There are some items that are "info only" type checks that look for things that may not have a security flaw, but Pentester may not know are present on the server. These items are usually marked appropriately in the information printed. There are also some checks for unknown items which have been seen scanned for in log files.

概要②(基本はGoogle翻訳))

Niktoはステルスツールとして設計されていません。可能な限り迅速にWebサーバーをテストし、ログファイルまたはIPS / IDSで明らかになります。ただし、試してみたい(またはIDSシステムをテストしたい)場合に備えて、LibWhiskerのアンチIDSメソッドがサポートされています。 すべてのチェックがセキュリティの問題であるとは限りません。セキュリティ上の欠陥がない可能性のあるものを探す「情報のみ」のタイプのチェックである項目がいくつかありますが、Pentesterはサーバーに存在することを知らない可能性があります。これらのアイテムは通常、印刷される情報に適切にマークされています。ログファイルでスキャンされた不明なアイテムのチェックもいくつかあります。

概要②の要約

Niktoはステルスツールではない。なので、サーバーを監視している人に気づかれないように扱うようなツールではない。以前、SOC研修を受けた時、SIEMでサーバーへのリクエスト量を計測していたら、急激にリクエスト数が跳ね上がって監視役の人があたふたしたのを思い出した。確か、サーバーへ大量アクセスするときの手法としてNiktoを使ったって講師の人言っていたなぁ。。。 その時はスモークスクリーンとして使用されていて、Niktoのアクセスで監視役があたふたしているときに、本当にやりたい攻撃(XSSやSQLi)などを入れ込んでいた記憶。

Niktoのゴール(英語)

The goal of the project is to examine a web server to find potential problems and security vulnerabilities, including: ・Server and software misconfigurations ・Default files and programs ・Insecure files and programs ・Outdated servers and programs ・Pointers to lead a human tester to better manual testing Nikto is built on LibWhisker2 (by Rain Forest Puppy) and can run on any platform which has a Perl environment. It supports SSL, proxies, host authentication, attack encoding and more.

Niktoのゴール(基本はGoogle翻訳))

Niktoの目標は、Webサーバーを調べて、次のような潜在的な問題とセキュリティの脆弱性を見つけることです。 ・サーバーとソフトウェアの構成ミス ・デフォルトのファイルとプログラム ・安全でないファイルとプログラム ・古いサーバーとプログラム 人間のテスターをより良い手動テストに導くためのポインター Niktoは(Rain Forest Puppyによる)LibWhisker2上に構築されており、Perl環境を持つ任意のプラットフォームで実行できます。 SSL、プロキシ、ホスト認証、攻撃エンコーディングなどをサポートします。

Niktoのゴールの要約

引用形式では箇条書きが崩れてしまっているが、箇条書きの部分は下記。

  • サーバーとソフトウェアの構成ミス
  • デフォルトのファイルとプログラム
  • 安全でないファイルとプログラム
  • 古いサーバーとプログラム

人間のミスによる意図せず公開してしまっているファイルやディレクトリを見つけることや、安全ではないプログラムなどを見つけることができる。また、Perl環境で動いているので、Niktoを動かす際にPerl環境が必要な場合が存在する。

基本的なオプション

   Options:
       -ask+               Whether to ask about submitting updates
                               yes   Ask about each (default)
                               no    Don't ask, don't send
                               auto  Don't ask, just send
       -Cgidirs+           Scan these CGI dirs: "none", "all", or values like "/cgi/ /cgi-a/"
       -config+            Use this config file
       -Display+           Turn on/off display outputs:
                               1     Show redirects
                               2     Show cookies received
                               3     Show all 200/OK responses
                               4     Show URLs which require authentication
                               D     Debug output
                               E     Display all HTTP errors
                               P     Print progress to STDOUT
                               S     Scrub output of IPs and hostnames
                               V     Verbose output
       -dbcheck           Check database and other key files for syntax errors
       -evasion+          Encoding technique:
                               1     Random URI encoding (non-UTF8)
                               2     Directory self-reference (/./)
                               3     Premature URL ending
                               4     Prepend long random string
                               5     Fake parameter
                               6     TAB as request spacer
                               7     Change the case of the URL
                               8     Use Windows directory separator (\)
                               A     Use a carriage return (0x0d) as a request spacer
                               B     Use binary value 0x0b as a request spacer
        -Format+           Save file (-o) format:
                               csv   Comma-separated-value
                               htm   HTML Format
                               msf+  Log to Metasploit
                               nbe   Nessus NBE format
                               txt   Plain text
                               xml   XML Format
                               (if not specified the format will be taken from the file extension passed to -output)
       -Help              Extended help information
       -host+             Target host
       -IgnoreCode        Ignore Codes--treat as negative responses
       -id+               Host authentication to use, format is id:pass or id:pass:realm
       -key+              Client certificate key file
       -list-plugins      List all available plugins, perform no testing
       -maxtime+          Maximum testing time per host
       -mutate+           Guess additional file names:
                               1     Test all files with all root directories
                               2     Guess for password file names
                               3     Enumerate user names via Apache (/~user type requests)
                               4     Enumerate user names via cgiwrap (/cgi-bin/cgiwrap/~user type requests)
                               5     Attempt to brute force sub-domain names, assume that the host name is the parent domain
                               6     Attempt to guess directory names from the supplied dictionary file
       -mutate-options    Provide information for mutates
       -nointeractive     Disables interactive features
       -nolookup          Disables DNS lookups
       -nossl             Disables the use of SSL
       -no404             Disables nikto attempting to guess a 404 page
       -output+           Write output to this file ('.' for auto-name)
       -Pause+            Pause between tests (seconds, integer or float)
       -Plugins+          List of plugins to run (default: ALL)
       -port+             Port to use (default 80)
       -RSAcert+          Client certificate file
       -root+             Prepend root value to all requests, format is /directory
       -Save              Save positive responses to this directory ('.' for auto-name)
       -ssl               Force ssl mode on port
       -Tuning+           Scan tuning:
                               1     Interesting File / Seen in logs
                               2     Misconfiguration / Default File
                               3     Information Disclosure
                               4     Injection (XSS/Script/HTML)
                               5     Remote File Retrieval - Inside Web Root
                               6     Denial of Service
                               7     Remote File Retrieval - Server Wide
                               8     Command Execution / Remote Shell
                               9     SQL Injection
                               0     File Upload
                               a     Authentication Bypass
                               b     Software Identification
                               c     Remote Source Inclusion
                               x     Reverse Tuning Options (i.e., include all except specified)
       -timeout+          Timeout for requests (default 10 seconds)
       -Userdbs           Load only user databases, not the standard databases
                               all   Disable standard dbs and load only user dbs
                               tests Disable only db_tests and load udb_tests
       -until             Run until the specified time or duration
       -update            Update databases and plugins from CIRT.net
       -useproxy          Use the proxy defined in nikto.conf
       -Version           Print plugin and database versions
       -vhost+            Virtual host (for Host header)
              + requires a value

実際にやってみる

コマンド

$ perl nikto.pl -h 127.0.0.1 -p 8000 -nolookup -Format txt -o 

なんかPerlが既に入っていたのでPerlコマンドで実行。

ローカルにDjangoで簡易的なWebアプリを作成し試行しました。なので、portも通常のhttp/https通信で使われる80や443ではなく、Webアプリを立ち上げているportを指定。フォーマットとしては、txt形式で出力されるように指定しました。

実行結果(ターミナル)

$ perl nikto.pl -h 127.0.0.1 -p 8000 -nolookup -Format txt -o test_2021_0717_valtan_text.txt
- ***** SSL support not available (see docs for SSL install) *****
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          127.0.0.1
+ Target Hostname:    127.0.0.1
+ Target Port:        8000
---------------------------------------------------------------------------
+ SSL Info:        Subject:  
                   Ciphers:  
                   Issuer:   
+ Start Time:         2021-07-18 15:50:01 (GMT9)
---------------------------------------------------------------------------
+ Server: WSGIServer/0.2 CPython/3.7.2
+ The site uses SSL and the Strict-Transport-Security HTTP header is not defined.
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Hostname '127.0.0.1' does not match certificate's names: 
+ OSVDB-17113: /SilverStream: SilverStream allows directory listing
+ ///etc/hosts: The server install allows reading of any system file by adding an extra '/' to the URL.
+ Server banner changed from 'WSGIServer/0.2 CPython/3.7.2' to 'WSGIServer/0.2 Python/3.7.2'
+ /wp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpress/wp-content/themes/twentyeleven/images/headers/server.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpress/wp-includes/Requests/Utility/content-post.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /wordpress/wp-includes/js/tinymce/themes/modern/Meuhy.php?filesrc=/etc/hosts: A PHP backdoor file manager was found.
+ /assets/mobirise/css/meta.php?filesrc=: A PHP backdoor file manager was found.
+ /login.cgi?cli=aa%20aa%27cat%20/etc/hosts: Some D-Link router remote command execution.
+ /shell?cat+/etc/hosts: A backdoor was identified.
+ 8078 requests: 0 error(s) and 14 item(s) reported on remote host
+ End Time:           2021-07-18 15:51:13 (GMT9) (72 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

フィイルとしてアウトプットされたのも上記と同じ内容が出力されていた。

内容を見てみると、ヘッダーにStrict-Transport-Securityがついていないとの指摘が。ローカルの開発なので勘弁・・・

気になるのが、Djangoのプロジェクトなのにwordpressに関連するwp-includeswordpressなどが検知されていること。ローカル環境、変な汚れ方しているのかな・・・わからん。

【おまけ】実行結果(サーバー側)

当たり前のようだが、Niktoから大量のリクエストを受け付けていることを確認。

一部抜粋。nginxのファイルや、Docker、GitHubのReadmeなど考えられるありとあらゆる公開されていると思われるファイルへのリクエストを投げて404が返ってくる(ファイルが存在しない)ことを確認している。

[18/Jul/2021 06:51:13] "GET /nginx_status HTTP/1.1" 404 2089
Not Found: /Dockerfile
[18/Jul/2021 06:51:13] "GET /Dockerfile HTTP/1.1" 404 2083
Not Found: /cdn-cgi/trace
[18/Jul/2021 06:51:13] "GET /cdn-cgi/trace HTTP/1.1" 404 2092
Not Found: /v1/tasks
[18/Jul/2021 06:51:13] "GET /v1/tasks HTTP/1.1" 404 2077
Not Found: /v2/tasks
[18/Jul/2021 06:51:13] "GET /v2/tasks HTTP/1.1" 404 2077
Not Found: /v3/tasks
[18/Jul/2021 06:51:13] "GET /v3/tasks HTTP/1.1" 404 2077
Not Found: /v4/tasks
[18/Jul/2021 06:51:13] "GET /v4/tasks HTTP/1.1" 404 2077
Not Found: /.dockerignore
[18/Jul/2021 06:51:13] "GET /.dockerignore HTTP/1.1" 404 2092
Not Found: /tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp
[18/Jul/2021 06:51:13] "GET /tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/etc/hosts HTTP/1.1" 404 2237
Not Found: /
[18/Jul/2021 06:51:13] "GET / HTTP/1.1" 404 2035
Not Found: /var/
[18/Jul/2021 06:51:13] "GET /var/ HTTP/1.1" 404 2065
Not Found: /var/log/
[18/Jul/2021 06:51:13] "GET /var/log/ HTTP/1.1" 404 2077
Not Found: /etc/
[18/Jul/2021 06:51:13] "GET /etc/ HTTP/1.1" 404 2065
Not Found: /.ftpconfig
[18/Jul/2021 06:51:13] "GET /.ftpconfig HTTP/1.1" 404 2083
Not Found: /.remote-sync.json
[18/Jul/2021 06:51:13] "GET /.remote-sync.json HTTP/1.1" 404 2104
Not Found: /.vscode/ftp-sync.json
[18/Jul/2021 06:51:13] "GET /.vscode/ftp-sync.json HTTP/1.1" 404 2116
Not Found: /.vscode/sftp.json
[18/Jul/2021 06:51:13] "GET /.vscode/sftp.json HTTP/1.1" 404 2104
Not Found: /deployment-config.json
[18/Jul/2021 06:51:13] "GET /deployment-config.json HTTP/1.1" 404 2119
Not Found: /ftpsync.settings
[18/Jul/2021 06:51:13] "GET /ftpsync.settings HTTP/1.1" 404 2101
Not Found: /sftp-config.json
[18/Jul/2021 06:51:13] "GET /sftp-config.json HTTP/1.1" 404 2101

まとめ

  • NiktoはWebサーバーのスキャナー
  • 大量の多種多様な検査パターンのリクエストを投げて、意図しないファイルが公開されていないかを確認できる
  • 案外使ってみて楽だった

ドキュメントが公式で非常によくまとまっており、とても分かりやすかった。これを経たとして、Niktoマスターになったわけではないが、もう少し業務で扱えるようになりたいなぁ・・・