Listen and forward a connection by changing the source port - socat and netcat

Assume you want to connect to port 22 on a machine numbered 10.0.0.12 and source port 53 will allow you through the firewall. We will setup to listen on port 2323. Here are two methods that you can try:

SOCAT
socat TCP4-LISTEN:2323,fork TCP-CONNECT:10.0.0.12:22,sp=53
ssh -p 2323 127.0.0.1
Listen on port 2323 and then connect to an IP address on port 22 and set the source port of 53 to the outgoing packet.


NETCAT (nc)
mkfifo myfifo
nc -p 53 10.0.0.12 22 < myfifo | nc -l -p 2323 > myfifo
ssh -p 2323 127.0.0.1
Second netcat is listening on port 2323 and then pushing the contents to the fifo. Once you connect the first netcat command is executed, which connects to the server on port 22 and sets the source port to 53. The contents are taken from the fifo (e.g., myfifo) push from the second command.

Update: Works in Kali 2