Ssh – How to view traffic over a forwarded ssh port

ssh

It is possible to setup an SSH port forward where the ssh client prints out the traffic exchanged over the ssh port to the screen or a file.

I am trying to debug a problem and want to see what is being sent between a java process running on my local machine and a remote process running on Solaris. I am using the port forwarding via ssh so that i can step through the java program. Normally I would have to copy
the .java files to the Solaris machine, build them and run and it is not very productive way to debug, thus the port forwarding. The client and server as using IIOP protocol so I can't use an http proxy to monitor the traffic.

Best Answer

I would cheat and put a couple of netcat's and a tee in the pipeline:

nc -k -l -p $localport -c "tee file.out | nc 127.0.0.1 $portforwardport"

where $localport is an arbitrary port to point your java process at and $portforwardport is your ssh port forward port number. The -k makes the listening netcat stay listening rather than exiting after the first time a client disconnects. The output will end up in file.out on your localhost.

Related Question