SMB/CIFS协议解析

摘要:
.2 SMB协议SMB是ServerMessageBlock的缩写。此协议用于共享文件、打印机和串行端口。SMB服务器负责通过网络向SMB客户端提供可用的共享资源。服务器和客户端通过TCP/IP协议、IPX协议或NetBEUI连接。

1、SMB协议与CIFS协议的区别
     139端口是一种TCP端口,该端口在通过网上邻居访问局域网中的共享文件或共享打印机时就能发挥作用。
445端口也是一种TCP端口,该端口在 Windows 2000 Server或Windows Server 2003系统中发挥的作用与139端口是完全相同的。具体地说,它也是提供局域网中文件或打印机共享服务。不过该端口是基于CIFS协议(通用因特网文件系统协议)工作的,而139端口是基于SMB协议(Server Message Block服务器协议族)对外提供共享服务。
 
NBT(NetBIOS over TCP/IP)
使用137, 138 (UDP) and 139 (TCP)来实现基于TCP/IP的NETBIOS网际互联。
在Windows NT中SMB基于NBT实现。而在Windows2000中,SMB除了基于NBT的实现,还有直接通过445端口实现。
当Win2000(允许NBT)作为client来连接SMB服务器时,它会同时尝试连接139和445端口,如果445端口有响应,那么就发送RST包给139端口断开连接,以455端口通讯来继续.当445端口无响应时,才使用139端口。
当Win2000(禁止NBT)作为client来连接SMB服务器时,那么它只会尝试连接445端口,如果无响应,那么连接失败。(注意可能对方是NT4.0服务器。)
如果win2000服务器允许NBT, 那么UDP端口137, 138, TCP 端口 139, 445将开放。
如果 NBT 被禁止, 那么只有445端口开放。
.
2、SMB协议
SMB是的Server Message Block简写,这个协议用于共享文件,共享打印机,共享串口等用途。我们之所以能够在windows的网络邻居下访问一个域内的其他机器,就是通过这个协议实现的。
    SMB协议是一个很重要的协议,目前绝大多数的PC上都在运行这一协议,windows系统都充当着SMB协议的客户端和服务器,所以SMB是一个遵循客户机服务器模式的协议。SMB服务器负责通过网络提供可用的共享资源给SMB客户机,服务器和客户机之间通过TCP/IP协议、或者IPX协议、或者是NetBEUI进行连接。一旦服务器和客户机之间建立了一个连接,客户机就可以通过向服务器发送命令完成共享操作,比如读,写,检索等。
消息格式:SMB Message分为三个部分
SMB Header, //头部     4byte
SMB Command Header//命令头部    32byte
the Data Block. //数据部分

==================================================================

SMB 头部
数据结构:
typedef unsigned char UCHAR;          // 8 unsigned bits
typedef unsigned short USHORT;        // 16 unsigned bits
typedef unsigned long ULONG;          // 32 unsigned bits
 
typedef struct {
    ULONG LowPart;
    LONG HighPart;
} LARGE_INTEGER;                      // 64 bits of data
 
typedef struct  {
    UCHAR Protocol[4];                // Contains 0xFF,'SMB'
    UCHAR Command;                    // Command code
    union {
        struct {
            UCHAR ErrorClass;         // Error class
            UCHAR Reserved;           // Reserved for future use
            USHORT Error;             // Error code
        } DosError;
        ULONG Status;                 // 32-bit error code
    } Status;
    UCHAR Flags;                      // Flags
    USHORT Flags2;                    // More flags
    union {
        USHORT Pad[6];                // Ensure section is 12 by
        struct {
            USHORT PidHigh;          // High Part of PID
            UCHAR SecuritySignature[8];   // reserved for MAC
       } Extra;
    };
    USHORT Tid;                       // Tree identifier
    USHORT Pid;                       // Caller’s process ID, opaque for
client use
    USHORT Uid;                       // User id
    USHORT Mid;                       // multiplex id
    UCHAR  WordCount;                 // Count of parameter words
} SMB_HEADER;
说明:
1、Tid
Tid represents an instance of an authenticated connection to a server resource.  The server
returns Tid to the client when the client successfully connects to a resource, and the client uses Tid in subsequent requests referring to the resource.
2、Pid Pid is the caller's process id, and is generated by the client to uniquely identify a process within the client computer.
3、Uid Field
Uid is a reference number assigned by the server after a user authenticates to it, and that it will associate with that user until the client requests the association be broken. After authentication to the server, the client SHOULD make sure that the Uid is not used for a different user that the onethat authenticated. (It is permitted for a single user to have more than one Uid.) Requests that do authorization, such as open requests, will perform access checks using the identity associated with the Uid.
4、 Mid Field
The multiplex ID (Mid) is used along with the Pid to allow multiplexing the single client and server connection among the client's multiple processes, threads, and requests per thread. Clients may have many outstanding requests (up to the negotiated number, MaxMpxCount) at one time. Servers MAY respond to requests in any order, but a response message MUST always contain the same Mid and Pid values as the corresponding request message. The client MUST NOT have multiple outstanding requests to a server with the same Mid and Pid.
5、command code
(1)SMB_COM_NEGOTIATE           0x72
 Client Command             Server Response
 ========================== =========================================
 SMB_COM_NEGOTIATE          Must be the first message sent by client                 
                            to the server.  Includes a list of SMB
                            dialects supported by the client.  Server
                            response indicates which SMB dialect
                            should be used.
