Giter Site home page Giter Site logo

smb-ssh-tunnel's Introduction

smb-ssh-tunnel

Connect samba server with different ports on Windows

In Windows, smb is only supported with port 445, which is commonly blocked by firewalls. Two ways to avoid port 445 being blocked:

  • Use another port on the server. However, Windows explorer can't use any port other than 445. We can use smb.ps1 to workaround that.
  • If the service is behind some gateways, the NAT policy of the gateways may be limited. Or we don't want the SMB protocol be detected, we can use ssh-smb.ps1 to proxy our smb.

These Powershell scripts create a loopback network adapter to proxy the ports as a workaround. The ssh-smb also creates a task scheduler to automatically establish a ssh tunnel to connect to the samba server. Then we can connect to smb server with the added loopback NIC (by default, \\10.255.255.1\) to access the smb behind firewalls.

Need:

  • smb server
  • ssh server (for ssh-smb)
  • private and public keys to connect ssh (for ssh-smb, since openssh doesn't support password in command line).

From Win 10, openssh is built-in by OS. No need for other ssh clients.

Usage

.\smb.ps1 DESTINATION_IP DESTINATION_PORT

or with ssh

.\ssh-smb.ps1 "<user>@<ip> -p <SSH_Port> -i <private_key>"

if you want to specify the added NIC's ip and name (default are 10.255.255.1 and "Loopback"), use

.\smb.ps1 DESTINATION_IP DESTINATION_PORT NIC_IP NIC_NAME

or with ssh

.\ssh-smb.ps1 "<user>@<ip> -p <SSH_Port> -i <private_key>" DESTINATION_IP NIC_IP NIC_NAME

(DESTINATION_IP is 127.0.0.1 if smb server is the same as the ssh server.)

Then reboot.

Example

To connect to ip 114.514.19.19 and smb server port 810:

.\smb.ps1 114.514.19.19 810

or with ssh and normal smb port 445:

.\ssh-smb.ps1 "[email protected] -p 22 -i <private_key>"

Since one NIC can only proxy one smb server, multiple NIC with different name and ip need to be added:

.\smb.ps1 114.514.19.19 810 10.255.254.1 Loopback2

or with ssh and normal smb port 445:

.\ssh-smb.ps1 "[email protected] -p 22 -i <private_key>" 127.0.0.1 10.255.254.1 Loopback2

or the ssh server is not the same as the smb server, the smb server's internal network ip is 192.168.114.514:

.\ssh-smb.ps1 "[email protected] -p 22 -i <private_key>" 192.168.114.514 10.255.254.1 Loopback2

Test

To test the result, execute the two commands:

netstat -an | find ":445 "
netsh interface portproxy show v4tov4

The results should be like (with default NIC ip 10.255.255.1)

test

The line

TCP    10.255.255.1:445       0.0.0.0:0              LISTENING

should exists.

Then you can access smb server with locations like \\10.255.255.1\some_location

smb-ssh-tunnel's People

Contributors

dbshch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.