mig0 / SMB

Implementing CIFS (SMB) protocol in Perl
GNU General Public License v3.0
14 stars 6 forks source link

Can't read NetBIOS Session Service header (got 0 bytes) #1

Closed FROGGS closed 6 years ago

FROGGS commented 8 years ago

Hi, I want to run an SMB server to serve files from filesystem+database. However, when I start the server as:

bin/smb-server -p 3333

And then when I connect to smb://localhost:3333 I get:

* SMB::Server started, listening on port 3333
* Connected - client #1 [127.0.0.1:47908]
* SMB1 [Negotiate Request ] mid=0 uid=fffe tid=00 - client #1 [127.0.0.1:47908]
* SMB2 [Negotiate Response] mid=0 uid=0 tid=00 - client #1 [127.0.0.1:47908]
! Can't read NetBIOS Session Service header (got 0 bytes) - client #1 [127.0.0.1:47908]
* Disconnected - client #1 [127.0.0.1:47908]

Is there something I'm doing wrong?

FROGGS commented 8 years ago

And when I connect from a Windows 7 box I get:

$ bin/smb-server -p 3333
* SMB::Server started, listening on port 3333
* Connected - client #1 [127.0.0.1:48744]
! Only supported NetBIOS Session Service header with type=0 flags=0|1 - client #1 [127.0.0.1:48744]
# packet_type=79 packet_flags=80
* Disconnected - client #1 [127.0.0.1:48744]
* Connected - client #2 [127.0.0.1:48746]
! Only supported NetBIOS Session Service header with type=0 flags=0|1 - client #2 [127.0.0.1:48746]
# packet_type=79 packet_flags=80
* Disconnected - client #2 [127.0.0.1:48746]

And yes, that's a single connection attempt. Perhaps Windows 7 tries a second time on its own.

FROGGS commented 8 years ago

Okay, the Windows box actually sends:

OPTIONS / HTTP/1.1
Connection: Keep-Alive
User-Agent: DavClnt
translate: f
Host: 10.0.2.2:3333
vdudouyt commented 6 years ago

I'm getting exactly the same issue on Ubuntu 16.04:

$ sudo mount.cifs //127.0.0.1/ /net/mountpoint -o user=someuser,vers=2.0
mount error(22): Invalid argument

In smb-server's output I get:

! Can't read NetBIOS Session Service header (got 0 bytes) - client #2 [127.0.0.1:48662]

And I also see the following message in dmesg:

[8555943.335701] CIFS VFS: Bad protocol string signature header 0x424d53fe
vdudouyt commented 6 years ago

Actually this even reproduces when trying to connect with bin/smbclient:

$ ./smb-client -v -U user%password //127.0.0.1/share/
! Can't read NetBIOS Session Service header (got 0 bytes) - client #1 [127.0.0.1:49060]

Login & password correctness is not an issue - because when I use incorrect ones I'm also getting 'Failed password check for user'.

mig0 commented 6 years ago

The dmesg error means your CIFS VFS client does not support SMB2. (0x424d53fe is the SMB2 command signature.)

There is enough missing functionality in this SMB implementation to fail against real Linux or Windows clients and servers. But provided smb-client should work well enough against smb-server. Try this:

 % bin/smb-server -p 33333

And:

% bin/smb-client //localhost:33333/test -U test%12345
Connected to //localhost:33333/test. Enter 'help' to list commands.
smb:localhost:33333/test> dir

.                                        2018-03-18 15:31
..                                       2018-03-18 15:31
file1.txt                                2018-03-18 15:31
file2.txt                                2018-03-18 15:31
subdir                                   2018-03-18 15:31
smb:localhost:33333/test> 
mig0 commented 6 years ago

The error message from the subject should be mostly masked now by another message in the server: Connection reset by peer

Moreover, the server now actually checks that a client supports SMB2 and shows: Client does not support SMB2, and we do not support SMB1, stopping

The client is quite useful now. The server still needs work; this is planned in 0.08.

Any help is welcome.

mig0 commented 6 years ago

1) As of 0.08, both client and server are usable against Windows 7. I.e. you may access its share using smb-client and serve your share in Explorer using smb-server.

2) As of 0.09, the server may work with Nautilus client.

To configure nautilus to use SMB2 instead of SMB1, these lines may be added to /etc/samba/smb.conf [global] section:

    client min protocol = SMB2
    client max protocol = SMB3
    client signing = disabled

Then start "nautilus smb://localhost/test" or specify such address in its Location field.

3) Unfortunately, the samba's smbclient is too moody. You are supposed to tell smbclient to use SMB2 instead of SMB1 and disable signing by these arguments:

smbclient //localhost/test -U test%12345 -S off -m SMB2

In older samba version it didn't even pass the SessionSetup step (there was a bug I believe), now authentication is passed. However (at least in 4.6.5-0.fc26) it enforces message signing on TreeConnect. This contradicts with the "-S off" parameter... So I believe there is a bug in samba client again...

One day message signing may be added as well, but not right now.

4) To mount a share in unix/linux, you may add this to /etc/fstab:

//localhost/test /mnt/smb cifs noauto,user,vers=2.1,sec=ntlmssp,username=test,password=12345,domain=WORKSTATION,dir_mode=0775,file_mode=0664

All its requests (QueryInfo FS_INFO/FILE_INFO) are replied properly, but something is not satisfied, so "mount /mnt/smb" fails with strange error "mount error(22): Invalid argument". I will try to fix this later.

5) So I am closing this bug. Please report more specific issues.