一代 我最近設置了一個運行 Debian 9 的小型服務器。這台機器的目的是在端口 443 上運行 OpenVPN 服務器以繞過審查。僅運行以下服務:
- 私有 IP squid 屬於 VPN 池 (10.8.0.1:3128)
- 私有 IP 上的 SSH 屬於 VPN 池 (10.8.0.1:22)
- 私有 IP 的 DNS 解析器屬於 VPN 池 (10.8.0.1:53)
- 公共 IP 端口 443 上的 OpeneVPN (server_public_ip_address:443)
設置完所有內容後,我決定運行 Nmap 來掃描服務器。令我驚訝的是,我發現 80 端口是開放的。{macbookpro}$ sudo nmap ln.vpngatway
示例輸出:
Starting Nmap 7.50 ( https://nmap.org ) at 2017-07-03 00:24 IST
Nmap scan report for ln.vpngatway (xxx.yyy.zzz.123)
Host is up (0.20s latency).
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
443/tcp closed https
Nmap done: 1 IP address (1 host up) scanned in 19.87 second
我還通過運行以下 nc 命令驗證了端口 80 沒有響應(但它確實響應了):{macbookpro}$ nc -zv ln.vpngatway 80
示例輸出:
found 0 associations found 1 connections: 1: flags=82 outif en6 src 192.168.2.5 port 51462 dst xxx.yyy.zzz.123 port 80 rank info not available TCP aux info available Connection to ln.vpngatway port 80 [tcp/http] succeeded!
nmap 顯示端口已打開,而 netstat 顯示服務器本身的端口 80 上沒有運行任何內容。{ln.vpngatway}$ netstat -tulpn | grep :80
我一無所有。所以我運行了以下內容:{ln.vpngatway}$ ps aux | egrep -i 'httpd|nginx|apache|lighttpd'
示例輸出:
root 4257 0.0 0.0 12784 992 pts/0 S+ 19:06 0:00 grep -E -i httpd|nginx|apache|lighttpd
我對 nmap 輸出感到困惑。我仔細檢查了一切。結果相同。 為什麼端口 80 (HTTP) 被 nmap 報告為打開?我決定在開始使用 tcpdump 之前運行一個舊的 telnet/nc 會話。{macbookpro}$ nc ln.vpngatway 80
請求/文件:
GET / HTTP/1.1 host: ln.vpngatway
一段時間後,您應該會在屏幕上看到類似這樣的內容:
HTTP/1.1 503 Service Unavailable Server: squid Mime-Version: 1.0 Date: Sun, 02 Jul 2017 19:16:52 GMT Content-Type: text/html;charset=utf-8 Content-Length: 3406 X-Squid-Error: ERR_CONNECT_FAIL 60 Vary: Accept-Language Content-Language: en X-Cache: MISS from localhost X-Cache-Lookup: MISS from localhost:3128 Connection: keep-alive <html><head> <meta type="copyright" content="Copyright (C) 1996-2017 The Squid Software Foundation and contributors"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>ERROR: The requested URL could not be retrieved</title> <style type="text/css"><!-- .... ...... .. <script language="javascript"> if ('[unknown method]' != '[unknown method]') document.getElementById('missing-method').style.display = 'none'; if ('error:invalid-request' != '[no URL]') document.getElementById('missing-url').style.display = 'none'; if ('[unknown protocol]' != '[unknown protocol]') document.getElementById('missing-protocol').style.display = 'none'; </script> <hr> <div id="footer"> <p>Generated Sun, 02 Jul 2017 19:16:52 GMT by localhost (squid)</p> <!-- ERR_INVALID_REQ --> </div> </body></html>
謎團已揭開。 我找到了攔截緩存/透明代理。攔截緩存只不過是將 HTTP 連接從遠程客戶端重定向到緩存服務器的過程。在這種情況下,默認情況下,所有 HTTP 連接都使用防火牆和 squid 服務器的組合重定向到代理服務器。