スクリプトスキャンとターゲットサービス分析
このステップでは、Nmap の強力なスクリプトエンジン (NSE) について学び、ターゲットサービス分析を実行する方法を学びます。NSE スクリプトは、特定のサービスと脆弱性に対するより詳細なスキャンを可能にすることで、Nmap の機能を拡張します。
Nmap Scripting Engine (NSE) の紹介
Nmap Scripting Engine を使用すると、ユーザーはさまざまなネットワークタスクを自動化するためのスクリプトを記述して共有できます。Nmap には、さまざまなグループに分類された数百の事前記述スクリプトが付属しています。
auth: 認証関連のスクリプト
default: -sC でデフォルトで実行されるスクリプト
discovery: ホストとサービスの検出
exploit: 脆弱性の悪用を試みる
malware: マルウェアとバックドアを検出
safe: 安全で非侵入型のスクリプト
vuln: 脆弱性検出スクリプト
デフォルトスクリプトの実行 (-sC)
-sC フラグは、一般的に安全で有用な情報を提供するデフォルトのスクリプトセットを実行します。
nmap -sC localhost
出力:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:10 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
| ssh-hostkey:
| 3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
| 256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_ 256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp open http
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp open ipp
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open mysql
|_mysql-info: ERROR: Script execution failed (use -d to debug)
Nmap done: 1 IP address (1 host up) scanned in 3.42 seconds
スクリプトが、SSH ホストキーや HTTP ページタイトルなど、各サービスに関する追加情報を提供していることに注目してください。
特定のスクリプトの実行
--script フラグの後にスクリプト名またはカテゴリを指定して、特定のスクリプトを実行できます。
nmap --script=http-title localhost
これは、HTTP ページのタイトルを取得する http-title スクリプトのみを実行します。
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:15 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp open ipp
|_http-title: Home - CUPS 2.3.1
3306/tcp open mysql
Nmap done: 1 IP address (1 host up) scanned in 0.68 seconds
カテゴリ別のスクリプトの実行
特定のカテゴリのすべてのスクリプトを実行できます。
nmap --script=discovery localhost
これは、すべての検出スクリプトを実行します。これにより、ネットワークサービスに関する豊富な情報が得られます(出力を簡潔にするために切り捨てています)。
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:20 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
| ssh-hostkey:
| 3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
| 256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_ 256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp open http
|_http-favicon: Unknown favicon MD5: 6D33949773573A11BEBE0D20AC1B7967
| http-methods:
|_ Supported Methods: GET POST OPTIONS HEAD
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp open ipp
| cups-info:
| CUPS Server:
| Server: CUPS/2.3 IPP/2.1
|_ Authentication-Method: Basic
| http-methods:
|_ Supported Methods: GET HEAD OPTIONS POST
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open mysql
| mysql-info:
| Protocol: 10
| Version: 8.0.30-0ubuntu0.20.04.2
| Thread ID: 15
| Capabilities flags: 65535
| Some Capabilities: ConnectWithDatabase, SupportsLoadDataLocal, SupportsTransactions, DontAllowDatabaseTableColumn, Support41Auth, InteractiveClient, Speaks41ProtocolOld, FoundRows, IgnoreSigpipes, ODBCClient, SwitchToSSLAfterHandshake, IgnoreSpaceBeforeParenthesis, LongColumnFlag, Speaks41ProtocolNew, SupportsMultipleStatments, LongPassword, SupportsCompression, SupportsMultipleResults, SupportsAuthPlugins
| Status: Autocommit
| Salt: \x7FeL)\x0C\x5C#S\x06N%\x1E\x7EYaC
|_ Auth Plugin Name: caching_sha2_password
Nmap done: 1 IP address (1 host up) scanned in 5.28 seconds
スクリプトスキャンとサービス検出の組み合わせ
最も包括的な結果を得るには、スクリプトスキャンとサービス検出を組み合わせます。
nmap -sV -sC localhost
出力:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:25 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
| 256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_ 256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp open ipp CUPS 2.3
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open mysql MySQL 8.0.30-0ubuntu0.20.04.2
|_mysql-info: ERROR: Script execution failed (use -d to debug)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds
ターゲットサービス分析
特定のサービスをより詳細に分析することに焦点を当てましょう。
HTTP サービスの分析
HTTP サービスを詳細に分析するには、http-* スクリプトを使用できます。
nmap --script="http-*" -p 80 localhost
これは、ポート 80 に対してすべての HTTP 関連スクリプトを実行します。
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:30 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
PORT STATE SERVICE
80/tcp open http
|_http-chrono: Request times for /; avg: 32.68ms; min: 32.68ms; max: 32.68ms
|_http-comments-displayer: Couldn't find any comments.
|_http-date: Thu, 14 Sep 2023 17:30:24 GMT; +6s from local time.
|_http-devframework: Couldn't determine the underlying framework or CMS. Try increasing 'httpspider.maxpagecount' value to spider more pages.
|_http-dombased-xss: Couldn't find any DOM based XSS.
|_http-favicon: Unknown favicon MD5: 6D33949773573A11BEBE0D20AC1B7967
|_http-feed: Couldn't find any feeds.
|_http-fetch: Please enter the complete path of the directory to save data in.
|_http-generator: Couldn't find any generator in the HTML headers and body
| http-methods:
|_ Supported Methods: GET POST OPTIONS HEAD
|_http-mobileversion-checker: No mobile version detected.
|_http-referer-checker: Couldn't find any cross-domain scripts.
|_http-security-headers:
| http-server-header:
| Apache/2.4.41
|_ Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-traceroute: ERROR: Script execution failed (use -d to debug)
|_http-useragent-tester:
|_http-xssed: No previously reported XSS vuln.
Nmap done: 1 IP address (1 host up) scanned in 2.31 seconds
SSH サービスの分析
同様に、SSH サービスを分析できます。
nmap --script="ssh-*" -p 22 localhost
出力:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:35 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
PORT STATE SERVICE
22/tcp open ssh
| ssh-hostkey:
| 3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
| 256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_ 256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
|_ssh-run: ERROR: Script execution failed (use -d to debug)
Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds
脆弱性スキャン
Nmap には、潜在的な脆弱性を検出できるスクリプトが含まれています。vuln カテゴリを使用すると、セキュリティの問題を特定するのに役立ちます。
nmap --script=vuln localhost
これは、さまざまな脆弱性チェックを実行するため、ある程度の時間がかかる場合があります。出力は次のようになります。
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:40 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
|_http-csrf: Couldn't find any CSRF vulnerabilities.
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-slowloris-check:
| VULNERABLE:
| Slowloris DOS attack
| State: LIKELY VULNERABLE
| IDs: CVE:CVE-2007-6750
| Slowloris tries to keep many connections to the target web server open and hold
| them open as long as possible. It accomplishes this by opening connections to
| the target web server and sending a partial request. By doing so, it starves
| the http server's resources causing Denial Of Service.
|
| Disclosure date: 2009-09-17
| References:
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_ http://ha.ckers.org/slowloris/
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
631/tcp open ipp
3306/tcp open mysql
Nmap done: 1 IP address (1 host up) scanned in 87.28 seconds
この場合、Nmap は、Apache Web サーバーが Slowloris DoS 攻撃に対して脆弱である可能性があることを特定しました。この情報は、システムのセキュリティを確保するのに役立ちます。
包括的なスキャンレポートの作成
次に、これまで学習したすべてを組み合わせて、包括的なセキュリティレポートを作成しましょう。
sudo nmap -sS -sV -O -sC --script=vuln -T4 -oA comprehensive_security_report localhost
このコマンドは、次のことを行います。
- SYN ステルススキャンを使用 (-sS)
- サービスバージョンを検出 (-sV)
- OS 検出を試行 (-O)
- デフォルトスクリプトを実行 (-sC)
- 脆弱性検出スクリプトを実行 (--script=vuln)
- アグレッシブなタイミングを使用 (-T4)
- 結果をすべての形式で保存 (-oA)
出力は包括的であり、完了までに時間がかかる場合があります。完了すると、セキュリティ分析のために参照できる、さまざまな形式(通常、XML、grep 可能)の詳細なセキュリティレポートが作成されます。
このステップでは、Nmap のスクリプトエンジンを使用して、サービスに関する詳細な情報を収集し、潜在的な脆弱性を検出する方法を学びました。これらの高度な手法は、包括的なネットワークセキュリティ評価に不可欠です。