如何透過 SSH 隧道避免 MITM 攻擊?

如何透過 SSH 隧道避免 MITM 攻擊?

假設我在典型的家庭路由器內有一台電腦(但假設防火牆/連接埠轉送存取路由器不可用)。它的內部IP可以是192.168.1.81。該 LAN 上有一台 IP 為 192.168.1.85 的攻擊者電腦想要對 192.168.1.81 進行典型的 ARP 欺騙 MITM 攻擊(假設他想要運行 urlsnarf 之類的東西來嗅探訪問的網站)。 192.168.1.81 機器希望防止任何形式的 MITM 攻擊並在 Chrome 上瀏覽網路時保持安全。他有一個具有 SSH 存取權限的伺服器,他想用它來加密他的 Web 瀏覽,這樣攻擊者就無法透過 MITM 攻擊來嗅探它。我(希望使用 SSH 隧道來確保安全的用戶)如何在我的伺服器(公共 IP 162.xx.xxx.xx)上使用 SSH 隧道來防止潛在的 MITM 攻擊?這是一個科學博覽會專案。我必須在我的伺服器上進行哪些(如果有)設定(我有完全的 root 存取權限)?我的SSH埠與正常埠不同,所以請以SSH埠25512作為參考。我還在伺服器的防火牆上打開了4567端口,所以也請使用該端口作為參考。請使用 72.xxx.xx.xxx 作為家庭網路的公共 IP。請包含任何必要的命令。如果我需要更清楚,請告訴我。非常感謝任何可以提供幫助的人!

答案1

最簡單的方法是在遠端伺服器上執行代理程式(fe squid)並使其僅在本機介面上偵聽127.0.0.1(因為您不想開啟網際網路代理程式)。

然後,您透過 ssh 進入遠端伺服器並建立到遠端伺服器上的本機代理介面的 tcp 轉送。

例如,假設遠端伺服器上的代理162.xx.xx.xx正在偵聽 tcp 127.0.0.1:3128。現在您可以使用以下命令透過 ssh 連接到它:

ssh -p 25512 -L 3128:127.0.0.1:3128 -C 162.xx.xx.xx

127.0.0.1:3128這將打開從您的客戶端到遠端主機的隧道127.0.0.1:3128。然後,您可以簡單地將用戶端上的瀏覽器設定為使用代理127.0.0.1:3128,然後透過 ssh 隧道連接到遠端主機並傳遞到那裡的代理。

-C參數啟用壓縮,並且有望使您的瀏覽速度更快一些,因為需要傳輸的資料更少。

這些是以下的相關部分man 1 ssh

 -L [bind_address:]port:host:hostport
         Specifies that the given port on the local (client) host is to be forwarded to 
         the given host and port on the remote side.  This works by allocating a socket 
         to listen to port on the local side, optionally bound to the specified 
         bind_address.  Whenever a connection is made to this port, the connection is 
         forwarded over the secure channel, and a connection is made to host port 
         hostport from the remote machine.  Port forwardings can also be specified in 
         the configuration file.  IPv6 addresses can be specified by enclosing the 
         address in square brackets.  Only the superuser can forward privileged ports. 
         By default, the local port is bound in accordance with the GatewayPorts 
         setting.  However, an explicit bind_address may be used to bind the connection 
         to a specific address.  The bind_address of “localhost” indicates that the 
         listening port be bound for local use only, while an empty address or ‘*’ 
         indicates that the port should be available from all interfaces.

 -C      Requests compression of all data (including stdin, stdout, stderr, and data for
         forwarded X11 and TCP connections).  The compression algorithm is the same used
         by gzip(1), and the “level” can be controlled by the CompressionLevel option 
         for protocol version 1.  Compression is desirable on modem lines and other slow 
         connections, but will only slow down things on fast networks.  The default 
         value can be set on a host-by-host basis in the configuration files; see the 
         Compression option.

 -p port
         Port to connect to on the remote host.  This can be specified on a per-host 
         basis in the configuration file.

相關內容