MongoDB数据报文格式
MongoDB采用的小端字节序,由消息头和消息体组成
消息头为固定长度,由
消息长度 4个字节
+requestID 4个字节
+responseTo 4个字节
+opCode 4个字节
消息体长度为消息长度-消息头长度16
query请求的组成
opcode为d4 07 00 00 4个字节
+query flags 4个字节
+fullcollectionname 变长,以00结尾,database name与collection name用2e分割 例如admin.$cmd
+numbertoskiip 4个字节
+numbertoreturn 4个字节
+document 变长 ,由document长度 4个字节 + elements组成 变长
reply响应的组成
opcode 为01 00 00 00 4个字节+reply flags 4个字节
+cursor id 8个字节
+starting from 4个字节
+number returned 4个字节
+document 变长 ,由document长度 4个字节 + elements组成 变长
document的的组成
document长度 4个字节
+ elements组成 变长
element的组成
element type 1个字节
+element name 变长,以00结尾
+element length 4个字节 (对于定长element,例如int32,boolean,datetime,double没有该字段)
+element value 长度由element type决定,
例如int32为4个字节;double为8个字节;datetime为8个字节,boolean为1个字节;string为变长,以00结尾;binary为变长,大端字节序
mongodb的认证方式
(1)scram-sha-1
认证请求:

可以payload从中提取用户名
认证响应:

(2)chanllenge and Response
认证请求:

认证响应

参考:
预告:六、TCP/IP协议分析-Redis认证协议分析