从通过使用代理服务器进行拦截获得的二进制数据解码MongoDB Wire Protocol数据包

时间:2019-04-09 07:32:00

标签: python mongodb sockets protocols pymongo

我正在尝试使用代理服务器拦截mongo数据包。我可以截取二进制数据,但是不能将它们解码为https://docs.mongodb.com/manual/reference/mongodb-wire-protocol

中所述的Mongo Wire协议消息。

我得到的二进制数据看起来像这样

\xe0\x00\x00\x00i\x98<d\x00\x00\x00\x00\xdd\x07\x00\x00\x00\x00\x00\x00\x00\x95\x00\x00\x00\x02insert\x00\x06\x00\x00\x00dummy\x00\x08ordered\x00\x01\x03writeConcern\x00\x0c\x00\x00\x00\x10w\x00\x01\x00\x00\x00\x00\x03lsid\x00\x1e\x00\x00\x00\x05id\x00\x10\x00\x00\x00\x04\xc4*\xceT\x02,@\xe7\x98\xc4\xe7a\\\x03\xd4\x87\x00\x02$db\x00\x05\x00\x00\x00test\x00\x03$readPreference\x00\x17\x00\x00\x00\x02mode\x00\x08\x00\x00\x00primary\x00\x00\x00\x015\x00\x00\x00documents\x00'\x00\x00\x00\x07_id\x00\\\xac?\xd0\x8eB.?[\xbd\xf9\xec\x02string\x00\x05\x00\x00\x00test\x00\x00

这是当我在文档“虚拟”的字段“字符串”中存储字符串“ test”时的数据

根据MongoDB Wire Protocol,OP_INSERT消息的格式为

struct {
    MsgHeader header;             // standard message header
    int32     flags;              // bit vector - see below
    cstring   fullCollectionName; // "dbname.collectionname"
    document* documents;          // one or more documents to insert into the collection
}

邮件标题的格式为

struct MsgHeader {
    int32   messageLength; // total message size, including this
    int32   requestID;     // identifier for this message
    int32   responseTo;    // requestID from the original request
                           //   (used in responses from db)
    int32   opCode;        // request type - see table below for details
}

从上面的二进制数据中,我想提取Mongo Wire Protocol消息。是否有任何软件包/库来实现这一目标?

0 个答案:

没有答案