Nmap を使ってサーバをスキャンする
いきさつ
サーバのセキュリティを高めるために、 外側からサーバの確認をしたかったので、Nmap を使ってみた。
※Nmap はネットワークに負荷がかかる可能性があるため、 使用する場合は対抗機器に負荷がかからないように配慮する必要がある。 各種クラウドサービスなどを対象とする場合は、事前に申請が必要な場合もある。
install
Ubuntu
CentOS
ポートスキャン
ホスト host.example.net
の開いているポートを確認する。
すると、以下のような出力がでる。 xx.xx.xx.xx
にはホストのIPアドレスが入る。 ssh用の22番ポートだけが開いているのが確認できる。 オプション -A
をつけることでOSの種類も検出してくれる。
Starting Nmap 7.60 ( https://nmap.org ) at 2019-12-07 12:10 JST
Nmap scan report for host.example.net (xx.xx.xx.xx)
Host is up (0.0011s latency).
Not shown: 65530 filtered ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4 (protocol 2.0)
| ssh-hostkey: 1024 82:b3:54:d2:5a:e3:93:22:ea:95:5a:a5:6b:a3:ff:44 (DSA)
|_2048 8b:8a:e7:28:f3:50:ec:84:6d:fe:b3:fe:16:ec:9d:96 (RSA)
Service Info: OS: Linux; CPE: cpe:/o:linux:kernel
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 50.23 seconds
特定サブネット内の機器の探索
「サブネット 192.168.1.0/24
で稼働しているネットワーク機器をざっと調べたい」 という時は↓のようにする。
とすると、以下の様に4つの機器が見つかった。
Starting Nmap 6.00 ( http://nmap.org ) at 2013-11-12 21:53 JST
Nmap scan report for 192.168.1.x
Host is up (0.00042s latency).
Nmap scan report for 192.168.1.y
Host is up (0.0023s latency).
Nmap scan report for 192.168.1.z
Host is up (0.0018s latency).
Nmap scan report for 192.168.1.w
Host is up (0.00052s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 3.43 seconds
SMTP サーバがオープン・リレーとして稼働しているかどうかを確認する
SMTPサーバが無条件でメールを転送するような設定になっているかどうかを確認する。 そのような設定になっている場合、踏み台として利用される可能性がある。
↓のように “Server doesn’t seem to be an open relay” という表示がされれば、 ひとまずは問題ないはず。
$ nmap --script smtp-open-relay.nse -A hoge.example.net
Starting Nmap 7.40 ( https://nmap.org ) at 2017-01-27 13:28 JST
Nmap scan report for hoge.example.net (xx.xx.xx.xx)
Host is up (0.0038s latency).
Not shown: 990 filtered ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
25/tcp open smtp Postfix smtpd
|_smtp-open-relay: Server doesn't seem to be an open relay, all tests failed
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
110/tcp closed pop3
143/tcp closed imap
443/tcp closed https
465/tcp open ssl/smtp Postfix smtpd
|_smtp-open-relay: Server doesn't seem to be an open relay, all tests failed
587/tcp open smtp Postfix smtpd
|_smtp-open-relay: Server isn't an open relay, authentication needed
993/tcp open ssl/imap Dovecot imapd
995/tcp closed pop3s
Service Info: Host: hoge.example.net; 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 44.23 seconds