MySQL协议分析
此阶段的协议分析是在未压缩未加密情况下的协议分析
思路:
结合Oracle官网和自己用wireshark抓的网络数据包进行协议分析
官网说明
mysql包共分为4段,格式如下:
第一段:payload(通常是执行的SQL语句)的长度占3字节;
第二段:序列id占1字节;
第三段:payload类型占1字节;
第四段:payload内容占n字节,n为第一段描述的长度。
wireshark抓包分析验证
0000 1a 00 00 00 03 73 65 6c 65 63 74 20 2a 20 66 72 .....select * fr
0010 6f 6d 20 73 6d 61 6c 6c 74 61 62 6c 65 3b om smalltable;
MySQL Protocol
Packet Length: 26
Packet Number: 0
Request Command Query
Command: Query (3)
Statement: select * from smalltable;
我们看到1a 00 00 00 03就是mysql的协议头
1a 00 00 转换为10进制为26,与wireshark解析的Packet Length:26符合(也说明了wireshark原理不过就是把协议对应解析);
00 是sequence id,也就是序列id,我们没有创建序列,也就没有此id;
03 是payload的类型,对于类型说明,官网说明如下:
Type Description
int<1> 1 byte Protocol::FixedLengthInteger
int<2> 2 byte Protocol::FixedLengthInteger
int<3> 3 byte Protocol::FixedLengthInteger
int<4> 4 byte Protocol::FixedLengthInteger
int<6> 6 byte Protocol::FixedLengthInteger
int<8> 8 byte Protocol::FixedLengthInteger
int<lenenc> Protocol::LengthEncodedInteger
string<lenenc> Protocol::LengthEncodedString
string<fix> Protocol::FixedLengthInteger
string<var> Protocol::VariableLengthString:
string<EOF> Protocol::RestOfPacketString
string<NUL> Protocol::NulTerminatedString
总之对于第三个字段,我现在只看到过03 。
第四段自然就是payload,也就是我们的SQL语句。