6

I have an Apache webserver running on a local machine through reverse ssh tunnel, i.e.:

ssh -R *:80:local_machine:8080 username@gateway_machine

In other words, all traffic from port 80 on gateway_machine is sent to port 8080 on local_machine.

For monitoring purposes, I wish to know IP addresses of the remote clients connected to gateway_machine. However my local Apache server sees all traffic coming from the IP address of gateway_machine.

My question: Is there any way to setup ssh server running on gateway_machine such that it sends all traffic to local_machine with actual remote IP addresses ?

4

1 回答 1

2

SSH 协议使用一种称为“direct-tcpip”的通道类型来转发 TCP 连接。打开这些通道之一的协议消息包括正在转发连接的客户端的地址和端口。因此,您想要的信息可用于 ssh 客户端(在您的情况下,它正在打开与转发目标的连接)。

OpenSSHssh客户端将创建者地址和端口记录在调试级别消息中,因此如果您使用以下-v选项运行 ssh,您可以看到它:

$ ssh -v -R 2000:localhost:1000 localhost
...
debug1: client_request_forwarded_tcpip: listen localhost port 2000, originator ::1 port 51101

这里的发起者地址是 ::1 (IPv6 localhost) 和端口 51101。该ssh实用程序不会对这些信息做任何其他事情。

因此,根据您的需要,您可以通过三种方法来收集此信息:

  1. 使用选项调用ssh创建这些转发的进程-v,并安排收集和解析相关的调试信息。
  2. 更改源代码ssh使其按照您希望它对信息执行的操作。
  3. 编写您自己的 ssh 客户端,它可以满足您的需求。SSH 客户端库可用于大多数现代编程语言。
于 2017-12-02T14:47:17.770 回答