Port Redirection with powershell

Hello Experts,

I am trying to write a ps script that can redirect the incoming connections on a specific port from the internet to another spepcific port with an ip address. For Tcp connections I am using microsoft's netsh portproxy, but unfortunately portproxy doesn't supports the udp connections for that I am writing a script separately uptill now I have set up the udp listener so far I am now stuck here to where to go next, Anybody please suggest some articles regarding the udp port redirection with powershell or any ideas how this can be achieved.

 param (
[string] $ localip = "0.0.0.0"
[string] $ udplistenport = 1514
 )

 $ UdpClient = New-Object system.Net.Sockets.Udpclient ($ udplistenport)
 $ RemoteIpEndPoint = New-Object System.Net.IPEndPoint ([System.Net.IPAddress] :: Parse ($ localip) $ udplistenport);

 while ($ true) {
Write-Host "Receive UDP: Wait for Data on port: $ udplistenport"
$ data = $ udpclient.receive ([ref] $ RemoteIpEndPoint)
}

Thanks 

Frank

 
September 13th, 2015 1:02am

Port redirection is usually done at the router using NAT.  What you are trying too do is not possible because it will only copy one way traffic and will not allow the final target to respond.  Mapping of packet conversations is done in the packet and at the routers.  You cannot translate(redirect) a packet by copying it.  This requires using a NAT layer which can access the packet headers.  The UDPclient is an endpoint and cannot change the headers.
Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 1:10am

Start by reading this: https://en.wikipedia.org/wiki/Network_address_translation

NAT is sometimes referred to as "port forwarding&

September 13th, 2015 1:11am

Hello,

There are some third party applications like passport (http://sourceforge.net/projects/pjs-passport/) that redirects the incoming traffic at the OS level I was wondering how this application implements the logic of port redirection at the OS level...

Regards

Frank

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 1:19am

It does it by installing a driver at the transport layer of the communications stack.  The driver can see the raw packet and change it.  This is the same way that malware is able to redirect you whole machine if it can add a mall driver at the transport layer.  The driver can be only a few bytes and take over you system.  You cannot do this at the presentation layer.

See: https://en.wikipedia.org/wiki/OSI_model

This is how nearly all communications on the Internet are done.  The transport and network layers in IP networking are controlled at the network layer and rouge routes can work there or at the transport layer to redirect traffic.  Most work as multiplexers and just do what you are trying to do and copy both segments to a new location.  True NAT is normally done at the network layer in hardware or with a driver.

Windows NT servers have a NAT service used by RRAS and ISA and which can be coopted directly.  I believe that "netsh" can also define

September 13th, 2015 1:24am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics