关于MSSQL的通讯协议(一)

  最近要做个数据库代理服务器,需要封装一下数据库,没点思路,所以就想看看MSSQL的通讯协议,由于时间比较紧张,只是看了下查询、更新的协议,看完之后对MSSQL的通讯有了点大致的了解,但是大部分包内容还是不太明白

 

  使用MiniSniffer进行网络抓包(还是不错的,基本功能,不过不知道怎么上传附件,如果要可以留个邮箱)

 

  幸亏MSSQL没有对通讯包进行加密,之前对MySQL进行跟踪,感觉是加密了,不知道MSSQL能否进行加密,高手可以指教一下

 

  首先分析查询语句

  SELECT top 3 * FROM T_alarm

 

  生成的包如下:

  01 01                                                                       ####发起包标识
  00 54                                                                       ####包长度
  00 00 01 00                                                             ####未知
  16 00 00 00                                                             ####未知
  12 00 00 00                                                             ####未知
  02 00 00 00 00 00 00 00 00 00 01 00 00 00           ####未知

  ####语句的Unicode编码

  53 00 45 00 4C 00 45 00 43 00 54 00 20 00 74 00 6F 00 70 00 20 00 33 00 20 00
  2A 00 20 00 46 00 52 00 4F 00 4D 00 20 00 54 00 5F 00 61 00 6C 00 61 00 72 00 6D 00

 

  返回包内容如下:

04 01                                                                         ####响应包标识
01 64                                                                         ####整个包的长度
00 36 01 00                                                               ####未知
81                                                                              ####未知
09 00                                                                         ####返回字段个数

##字段1

00 00 00 00 08 00 38                                                ####猜测是字段类型
07                                                                              ####字段名称Unicode编码长度
47 00 72 00 61 00 64 00 65 00 49 00 44 00             ####字段Unicode编码

##字段2

00 00 00 00 08 00 38
06
54 00 79 00 70 00 65 00 49 00 44 00

##字段3

00 00 00 00 08 00 34
07
41 00 6C 00 61 00 72 00 6D 00 49 00 44 00
 ##字段4
00 00 00 00 08 00 30
0A
44 00 65 00 76 00 69 00 63 00 65 00 54 00 79 00 70 00 65 00

##字段5

00 00 00 00 08 00 AD 01 00
09
41 00 6C 00 61 00 72 00 6D 00 42 00 79 00 74 00 65 00

##字段6
00 00 00 00 08 00 E7 64 00 04 08 D0 00 00
09
41 00 6C 00 61 00 72 00 6D 00 4E 00 61 00 6D 00 65 00

##字段7
00 00 00 00 08 00 30
0B
43 00 6F 00 6D 00 6D 00 61 00 6E 00 64 00 4D 00 6F 00 64 00 65 00

##字段8
00 00 00 00 09 00 26 04
08
41 00 6C 00 61 00 72 00 6D 00 4C 00 65 00 6E 00

##字段9
00 00 00 00 09 00 26 01
05
53 00 74 00 61 00 74 00 65 00

 

## 数据行1

D1
01 00 00 00 00 00 00 00 01 00 02 01 00 01 0E 00 47
00 50 00 53 00 70 65 6E 63 0A 4E A5 62 00 04 0A
00 00 00 01 00

## 数据行2

D1
02 00 00 00 00 00 00 00 02 00
02 01 00 02 08 00 66 8F 86 8F B6 72 01 60 10 04
0A 00 00 00 01 00

## 数据行3

D1
02 00 00 00 00 00 00 00 03
00 02 01 00 03 08 00 09 63 2E 95 09 63 0B 4E 10
04 0A 00 00 00 01 00 


FD 10 00 C1 00                                                 #### 位置
03 00                                                                #### 返回影响行数
00 00 00 00 00 00                                            #### 包尾

 

分析语句

UPDATE T_alarm SET State = 1 WHERE AlarmID = 1

生成包

01 01                                                                 #### 发起包标识
00 7E                                                                 #### 包长度
00 00 01 00                                                       #### 未知
16 00 00 00                                                       #### 未知
12 00 00 00                                                       #### 未知
02 00 00 00 00 00 00 00 00 00 01 00 00 00     #### 未知

## 以下生成语句

55 00 50 00 44 00 41 00 54 00 45 00 20 00 54 00 5F 00 61 00 6C 00 61 00 72 00 6D 00 0D 00 0A 00 53 00
45 00 54 00 20 00 53 00 74 00 61 00 74 00 65 00 20 00 3D 00 20 00 31 00 0D 00 0A 00 57 00 48 00 45 00
52 00 45 00 20 00 41 00 6C 00 61 00 72 00 6D 00 49 00 44 00 20 00 3D 00 20 00 31 00

 

应答包

04 01                                                                 #### 应答包标识 
00 15                                                                 #### 包长度
00 36 01 00                                                       #### 未知
 
FD 10 00 C5 00                                                  #### 未知
01 00                                                                 #### 响应行数
00 00 00 00 00 00                                             #### 包尾

 

 

总结:

1.发起包开头01 01,应答包开始04 01

2.紧跟这个两字节的包长度,意味着最长65536

3.其他的不知道写了(鄙视我一下)

 

还有个问题不太明白:

就是发起包怎么和应答包能够联系到一起????

 

参考:

http://www.phpdiy.com/?action-viewnews-itemid-77345

你可能感兴趣的:(MSSQL)