
我最近安裝了兩台 Ubuntu Server 機器,我想找到機器中開放的連接埠。
當我nmap
從我的機器(Ubuntu 11.10)運行時,我觀察到兩台伺服器都有
135/tcp filtered msrpc
4444/tcp filtered krb524
4662/tcp filtered edonkey
5000/tcp filtered upnp
5631/tcp filtered pcanywheredata
我從來沒有打開過這些連接埠。我只安裝了 LAMP 和 SAMBA。為什麼這些連接埠開放?
開放連接埠的完整列表是:
22/tcp open ssh
25/tcp open smtp
53/tcp open domain
80/tcp open http
110/tcp open pop3
135/tcp filtered msrpc
139/tcp open netbios-ssn
143/tcp open imap
445/tcp open microsoft-ds
993/tcp open imaps
995/tcp open pop3s
4444/tcp filtered krb524
4662/tcp filtered edonkey
5000/tcp filtered upnp
5631/tcp filtered pcanywheredata
問題是為什麼這些連接埠打開:135/tcp filtered msrpc
, 4444/tcp filtered krb524
, 4662/tcp filtered edonkey
。5000/tcp filtered upnp
, 5631/tcp filtered pcanywheredata
.我從來沒有打開過這些連接埠。我只安裝了 LAMP 和 SAMBA。
該清單看起來安全嗎?
答案1
您可以從名為 /etc/services 的檔案中取得連接埠列表
cat /etc/services | grep 137 (example)
例子
Samba 需要開啟哪些連接埠才能進行通信
netbios-ns - 137 # NETBIOS Name Service
netbios-dgm - 138 # NETBIOS Datagram Service
netbios-ssn - 139 # NETBIOS session service
microsoft-ds - 445 # if you are using Active Directory
運行這個命令
netstat -anltp | grep "LISTEN"
執行 FTP、SSH 和 MySQL 的典型 Web 伺服器將具有以下輸出:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 21432/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4090/apache2
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7213/sshd
tcp6 0 0 :::21 :::* LISTEN 19023/proftpd
tcp6 0 0 :::22 :::* LISTEN 7234/sshd
答案2
你的問題很廣泛,「安全」是相對的。
當您安裝伺服器並開啟連接埠時,總是會存在潛在的漏洞。
當您安裝伺服器(ssh、samba)並啟動伺服器(它們通常在您啟動時預設為啟動)時,您將開啟一個連接埠。
您可以對每台伺服器(ssh、samba、http)進行設定變更以提高安全性。
對於 ssh,這可能包括使用金鑰(並停用密碼)、tcpwrapper、防火牆等。
使用防火牆時有 3 個主要策略
1) 允許所有和黑名單不良行為IP。 http 就是一個例子。一般來說,您將 http 作為公共伺服器運行,允許所有 IP,並將那些向您的伺服器發送垃圾郵件的人列入黑名單。
2) 拒絕全部並允許白名單。 ssh 就是一個例子。
3)限制。有時您會限制連線速率或 # pings/秒。
希望能讓您開始,您可能想看看
https://help.ubuntu.com/11.10/serverguide/C/index.html
https://help.ubuntu.com/community/Security
或詢問有關特定伺服器的特定問題。
答案3
「已過濾」不一定等同於目標主機上的開放埠。
事實上,這可能毫無意義。
例如,如果您運行的位置和目標之間存在防火牆nmap
,並且該防火牆正在主動過濾連接埠 5000,則 5000 將在您的清單中顯示為“已過濾”,而目標主機不會看到任何流量到該連接埠- 因此該連接埠是否在目標上開啟變得完全無關。
要獲得伺服器上開放連接埠的明確列表,請嘗試:
sudo netstat -lnp --tcp --udp
-l : only show listening ports
-n : don't bother looking up DNS hostnames
-p : show which processes have the port open
--tcp : show tcp ports
--udp : show udp ports
您可以省略--tcp
,--udp
但隨後您將獲得大量不相關的本機檔案系統套接字訊息,這些資訊無法透過網路存取。
sudo
是-p
正常工作所必需的,否則它只會列印-
不屬於您的用戶的任何進程。
答案4
由於netstat
預設不再安裝,與 相反lsof
,我想我可以添加一個開箱即用的選項:
sudo lsof -nP -iTCP -sTCP:LISTEN