(2)SMB_COM_SESSION_SETUP_ANDX  0x73
SMB_COM_SESSION_SETUP_ANDX  Transmits the user's name and credentials        
                            to the server for verification.
                            Successful server response has Uid field
                            set in SMB header used for subsequent
                            SMBs on behalf of this user.
(3)SMB_COM_NT_CREATE_ANDX   0xa2
 Client Command             Server Response
 ========================== =========================================
SMB_COM_NT_CREATE_ANDX     An SMB_COM_NT_CREATE_ANDX request is sent
                           by a client to open a file or device on the server.
(4)SMB_COM_READ_AndX                0x2e
SMB_COM_READ_AndX              
An SMB_COM_READ_ANDX request is sent by a client to read from a file or named pipe on a server
(5) SMB_COM_WRITE_AndX                0x2f
SMB_COM_WRITE_AndX              
An SMB_COM_WRITE_AndX request is sent by a client to write from a file or named pipe on a server

免责声明:文章转载自《SMB/CIFS协议解析》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇OnZoom 基于Apache Hudi的流批一体架构实践EF Core 原理从源码出发(二)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

samba

一、samba简介 Samba最大的功能可用于Linux与windows系统直接的文件共享和打印共享,Samba既可用于windows与Linux之间的文件共享,也可用于Linux与Linux之间的资源共享,由于NFS的出现,因而 Samba更多用在Linux与windows之间的数据共享上面。 Samba服务器可实现如下功能: WINS和DNS服务;...

smb(ms17-010)远程命令执行之msf

1.本次用到的环境: kali(2016.2)32位系统.ip地址:192.168.1.104 目标靶机为:win7sp1x64系统(关闭防火墙),ip地址:192.168.1.105 具体的步骤如下: kali系统下安装wine32: apt-get install wine32 用wine32执行cmd.exe wine cmd.exe exi...

windows CIFS sabma协议识别

今天在linux上搭建了CIFS协议,使用sabma4.7.0版本。 通过smbstatus可以查看smb软件的版本 通过/bin/smbstatus -d 0可以查看目前正连接的客户端。 问题来了:不知道这个smb到底支持哪些SMB协议,目前SMB的版本有1.X    2.02   2.1    3.0    3.0.2   3.1.1 至少网上没有查询...

Linux与Windows共享资源samba+mount

smb:server message block protocol, smb是一种客户机/服务器、请求/响应协议。通过 smb 协议,客户端应用程序可以在各种网络环境下读、写服务器上的文件,以及对服务器程序提出服务请求。此外通过 smb 协议,应用程序可以访问远程服务器端的文件、以及打印机、邮件槽(mailslot)、命名管道(named pipe)等资源...

Shell命令

复制别人的,并没有全部用过 (一)文件创建命令 1.touch命令 例如:touch abc命令在本地目录中创建了一个名为abc的空文件 2.cp命令 cp命令允许我们把一个文件的内容复制到同名或不同名的文件中,复制得到的文件可以在任何目录。使用cp命令的一个风险是它会在不提示用户的情况下很容易覆盖掉不同目录中的文件 -r选项支持递归复制。例如:cp -a...

crontab命令加载和使用

crontab命令用于设置周期性被执行的指令。 在Linux系统中,Linux任务调度的工作主要分为以下两类:1、系统执行的工作:系统周期性所要执行的工作,如备份系统数据、清理缓存2、个人执行的工作:某个用户定期要做的工作,例如每隔10分钟检查邮件服务器是否有新信,这些工作可由每个用户自行设置 首先查看有无安装crontab [root@localhost...