Random local port - WeOnlyDo Discussion board

Random local port (General questions)

by Chad Amberg, Thursday, October 07, 2004, 00:58 (7151 days ago)

While defining tunnels, is it possible to not choose a local port, and have the wodtunnel randomly pick an unused port to bind to?

Re: Random local port

by wodSupport, Thursday, October 07, 2004, 01:06 (7151 days ago) @ Chad Amberg

Chad,

this already works. Set LocalPort to 0, and then in ChannelStart read it's value to see what port we assigned.

Regards.

Re: Random local port

by Chad Amberg, Thursday, October 07, 2004, 13:29 (7151 days ago) @ wodSupport

Chad,

this already works. Set LocalPort to 0, and then in ChannelStart read it's value to see what port we assigned.

Regards.

Sweet! This makes things a lot easier on my side!

Re: Random local port

by Chad Amberg, Saturday, August 26, 2006, 03:53 (6463 days ago) @ Chad Amberg

Chad,

this already works. Set LocalPort to 0, and then in ChannelStart read it's value to see what port we assigned.

Regards.

Sweet! This makes things a lot easier on my side!

Re: Random local port

by Chad Amberg, Saturday, August 26, 2006, 03:55 (6463 days ago) @ Chad Amberg

I'm starting a RemoteListen tunnel. And I need it to pick a random port on the remote side. Is there any way to tell what that remote port is chosen after the channel is connected? Essentially I'm adding the channel using a 0 for the RemotePort, but afterwards I need to know what port it is.

Re: Random local port

by woddrazen, Saturday, August 26, 2006, 10:08 (6463 days ago) @ Chad Amberg

Hi Chad,


Here is example which will show you what channel is started after you make RemoteListen Connection:

-------------------------
Dim i As Integer

For i = 0 To SSH_1.Channels.Count - 1
Debug.Print SSH_1.Channels(i).RemotePort & = & SSH_1.Channels(i).Activated
Next i
-------------------------

Hope I helped.


Regards,
Drazen

Re: Random local port

by Chad Amberg, Saturday, August 26, 2006, 15:57 (6462 days ago) @ woddrazen

Hi Chad,


Here is example which will show you what channel is started after you make RemoteListen Connection:

-------------------------
Dim i As Integer

For i = 0 To SSH_1.Channels.Count - 1
Debug.Print SSH_1.Channels(i).RemotePort & = & SSH_1.Channels(i).Activated
Next i
-------------------------

Hope I helped.


Regards,
Drazen

Hi Drazen-
If I open up a connection saying that the remote port is 0, because we can't know what port is available ahead of time, your debug output above always shows port 0.

However, the server does open up a random port correctly.

Looking at http://www.ietf.org/rfc/rfc4254.txt for the SSH_MSG_CHANNEL_OPEN_CONFIRMATION message, it does seem that when the server replies, that it includes both sides of the channel information. Of course, I've never debugged what the actual SSH conversation looks like, but I'm hoping that you can tell me that after a tunnel is opened, that the server does respond with the port information, and that this can be added to wodtunnel hopefully?

Thanks,
Chad


Re: Random local port

by Chad Amberg, Saturday, August 26, 2006, 16:28 (6462 days ago) @ Chad Amberg

Whups, wrong message. Looking at the right section of the RFC, part 7.1:

If a client passes 0 as port number to bind and has 'want reply' as
TRUE, then the server allocates the next available unprivileged port
number and replies with the following message; otherwise, there is no
response-specific data.

byte SSH_MSG_REQUEST_SUCCESS
uint32 port that was bound on the server

Re: Random local port

by wodSupport, Sunday, August 27, 2006, 09:52 (6462 days ago) @ Chad Amberg

Chad,

I have double checked - we do accept SSH_MSG_REQUEST_SUCCESS and read it's value, and is stored to RemotePort property.

Kreso

Re: Random local port

by Chad Amberg, Sunday, August 27, 2006, 16:43 (6461 days ago) @ wodSupport

Chad,

I have double checked - we do accept SSH_MSG_REQUEST_SUCCESS and read it's value, and is stored to RemotePort property.

Kreso

Hi Kreso-
Strange, I read the remote port continuously and only ever see a remote port of 0.
Could this be because the SSH server is reporting back a 0? I can go bug WinSSHD also on this...

Re: Random local port

by wodSupport, Sunday, August 27, 2006, 23:08 (6461 days ago) @ Chad Amberg

Chad,

it is very possible that server implementations don't work as that specification. Most of them were made on older draft which did not send port value with SSH_MSG_REQUEST_SUCCESS message.

I'll change wodSSHServer and freeSSHd now, can't say for others. wodSSHTunnel *IS* ready for this and should work as is.

Kreso

Re: Random local port

by wodSupport, Sunday, August 27, 2006, 23:32 (6461 days ago) @ wodSupport

Actually I was wrong. There was a bug in wodSSHTunnel. It's not fixed. Grab newest version and try it out.

Kreso

Re: Random local port

by Chad Amberg, Monday, August 28, 2006, 00:30 (6461 days ago) @ wodSupport

Actually I was wrong. There was a bug in wodSSHTunnel. It's not fixed. Grab newest version and try it out.

Kreso

Just tried build 1.52.49 and I still get the same results.

I'm just doing a real simple function to check:

Private Sub ssh1_ChannelStart(ByVal Chan As wodSSHTunnelServLib.Channel) Handles ssh1.ChannelStart
Dim chanInfo As String =
chanInfo = Secure Channel Opened
chanInfo = chanInfo & vbCrLf & Channel: & Chan.Name
chanInfo = chanInfo & vbCrLf & Local Address: & Chan.LocalAddress
chanInfo = chanInfo & vbCrLf & Local Port: & Chan.LocalPort
chanInfo = chanInfo & vbCrLf & Remote Address: & Chan.RemoteAddress
chanInfo = chanInfo & vbCrLf & Remote Port: & Chan.RemotePort
writeToLog(EventLogEntryType.Information, chanInfo, 2)
end sub

So this should show up as soon as the channelstart event, correct?

Re: Random local port

by wodSupport, Monday, August 28, 2006, 00:33 (6461 days ago) @ Chad Amberg

Yes, on channel start. What server do you use? I tested with wodSSHServer which I *know* it works (because I just made it by the specs...)

Kreso

Re: Random local port

by Chad Amberg, Monday, August 28, 2006, 01:28 (6461 days ago) @ wodSupport

Latest greatest version of WinSSHD. I've sent Bitvise an email to make sure they're up to spec to but haven't heard a response back yet.

Does the current build of freesshd available work?

Re: Random local port

by wodSupport, Monday, August 28, 2006, 01:31 (6461 days ago) @ Chad Amberg

Chad,

don't know about freeSSHd, you have to post question there.

Kreso

Re: Random local port

by Chad Amberg, Saturday, September 02, 2006, 22:11 (6455 days ago) @ wodSupport

Just an FYI to all...
The ssh server from VanDyke software called VShell does support this and it works really well.