smb协议讲解_SMBCIFS协议解析(一)

smb协议讲解_SMBCIFS协议解析(⼀)
⼀、SMB/CIFS协议的区别
在NetBIOS出现之后,Microsoft就使⽤NetBIOS实现了⼀个⽹络⽂件/打印服务系统,这个系统基于NetBIOS设定了⼀套⽂件共享
议,Microsoft称之为SMB(Server Message Block)协议。这个协议被Microsoft⽤于它们Lan
Manager和Windows
NT服务器系统中,⽽Windows系统均包括这个协议的客户软件,因⽽这个协议在局域⽹系统中影响很⼤。
随着Internet的流⾏,Microsoft希望将这个协议扩展到Internet上去,成为Internet上计算机之间相互共享数据的⼀种标
准。因此它将原有的⼏乎没有多少技术⽂档的SMB协议进⾏整理,重新命名为CIFS(Common Internet File
System),并打算将它与NetBIOS相脱离,试图使它成为Internet上的⼀个标准协议。
SMB(Server Message Block)协议在NT/2000中⽤来作⽂件共享,在NT中,SMB运⾏于NBT(NetBIOS
over TCP/IP)上,使⽤137,139(UDP),139(TCP)端⼝。
在2000中,SMB可以直接运⾏在tcp/ip上,⽽没有额外的NBT层,使⽤TCP
445端⼝。因此在2000上应该⽐NT稍微变化多⼀些。可以在“⽹络连接/属性/TCPIP协议/属性/⾼级/WINS中设置启⽤或者禁⽤
NBT(NetBIOS over TCP/IP)。
当2000使⽤⽹络共享的时候,就⾯临着选择139或者445端⼝了。下⾯的情况确定会话使⽤的端⼝:
1、如果客户端启⽤了
NBT,那么连接的时候将同时访问139和445端⼝,如果从445端⼝得到回应,那么客户端将发送RST到139端⼝,终⽌这个端⼝的连接,接着就从
445端⼝进⾏SMB的会话了;如果没有从445端⼝⽽是从139得到回应,那么就从139端⼝进⾏会话;如果没有得到任何回应,那么SMB 会话失败。
2、如果客户端禁⽤了NBT,他就将只从445端⼝进⾏连接。当然如果服务器(开共享端)没有445端⼝进⾏SMB会话的话,那么就会访问失败了,所以禁⽤445端⼝后,对访问NT机器的共享会失败。
3、如果服务器端启⽤NBT,那么就同时监听UDP
137、138端⼝和TCP139,445。如果禁⽤NBT,那么就只监听445端⼝了。
所以对于2000来说,共享问题就不仅仅是139端⼝,445端⼝同样能够完成。
⼆、SMB包头部分:
其中SMB Header的长度为32个byte,NETBIOS Header的长度为4个byte,TCP
Header为20个byte,SMB Command Header的长度不是固定的,不同的命令有不同的长度。
宋育英
三、SMB Header
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 bytes long struct {
蚕蛾交尾多久
USHORT PidHigh;
// High part of PID
ULONG Unused;
// Not used
ULONG Unused2;
}
Extra;
};
USHORT Tid;
// Tree identifier
USHORT Pid;
/
/ Caller's process id
USHORT Uid;
//
Unauthenticated user id
USHORT Mid;
// multiplex id
} SMB_HEADER;
下图为SMB Header每个字段占⽤的字节图:
生态系统的稳定性⽤wireshark抓包,SMB Header的截图:
SMB Command:SMB命令
NT Status:SMB命令的状态,0x00000000为成功
四、SMB Command
1、SMB_COM_NEGOTIATE(0x72) 协商命令  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)
建⽴会话,成功以后,⽤户正确登录。可以得到⽤户名和登录的主机名等信息
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_TREE_CONNECT (0x75)
遍历共享⽂件夹的⽬录及⽂件
Transmits the name of the disk share the client wants to
access. Successful server response has Tid field
set in SMB header used for subsequent SMBs referring to this
resource.
4、SMB_COM_NT_CREATE_ANDX (0xa2)
打开或者创建⽂件(夹),可以获取⽂件名及其⽬录,可以判断打开的是⽂件还是⽂件夹,获得读取⽂件的总长度。5、
SMB_COM_OPEN (0x2d)
读取⽂件,与read命令很相似。获得⽂件内容。
Transmits the name of the
file, relative to Tid, the client wants to open. Successful server
response includes a file id (Fid) the client
should supply for subsequent operations on this file.
6、SMB_COM_READ (0x2e) 读取⽂件,获得读取⽂件内容。
Client supplies Tid, Fid, file offset, and number of bytes to
read. Successful server response includes the
requested file data.
7、SMB_COM_WRITE
(0x2f) 写⼊⽂件,获得写⼊的⽂件内容
8、
SMB_COM_CLOSE (0x04) Client closes the file represented by
南京东方卫报Tid and Fid. Server responds with success code.
bd留置针9、
SMB_COM_TREE_DISCONNECT (0x71)
Client disconnects from resource represented by Tid.

本文发布于:2024-09-23 02:29:12,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/62021.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:协议   共享   得到
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议