/ Hack

Port forwarding – script to transform your PC into proxy

In some situations companies security services can forbid access to important server from WAN network, but still allow connections to your computer that has full LAN access (usually throw VPN-service).


In this situation, most common sollution to access server is to connect to your personal computer using RDP and then connect to server, using second layer of RDP. This may be not appropriate or convenient in some situations and this article can help you to bypass this limitation.

Here is JS script, that will create easy proxy for you.

var net = require('net');

// parse "80" and "localhost:80" or even "someadress.com:80"
var addrRegex = /^(([a-zA-Z\-\.0-9]+):)?(\d+)$/;

var addr = {
    from: addrRegex.exec(process.argv[2]),
    to: addrRegex.exec(process.argv[3])

if (!addr.from || !addr.to) {
    console.log('Usage: <from> <to>');

var server =  net.createServer(function(from) {
    var to = net.createConnection({
        host: addr.to[2],
        port: addr.to[3]

    to.on('error', function (exc) {
        console.log("ignoring exception from FROM: " + exc);
    from.on('error', function (exc) {
        console.log("ignoring exception from TO: " + exc);
.listen(addr.from[3], addr.from[2]);
  • To execute it, install Node from official site (I recommend you to use LTS version, if your are not familiar with Node);
  • Save script presented earlier with .js extension (for example proxy.js);
  • Open CMD on Windows or Terminal App on Mac OS and Linux go to folder with script and execute script with node proxy.js 3000, where 3000 is port that will be opened on this computer, and 3389 is address and port of LAN server to which forward trafic. Change this parameters to accomplish your mission.

In this example we create proxy for RDP service of server. Now we can connect to it using adress of our corporate computer and port 3000. Script will do other job for us. Now we have only one layer of RDP. Of cource you can forward any trafic and use any ports, it's all on you. Good luck.


P.S. If you want this script to work permanently, use forever CLI tool.