PowerShell und SSH Portweiterleitung

PowerShell und SSH Portweiterleitung

avatar
kar
Disabled

Guten Tag,

Ich habe eine SSH Portweiterleitung eingerichtet und würde das Lokale Portmapping gerne über Powershell verwalten. Wenn ich z.B. per Powershell einen neuen RDP Eintrag erstelle, würde ich gerne das passende Portmapping in der SSH Portweiterleitung hinterlegen. Ist sowas möglich? Und wenn ja wie?

vielen Dank im Vorraus

All Comments (7)

avatar

Hallo Karim,

ich bin mir gerade nicht sicher was du genau erreichen willst; wenn es um die Einstellungen der SSH Portweiterleitung geht kannst du diese auch per Powershell ändern. Eine direkte Automatisierung die deine Daten in der Sitzung einträgt nachdem du per Powershell eine RDP Sitzung erstellst gibt es allerdings nicht.

Mit freundlichen Grüßen,
Etienne.

avatar

Hallo Etienne,

vielen Dank für die Antwort.
Mein Ziel ist es mit einem Powershell Skript neue RDP Hosts zu importieren, und diese die SSH Portweiterleitung nutzen zu lassen. Dafür müsste ich aber für jeden neuen Host einen Eintrag in der SSH Portweiterleitung. Mit welchem Powershell Befehl komme ich an die Liste um eine Weiterleitung hinzu zufügen?

Mit freundlichen Grüßen

Karim

avatar

Hello,

Sorry to jump in this conversation and writing in English.

To provide you the right information on how to configure SSH Port Forwarding using the RDM PowerShell cmdlets and properties, I want to know how you configure it in RDM. Could you please post some screen shots of the properties you want to manage through your PowerShell script?

You can reply in German, I will use Google Translator to translate your answers.


Best regards,

Érica Poirier

avatar

Hello,

Thank you for your respodes. I's tolley fine for me to write in english.
What i want to do is, for each RDP session that is added to an RDM folder, set an entry in the list. for example the host 12.12.12.2 should be added, then the SSH list should get the entry 127.0.0.1:30002 -> 12.12.12.2 and the RDP session should connect via 127.0.0.1:30002. the perpose of this is an aws ec2 environment which can only be reached via an ssh server and all servers should be added automatically if possible. If there is an more comfortable way to do that i'm open to that.
Thank you and best regards
Karim

Portforwarding.JPG

avatar

Hello,

Thank you for the information.

The reason why I have asked that question is because if you plan to add more that 20 entries in the SSH list, on opening an RDP entry that refers to the SSH Port Forwarding entry, it will open all ports at the same time and this could cause some performance issues on your local machine.

There is another solution to prevent having performance problems when there is more than 20 entries.

So, how many entries will be listed in the SSH Port Forward entry?


Best regards,

Érica Poirier

avatar

Hello,

Thank you.

unfortunately there will be more than 20.
how is does the other solution?

Best regards,

Karim

avatar

Hello,

Sorry for the late reply but here is the instructions and PowerShell script sample to create your entries.

First of all, instead of creating a list of SSH Entries in the SSH Port Forwarding entry, it is recommended to just create one dynamic SSH entry like the following screen shot.

1- IP address of the SSH Gateway Server
2- Port number of the SSH Gateway Server



Then, create the Dynamic link that will be used by every Proxy Tunnel. The Source must be 127.0.0.1 and the Mode must be Dynamic. The Source Port must be the same as the one configured in each Proxy Tunnel entry.




Here is the PowerShell script to create this entry.

# Create the SSH Port Forward entry type with Dynamic port
$sshPortForward = New-RDMSession -Name "PortForward" -Type PortForward -Group "RDP Over SSH Proxy"
$sshPortForward.Terminal.Host = "192.168.8.25"
$sshPortForward.Terminal.HostPort = "60025"
$sshPortForward.Terminal.Username = "useraccount"
$sshPortForward.Terminal.PrivateKeyPromptForPassPhrase = $false
$sshPortForward.Terminal.TCPKeepaliveInterval = 1
$sshPortForward.Terminal.Verbose = $true
$sshPortForward.Terminal.VerbosityLevelMac = 2
$newPortForward = New-Object Devolutions.RemoteDesktopManager.Business.PortForward
$newPortForward.Mode = "Dynamic"
$newPortForward.Source = "127.0.0.1"
$newPortForward.SourcePort = 60000
$sshPortForward.Terminal.PortForwards = $newPortForward
Set-RDMSession $sshPortForward -Refresh
$pwdSSHPF = ConvertTo-SecureString "123456" -AsPlainText -Force
Set-RDMSessionPassword -Session $sshPortForward -Password $pwdSSHPF
Set-RDMSession $sshPortForward -Refresh
Next, you need to create one Proxy Tunnel per RDP entry and bind the RDP entry to the Proxy Tunnel using the VPN settings.

3- Same port number of the SSH Port Forward entry.
4- Port number used by the RDP entry. This port number should be unique for every Proxy Tunnel/RDP entry group.
5- IP address of the RDP machine.



And create the RDP with the following properties.

7- Port number configured in the Proxy Tunnel in step 4.
8- Set VPN Open parameter to Always connect.
9- Set the Type parameter to Proxy Tunnel.
10- Select the Proxy Tunnel in the Session parameter.








Here is the PowerShell code to create the Proxy Tunnel / RDP duo entries. You would need to put this in a loop to create them from your CSV file that contains all your RDP entries.


# For each RDP entry, you need to create a Proxy Tunnel and a RDP entry bind to that Proxy Tunnel entry
# Create the Proxy Tunnel entry type
$proxyTunnel = New-RDMSession -Name "Proxy Tunnel" -Type ProxyTunnel -Group "RDP Over SSH Proxy"
$proxyTunnel.ProxyTunnel.Host = "10.10.0.25"
$proxyTunnel.ProxyTunnel.LocalHost = "127.0.0.1"
$proxyTunnel.ProxyTunnel.LocalPort = "61125"
$proxyTunnel.ProxyTunnel.Port = "3389"
$proxyTunnel.ProxyTunnel.ProxyHost = "127.0.0.1"
$proxyTunnel.ProxyTunnel.ProxyPort = "60000"
$proxyTunnel.ProxyTunnel.ProxyType = "Socks4"
$proxyTunnel.ProxyTunnel.Username = "useraccount"
Set-RDMSession $proxyTunnel -Refresh
$pwdProxy = ConvertTo-SecureString "123456" -AsPlainText -Force
Set-RDMSessionPassword -Session $proxyTunnel -Password $pwdProxy
Set-RDMSession $proxyTunnel -Refresh

# Create the RDP entry bind to the Proxy Tunnel
$rdp = New-RDMSession -Name "RDP Through Proxy" -Type RDPConfigured -Group "RDP Over SSH Proxy"
$rdp.RDP.NetworkLevelAuthentication = $true
$rdp.RDP.Username = "useraccount"
$rdp.VPN.Enabled = $true
$rdp.VPN.Application = "ExistingProxyTunnel"
$rdp.VPN.AutoClose = $false
$rdp.VPN.CloseMode = "Manually"
$rdp.VPN.ExistingSessionID = $proxyTunnel.ID
$rdp.VPN.Mode = "AlwaysConnect"
$rdp.Host = "127.0.0.1"
$rdp.HostPort = "61125"
Set-RDMSession $rdp -Refresh
$pwdRdp = ConvertTo-SecureString "123456" -AsPlainText -Force
Set-RDMSessionPassword -Session $rdp -Password $pwdRdp
Set-RDMSession $rdp -Refresh
I know that it's a very long post but these are all the instructions you need to achieve your goal. I would recommend you to try to configure this set of entries to test this in your environment before running the whole PowerShell script. In order to work, you need to first open the SSH Port Forward entry, then open the RDP entry.

Best regards,

Érica Poirier