5

I would like to implement a little tool that lets me do on Windows what I can already do easily on any other OS - specify a remote SMB server by both IP address and port. Natively, Windows will not do SMB over any ports other than 445 or 139 (its choice), and I'm sick of playing whack-a-mole with workarounds for the various Bad Things that Microsoft keeps adding to Windows to fsck up tunnelling SMB over SSH port forwarding.

What I have in mind is a little command line app that would let me do something like

netsubst servername -i IP -p PORT

This would work hand in hand with a driver? dll? that hooks into Windows as an SMB redirector, but scans a table of server names set up by netsubst instead of looking them up on the network in order to find out what to connect to. So I'd be able to do

net use X: //servername/sharename /user:username *

in the usual way, except that instead of Windows looking for //servername on ports 445 or 139 of whatever machines it could find, it would go straight to address IP, port PORT; and if IP happened to be 127.0.0.1 and PORT happened to be something forwarded to somewhere else via ssh, it would All Just Work and I would no longer need to deal with the walls of stupid that Windows puts around access to localhost ports 139 and 445.

I figure what I need is something akin to the //vboxsvr guest addition that VirtualBox uses to do host file sharing, but probably rather simpler since it wouldn't need a full back end - in my ideal world, the only Windows functionality I'd need to replace is the part that establishes the initial connection to the remote SMB server. But before I start tearing into the VirtualBox source code, can somebody suggest an easier way to get this done, or perhaps point me to Microsoft documentation on implementing SMB redirectors?

flabdablet
  • 3,565
  • 3
  • 22
  • 15
  • I know you can do ip/port redirection in a TDI or WFP filter driver, but I don't really know the specifics of developing them. Maybe somebody has already written a simple, generic ip/port redirection driver? – Luke Feb 25 '11 at 19:20
  • Pretty sure I need to get in above all of TCP/IP rather than gurgle about in its guts. – flabdablet Feb 26 '11 at 03:44
  • How about this (http://www.minek.com/?port_redirection)? Somewhat hackish, but I don't think you can make it any more elegant without using a filter driver. Windows isn't Linux. – Luke Feb 26 '11 at 15:25
  • The problem is not so much the port redirection; that part is easy. The problem is that Windows wants exclusive control over ports 445 and 139 on *all* local network interfaces, while having no way to run SMB over any other port. So yes, a filter driver is what I'm going to need, and I'm looking for the fastest way to skill up to writing one. – flabdablet Feb 28 '11 at 03:58

4 Answers4

5

\\server@port\share is a valid syntax for WebDAV. The moment you put the @port in the UNC path notation, net use changes from SMB to WebDAV. You cannot change the port SMB is using.

--Ben

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
user3242520
  • 51
  • 1
  • 1
2

Writing a driver is not easy; it requires a lot of domain specific knowledge. Here are some links to get started:

How to Write a Windows Driver
Develop a Windows Driver
WDK Documentation on MSDN

Good luck.

You might also find this (PDF) helpful.

Luke
  • 11,211
  • 2
  • 27
  • 38
1

You may need to implement a network redirector by yourself.

Looking TalAloni's SMBLibrary note and PcapDotNet , that can make some help.

IlPADlI
  • 1,943
  • 18
  • 22
-1

net use * \\servername@XXXX\ where XXXX is a port number. I've jast checked it on Windows 7. So it works perfect